From 2654ff5466f5d84e359b8d8ee25fe90a72574c7d Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Fri, 8 Nov 2013 13:21:41 +0100 Subject: [PATCH] Drop obsolete tests/. --- tests/DbTest.php | 123 ---------------- tests/syncLibTest.php | 333 ------------------------------------------ tests/test-multi.php | 22 --- 3 files changed, 478 deletions(-) delete mode 100644 tests/DbTest.php delete mode 100644 tests/syncLibTest.php delete mode 100644 tests/test-multi.php diff --git a/tests/DbTest.php b/tests/DbTest.php deleted file mode 100644 index 8e7effe..0000000 --- a/tests/DbTest.php +++ /dev/null @@ -1,123 +0,0 @@ -db=new Db($baseParams['__YKVAL_DB_DSN__'], - 'root', - 'lab', - $baseParams['__YKVAL_DB_OPTIONS__']); - $this->db->connect(); - $this->db->customQuery("drop table unittest"); - $this->db->customQuery("create table unittest (id int,value1 int, value2 int)"); - - } - public function test_template() - { - } - - public function testConnect() - { - $this->assertTrue($this->db->isConnected()); - $this->db->disconnect(); - $this->assertFalse($this->db->isConnected()); - } - public function testSave() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200))); - $res=$this->db->findByMultiple('unittest', array('value1'=>100, - 'value2'=>200)); - $this->assertEquals(1, count($res)); - } - - public function testUpdateBy() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200))); - $this->db->updateBy('unittest', 'value1', 100, array('value2'=>NULL)); - $res=$this->db->findByMultiple('unittest', array('value1'=>100, - 'value2'=>NULL)); - $this->assertEquals(1, count($res)); - } - public function testFindBy() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200))); - $res=$this->db->findBy('unittest', 'value1', 100); - $this->assertEquals(1, count($res)); - } - public function testUpdate() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200, - 'id'=>1))); - $res=$this->db->findBy('unittest', 'value1', 100); - $this->assertTrue($this->db->update('unittest', 1, - array('value2'=>1000))); - - $res=$this->db->findBy('unittest', 'id', 1, 1); - $this->assertEquals(1000, $res['value2']); - } - public function testDeleteByMultiple() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200, - 'id'=>1))); - $this->assertTrue($this->db->deleteByMultiple('unittest', array('value1'=>100, - 'value2'=>200))); - - } - - public function testRowCount() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200, - 'id'=>1))); - $this->assertEquals(1, $this->db->rowCount(), "1 row should have been affected by previous statement"); - } - public function testConditionalUpdate() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200, - 'id'=>1))); - $condition="(100 > value1 or (100=value1 and 200>value2))"; - $this->assertTrue($this->db->conditionalUpdate('unittest', 1, array('value2'=>201), $condition)); - $this->assertEquals(0, $this->db->rowCount(), "One row should have been affected"); - $condition="(100 > value1 or (100=value1 and 201>value2))"; - $this->assertTrue($this->db->conditionalUpdate('unittest', 1, array('value2'=>201), $condition)); - $this->assertEquals(1, $this->db->rowCount(), "One row should have been affected"); - } - public function testConditionalUpdateBy() - { - $this->assertTrue($this->db->save('unittest', array('value1'=>100, - 'value2'=>200, - 'id'=>1))); - $condition="(100 > value1 or (100=value1 and 201>value2))"; - $this->assertTrue($this->db->conditionalUpdateBy('unittest', 'value1', 100, array('value2'=>201), $condition)); - $this->assertEquals(1, $this->db->rowCount(), "One row should have been affected"); - - - $this->db->customQuery("drop table myunittest"); - $this->db->customQuery("create table myunittest (id int, string1 varchar(10), value1 int)"); - - - $this->assertTrue($this->db->save('myunittest', array('value1'=>100, - 'string1'=>'hej', - 'id'=>1))); - $condition="(101 > value1)"; - $this->assertTrue($this->db->conditionalUpdateBy('myunittest', 'string1', 'hej', array('value1'=>101), $condition)); - $this->assertEquals(1, $this->db->rowCount(), "One row should have been affected"); - - - } -} -?> \ No newline at end of file diff --git a/tests/syncLibTest.php b/tests/syncLibTest.php deleted file mode 100644 index 1750b4c..0000000 --- a/tests/syncLibTest.php +++ /dev/null @@ -1,333 +0,0 @@ -connect(); - # $db->truncateTable('queue'); - $db->disconnect(); - } - public function testTemplate() - { - } - - public function testConstructor() - { - $sl = new SyncLib(); - $this->assertGreaterThan(1, $sl->getNumberOfServers()); - $this->assertEquals($sl->getServer(0), "http://api2.example.com/wsapi/2.0/sync"); - } - - - public function testQueue() - { - $sl = new SyncLib(); - $nr_servers = $sl->getNumberOfServers(); - $queue_length = $sl->getQueueLength(); - - - $sl->queue(array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>20, - 'yk_high'=>100, - 'yk_low'=>1000), - array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>18, - 'yk_high'=>100, - 'yk_low'=>1000) - ); - - - $this->assertEquals($nr_servers + $queue_length, $sl->getQueueLength()); - $res=$sl->db->findByMultiple('queue', - array("modified"=>1259585588, - "server_nonce"=>$sl->server_nonce)); - $lastRes=$res[0]; - $info=$sl->otpParamsFromInfoString($lastRes['info']); - $lastSync=array('queued'=>$lastRes['queued'], - 'modified'=>$lastRes['modified'], - 'otp'=>$lastRes['otp'], - 'server'=>$lastRes['server'], - 'nonce'=>$info['nonce'], - 'yk_publicname'=>$info['yk_publicname'], - 'yk_counter'=>$info['yk_counter'], - 'yk_use'=>$info['yk_use'], - 'yk_high'=>$info['yk_high'], - 'yk_low'=>$info['yk_low']); - - - $this->assertEquals($lastSync['modified'], 1259585588); - $this->assertEquals($lastSync['otp'], "ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui"); - $this->assertEquals($lastSync['yk_publicname'], "cccccccccccc"); - $this->assertEquals($lastSync['yk_counter'], 10); - $this->assertEquals($lastSync['yk_use'], 20); - $this->assertEquals($lastSync['yk_high'], 100); - $this->assertEquals($lastSync['yk_low'], 1000); - } - - public function testCountersHigherThan() - { - $sl = new SyncLib(); - $localParams=array('yk_counter'=>100, - 'yk_use'=>10); - $otpParams=array('yk_counter'=>100, - 'yk_use'=>11); - - $this->assertTrue($sl->countersHigherThan($otpParams, $localParams)); - $this->assertFalse($sl->countersHigherThan($localParams, $otpParams)); - $otpParams['yk_use']=10; - $this->assertFalse($sl->countersHigherThan($otpParams, $localParams)); - $otpParams['yk_counter']=99; - $this->assertFalse($sl->countersHigherThan($otpParams, $localParams)); - $otpParams['yk_counter']=101; - $this->assertTrue($sl->countersHigherThan($otpParams, $localParams)); - } - - public function testCountersHigherThanOrEqual() - { - $sl = new SyncLib(); - $localParams=array('yk_counter'=>100, - 'yk_use'=>10); - $otpParams=array('yk_counter'=>100, - 'yk_use'=>11); - - $this->assertTrue($sl->countersHigherThanOrEqual($otpParams, $localParams)); - $this->assertFalse($sl->countersHigherThanOrEqual($localParams, $otpParams)); - $otpParams['yk_use']=10; - $this->assertTrue($sl->countersHigherThanOrEqual($otpParams, $localParams)); - $otpParams['yk_counter']=99; - $this->assertFalse($sl->countersHigherThanOrEqual($otpParams, $localParams)); - $otpParams['yk_counter']=101; - $this->assertTrue($sl->countersHigherThanOrEqual($otpParams, $localParams)); - } - - public function testCountersEqual() - { - $sl = new SyncLib(); - $localParams=array('yk_counter'=>100, - 'yk_use'=>10); - $otpParams=array('yk_counter'=>100, - 'yk_use'=>10); - - $this->assertTrue($sl->countersEqual($otpParams, $localParams)); - $otpParams['yk_use']=8; - $this->assertFalse($sl->countersEqual($otpParams, $localParams)); - $otpParams['yk_use']=9; - $this->assertFalse($sl->countersEqual($otpParams, $localParams)); - $otpParams['yk_use']=-11; - $this->assertFalse($sl->countersEqual($otpParams, $localParams)); - $otpParams['yk_use']=10; - $otpParams['yk_counter']=101; - $this->assertFalse($sl->countersEqual($otpParams, $localParams)); - - } - - - public function testSync1() - { - $sl = new SyncLib(); - $sl->syncServers = array("http://localhost/wsapi/syncvalid1", - "http://localhost/wsapi/syncvalid2", - "http://localhost/wsapi/syncvalid3"); - - $start_length=$sl->getQueueLength(); - $this->assertTrue( - $sl->queue(array('modified'=>1259585588+1000, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>9, - 'yk_use'=>3, - 'yk_high'=>100, - 'yk_low'=>1000), - array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>18, - 'yk_high'=>100, - 'yk_low'=>1000) - )); - - - - $res=$sl->sync(3); - $this->assertEquals(3, $sl->getNumberOfValidAnswers()); - $this->assertTrue($res, "all sync servers should be configured to return ok values"); - $this->assertEquals($start_length, $sl->getQueueLength()); - - $this->assertTrue( - $sl->queue(array('modified'=>1259585588+1000, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>9, - 'yk_use'=>3, - 'yk_high'=>100, - 'yk_low'=>1000), - array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>18, - 'yk_high'=>100, - 'yk_low'=>1000) - )); - - - $res=$sl->sync(2); - $this->assertEquals(2, $sl->getNumberOfValidAnswers()); - $this->assertTrue($res, "all sync servers should be configured to return ok values"); - $this->assertEquals($start_length+1, $sl->getQueueLength()); - - - } - - public function testSync2() - { - $sl = new SyncLib(); - $sl->syncServers = array("http://localhost/wsapi/syncinvalid1", - "http://localhost/wsapi/syncinvalid2", - "http://localhost/wsapi/syncinvalid3"); - - $start_length=$sl->getQueueLength(); - $this->assertTrue( - $sl->queue(array('modified'=>1259585588+1000, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>9, - 'yk_use'=>3, - 'yk_high'=>100, - 'yk_low'=>1000), - array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>18, - 'yk_high'=>100, - 'yk_low'=>1000) - )); - - - $res=$sl->sync(3); - $this->assertEquals(0, $sl->getNumberOfValidAnswers()); - $this->assertFalse($res, "only 1 sync server should have returned ok values"); - $this->assertEquals($start_length, $sl->getQueueLength()); - - - } - - public function testSync3() - { - $sl = new SyncLib(); - $sl->syncServers = array("http://localhost/wsapi/syncvalid1", - "http://localhost/wsapi/syncvalid2", - "http://localhost/wsapi/syncvalid3"); - - $start_length=$sl->getQueueLength(); - $this->assertTrue( - $sl->queue(array('modified'=>1259585588+1000, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>9, - 'yk_use'=>3, - 'yk_high'=>100, - 'yk_low'=>1000), - array('modified'=>1259585588, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>10, - 'yk_use'=>18, - 'yk_high'=>100, - 'yk_low'=>1000) - )); - - - $res=$sl->sync(1); - $this->assertEquals(1, $sl->getNumberOfValidAnswers()); - $this->assertTrue($res, "only 1 sync server should have returned ok values"); - $this->assertEquals($start_length+2, $sl->getQueueLength()); - - - } - - public function testNullQueue() - { - $sl = new SyncLib(); - $sl->syncServers = array("http://localhost/wsapi/syncvalid1", - "http://doesntexist/wsapi/syncvalid2", - "http://localhost/wsapi/syncvalid3"); - - $start_length=$sl->getQueueLength(); - $p1=array('modified'=>1259585588+1000, - 'otp'=>"ccccccccccccfrhiutjgfnvgdurgliidceuilikvfhui", - 'yk_publicname'=>"cccccccccccc", - 'yk_counter'=>9, - 'yk_use'=>3, - 'yk_high'=>100, - 'yk_low'=>1000); - - $this->assertTrue($sl->queue($p1, $p1)); - - - $res=$sl->db->findByMultiple('queue', - array("modified"=>1259585588+1000, - "server_nonce"=>$sl->server_nonce)); - $lastRes=$res[0]; - $info=$sl->otpParamsFromInfoString($lastRes['info']); - $res=array('queued'=>$lastRes['queued'], - 'modified'=>$lastRes['modified'], - 'otp'=>$lastRes['otp'], - 'server'=>$lastRes['server'], - 'nonce'=>$info['nonce'], - 'yk_publicname'=>$info['yk_publicname'], - 'yk_counter'=>$info['yk_counter'], - 'yk_use'=>$info['yk_use'], - 'yk_high'=>$info['yk_high'], - 'yk_low'=>$info['yk_low']); - - $this->assertNotNull($res['queued']); - $res=$sl->sync(3); - - $this->assertEquals(1+$start_length, $sl->getQueueLength()); - - $res=$sl->db->findByMultiple('queue', - array("modified"=>1259585588+1000, - "server_nonce"=>$sl->server_nonce)); - $lastRes=$res[0]; - $info=$sl->otpParamsFromInfoString($lastRes['info']); - $res=array('queued'=>$lastRes['queued'], - 'modified'=>$lastRes['modified'], - 'otp'=>$lastRes['otp'], - 'server'=>$lastRes['server'], - 'nonce'=>$info['nonce'], - 'yk_publicname'=>$info['yk_publicname'], - 'yk_counter'=>$info['yk_counter'], - 'yk_use'=>$info['yk_use'], - 'yk_high'=>$info['yk_high'], - 'yk_low'=>$info['yk_low']); - - - $this->assertNull($res['queued']); - - - } - -} -?> \ No newline at end of file diff --git a/tests/test-multi.php b/tests/test-multi.php deleted file mode 100644 index 29201cc..0000000 --- a/tests/test-multi.php +++ /dev/null @@ -1,22 +0,0 @@ -'; - -$r = retrieveURLasync($data); -if ($r) { - print "ok $r"; - } else { - print "err"; - } - -?>