From 05c970095d3e5fdce711aa92df7b79c027368ff6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 4 Sep 2013 17:15:08 +0200 Subject: [PATCH 01/13] Test whether an expired user share is still accessible. --- tests/lib/share/share.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index e7d441a7e7..bce041a06f 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -264,6 +264,39 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); } + public function testShareWithUserExpirationExpired() + { + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ), + 'Failed asserting that user 1 successfully shared text.txt with user 2.' + ); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that test.txt is a shared file of user 1.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 has access to test.txt after initial sharing.' + ); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00'), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 no longer has access to test.txt after expiration.' + ); + } + public function testShareWithGroup() { // Invalid shares $message = 'Sharing test.txt failed, because the group foobar does not exist'; From 1358b0078ab60efe341db0d7768ad9cdfe4e2bea Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 4 Sep 2013 17:26:30 +0200 Subject: [PATCH 02/13] Test whether a still-valid user share is still accessible. --- tests/lib/share/share.php | 47 +++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index bce041a06f..cf211817e3 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -265,6 +265,41 @@ class Test_Share extends PHPUnit_Framework_TestCase { } public function testShareWithUserExpirationExpired() + { + $this->shareUserOneTestFileWithUserTwo(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00'), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 no longer has access to test.txt after expiration.' + ); + } + + public function testShareWithUserExpirationValid() + { + $this->shareUserOneTestFileWithUserTwo(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', '2037-01-01 00:00'), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.' + ); + } + + protected function shareUserOneTestFileWithUserTwo() { OC_User::setUserId($this->user1); $this->assertTrue( @@ -283,18 +318,6 @@ class Test_Share extends PHPUnit_Framework_TestCase { OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), 'Failed asserting that user 2 has access to test.txt after initial sharing.' ); - - OC_User::setUserId($this->user1); - $this->assertTrue( - OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00'), - 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' - ); - - OC_User::setUserId($this->user2); - $this->assertFalse( - OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), - 'Failed asserting that user 2 no longer has access to test.txt after expiration.' - ); } public function testShareWithGroup() { From 924a7046dd496ee5f8fb53cd7cbe7bab10b2ecd2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 5 Sep 2013 00:15:58 +0200 Subject: [PATCH 03/13] Try to make Oracle happy by also specifying seconds. --- tests/lib/share/share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index cf211817e3..cd108a24f4 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -270,7 +270,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_User::setUserId($this->user1); $this->assertTrue( - OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00'), + OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00:00'), 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' ); @@ -287,7 +287,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_User::setUserId($this->user1); $this->assertTrue( - OCP\Share::setExpirationDate('test', 'test.txt', '2037-01-01 00:00'), + OCP\Share::setExpirationDate('test', 'test.txt', '2037-01-01 00:00:00'), 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' ); From e4b334c3f199b210fbd18b619f65cac44795dd7c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 5 Sep 2013 02:27:29 +0200 Subject: [PATCH 04/13] Make dates test class properties. --- tests/lib/share/share.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index cd108a24f4..c82ede2f38 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -30,6 +30,9 @@ class Test_Share extends PHPUnit_Framework_TestCase { protected $group2; protected $resharing; + protected $dateInPast = '2000-01-01 00:00:00'; + protected $dateInFuture = '2037-01-01 00:00:00'; + public function setUp() { OC_User::clearBackends(); OC_User::useBackend('dummy'); @@ -270,7 +273,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_User::setUserId($this->user1); $this->assertTrue( - OCP\Share::setExpirationDate('test', 'test.txt', '2000-01-01 00:00:00'), + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast), 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' ); @@ -287,7 +290,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_User::setUserId($this->user1); $this->assertTrue( - OCP\Share::setExpirationDate('test', 'test.txt', '2037-01-01 00:00:00'), + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture), 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' ); From cf97eac4010a19b1d9baba02970f825c157fbabe Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 5 Sep 2013 02:31:54 +0200 Subject: [PATCH 05/13] Do not repeat shareUserOneTestFileWithUserTwo() code. --- tests/lib/share/share.php | 47 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index c82ede2f38..af69c68c19 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -124,6 +124,27 @@ class Test_Share extends PHPUnit_Framework_TestCase { } } + protected function shareUserOneTestFileWithUserTwo() + { + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ), + 'Failed asserting that user 1 successfully shared text.txt with user 2.' + ); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that test.txt is a shared file of user 1.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 has access to test.txt after initial sharing.' + ); + } + public function testShareWithUser() { // Invalid shares $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; @@ -149,10 +170,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { } // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ)); - $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user2); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); + $this->shareUserOneTestFileWithUserTwo(); // Attempt to share again OC_User::setUserId($this->user1); @@ -302,27 +320,6 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } - protected function shareUserOneTestFileWithUserTwo() - { - OC_User::setUserId($this->user1); - $this->assertTrue( - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ), - 'Failed asserting that user 1 successfully shared text.txt with user 2.' - ); - $this->assertEquals( - array('test.txt'), - OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), - 'Failed asserting that test.txt is a shared file of user 1.' - ); - - OC_User::setUserId($this->user2); - $this->assertEquals( - array('test.txt'), - OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), - 'Failed asserting that user 2 has access to test.txt after initial sharing.' - ); - } - public function testShareWithGroup() { // Invalid shares $message = 'Sharing test.txt failed, because the group foobar does not exist'; From fb650deaf73fb622012345c22dabf266f93a9923 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 5 Sep 2013 02:41:24 +0200 Subject: [PATCH 06/13] Expiration tests for sharing with groups. --- tests/lib/share/share.php | 82 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index af69c68c19..98f3045201 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -320,6 +320,34 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } + protected function shareUserOneTestFileWithGroupOne() + { + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ), + 'Failed asserting that user 1 successfully shared text.txt with group 1.' + ); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that test.txt is a shared file of user 1.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 has access to test.txt after initial sharing.' + ); + + OC_User::setUserId($this->user3); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 has access to test.txt after initial sharing.' + ); + } + public function testShareWithGroup() { // Invalid shares $message = 'Sharing test.txt failed, because the group foobar does not exist'; @@ -341,12 +369,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC_Appconfig::setValue('core', 'shareapi_share_policy', $policy); // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ)); - $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user2); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); - OC_User::setUserId($this->user3); - $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE)); + $this->shareUserOneTestFileWithGroupOne(); // Attempt to share again OC_User::setUserId($this->user1); @@ -466,4 +489,51 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array(), OCP\Share::getItemsShared('test')); } + public function testShareWithGroupExpirationExpired() + { + $this->shareUserOneTestFileWithGroupOne(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 no longer has access to test.txt after expiration.' + ); + + OC_User::setUserId($this->user3); + $this->assertFalse( + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 no longer has access to test.txt after expiration.' + ); + } + + public function testShareWithGroupExpirationValid() + { + $this->shareUserOneTestFileWithGroupOne(); + + OC_User::setUserId($this->user1); + $this->assertTrue( + OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture), + 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' + ); + + OC_User::setUserId($this->user2); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 2 still has access to test.txt after expiration date has been set.' + ); + + OC_User::setUserId($this->user3); + $this->assertEquals( + array('test.txt'), + OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), + 'Failed asserting that user 3 still has access to test.txt after expiration date has been set.' + ); + } } From f567bd1b8a290f306c829eeb376d40dcf522bb6f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 5 Sep 2013 02:45:52 +0200 Subject: [PATCH 07/13] Coding style: { for methods start are supposed to be on the same line. --- tests/lib/share/share.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 98f3045201..c35e608df1 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -124,8 +124,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { } } - protected function shareUserOneTestFileWithUserTwo() - { + protected function shareUserOneTestFileWithUserTwo() { OC_User::setUserId($this->user1); $this->assertTrue( OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ), @@ -285,8 +284,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET)); } - public function testShareWithUserExpirationExpired() - { + public function testShareWithUserExpirationExpired() { $this->shareUserOneTestFileWithUserTwo(); OC_User::setUserId($this->user1); @@ -302,8 +300,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } - public function testShareWithUserExpirationValid() - { + public function testShareWithUserExpirationValid() { $this->shareUserOneTestFileWithUserTwo(); OC_User::setUserId($this->user1); @@ -320,8 +317,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } - protected function shareUserOneTestFileWithGroupOne() - { + protected function shareUserOneTestFileWithGroupOne() { OC_User::setUserId($this->user1); $this->assertTrue( OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ), @@ -489,8 +485,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { $this->assertEquals(array(), OCP\Share::getItemsShared('test')); } - public function testShareWithGroupExpirationExpired() - { + public function testShareWithGroupExpirationExpired() { $this->shareUserOneTestFileWithGroupOne(); OC_User::setUserId($this->user1); @@ -512,8 +507,7 @@ class Test_Share extends PHPUnit_Framework_TestCase { ); } - public function testShareWithGroupExpirationValid() - { + public function testShareWithGroupExpirationValid() { $this->shareUserOneTestFileWithGroupOne(); OC_User::setUserId($this->user1); From 261766fe49438144e28d9a28a347db49c7c9c3aa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 10 Sep 2013 01:30:48 +0200 Subject: [PATCH 08/13] Add comment explaining how $dateInFuture was picked. --- tests/lib/share/share.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index c35e608df1..a0ac55d91c 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -31,6 +31,8 @@ class Test_Share extends PHPUnit_Framework_TestCase { protected $resharing; protected $dateInPast = '2000-01-01 00:00:00'; + + // Picked close to the "year 2038 problem" boundary. protected $dateInFuture = '2037-01-01 00:00:00'; public function setUp() { From 7f07d737f85fcf511219f44d5369b352b9f0e067 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 10 Sep 2013 19:14:30 +0200 Subject: [PATCH 09/13] Create instance of Doctrine\Common\EventManager() in OC_DB. --- lib/db.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/db.php b/lib/db.php index f090f47424..bd67937cdd 100644 --- a/lib/db.php +++ b/lib/db.php @@ -75,6 +75,7 @@ class OC_DB { // do nothing if the connection already has been established if (!self::$connection) { $config = new \Doctrine\DBAL\Configuration(); + $eventManager = new \Doctrine\Common\EventManager(); switch($type) { case 'sqlite': case 'sqlite3': @@ -142,7 +143,7 @@ class OC_DB { $connectionParams['wrapperClass'] = 'OC\DB\Connection'; $connectionParams['tablePrefix'] = OC_Config::getValue('dbtableprefix', 'oc_' ); try { - self::$connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); + self::$connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config, $eventManager); if ($type === 'sqlite' || $type === 'sqlite3') { // Sqlite doesn't handle query caching and schema changes // TODO: find a better way to handle this From 786017c2472067997239f7b225ed22fd24cab264 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 10 Sep 2013 19:15:06 +0200 Subject: [PATCH 10/13] Register EventSubscriber that resets Oracle's NLS_DATE_FORMAT etc. --- lib/db.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/db.php b/lib/db.php index bd67937cdd..b9505b88d8 100644 --- a/lib/db.php +++ b/lib/db.php @@ -124,6 +124,7 @@ class OC_DB { $connectionParams['port'] = $port; } $connectionParams['adapter'] = '\OC\DB\AdapterOCI8'; + $eventManager->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\OracleSessionInit); break; case 'mssql': $connectionParams = array( From bd1163b7d571f13d7a2a90e559661b4b2e955917 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 12 Sep 2013 22:36:28 +0200 Subject: [PATCH 11/13] Add database tests for INSERT/SELECT date format. --- tests/data/db_structure.xml | 21 ++++++++++++++++++++ tests/data/db_structure2.xml | 21 ++++++++++++++++++++ tests/lib/db.php | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml index 8f6dc5e2ec..2e83bbb78c 100644 --- a/tests/data/db_structure.xml +++ b/tests/data/db_structure.xml @@ -178,4 +178,25 @@ + + *dbprefix*timestamp + + + id + 1 + integer + 0 + true + 4 + + + + timestamptest + timestamp + + false + + +
+ diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index 6f12f81f47..bbfb24985c 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -75,4 +75,25 @@ + + *dbprefix*timestamp + + + id + 1 + integer + 0 + true + 4 + + + + timestamptest + timestamp + + false + + +
+ diff --git a/tests/lib/db.php b/tests/lib/db.php index 1977025cf1..befb52ee19 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -145,4 +145,42 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertEquals(1, $result->numRows()); } + + /** + * Tests whether the database is configured so it accepts and returns dates + * in the expected format. + */ + public function testTimestampDateFormat() { + $table = '*PREFIX*'.$this->test_prefix.'timestamp'; + $column = 'timestamptest'; + + $expectedFormat = 'Y-m-d H:i:s'; + $now = new \DateTime; + + $query = OC_DB::prepare("INSERT INTO `$table` (`$column`) VALUES (?)"); + $result = $query->execute(array($now->format($expectedFormat))); + $this->assertEquals( + 1, + $result, + "Database failed to accept dates in the format '$expectedFormat'." + ); + + $id = OC_DB::insertid($table); + $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `id` = ?"); + $result = $query->execute(array($id)); + $row = $result->fetchRow(); + + $dateFromDb = \DateTime::createFromFormat($expectedFormat, $row[$column]); + $this->assertInstanceOf( + '\DateTime', + $dateFromDb, + "Database failed to return dates in the format '$expectedFormat'." + ); + + $this->assertEquals( + $now->format('c u'), + $dateFromDb->format('c u'), + 'Failed asserting that the returned date is the same as the inserted.' + ); + } } From 20b799b2b49ab301e744d2caab239a278df92ce6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 12 Sep 2013 22:52:14 +0200 Subject: [PATCH 12/13] Compare objects directly. Also use $expected and $actual. --- tests/lib/db.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/lib/db.php b/tests/lib/db.php index befb52ee19..c87bee4ab9 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -155,10 +155,10 @@ class Test_DB extends PHPUnit_Framework_TestCase { $column = 'timestamptest'; $expectedFormat = 'Y-m-d H:i:s'; - $now = new \DateTime; + $expected = new \DateTime; $query = OC_DB::prepare("INSERT INTO `$table` (`$column`) VALUES (?)"); - $result = $query->execute(array($now->format($expectedFormat))); + $result = $query->execute(array($expected->format($expectedFormat))); $this->assertEquals( 1, $result, @@ -170,16 +170,16 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array($id)); $row = $result->fetchRow(); - $dateFromDb = \DateTime::createFromFormat($expectedFormat, $row[$column]); + $actual = \DateTime::createFromFormat($expectedFormat, $row[$column]); $this->assertInstanceOf( '\DateTime', - $dateFromDb, + $actual, "Database failed to return dates in the format '$expectedFormat'." ); $this->assertEquals( - $now->format('c u'), - $dateFromDb->format('c u'), + $expected, + $actual, 'Failed asserting that the returned date is the same as the inserted.' ); } From 294f3632e0506cf49ca65dff1ae05cb5324a8839 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 12 Sep 2013 23:37:43 +0200 Subject: [PATCH 13/13] Calculate dateInPast and dateInFuture. --- tests/lib/share/share.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index a0ac55d91c..e02b0e4354 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -29,11 +29,8 @@ class Test_Share extends PHPUnit_Framework_TestCase { protected $group1; protected $group2; protected $resharing; - - protected $dateInPast = '2000-01-01 00:00:00'; - - // Picked close to the "year 2038 problem" boundary. - protected $dateInFuture = '2037-01-01 00:00:00'; + protected $dateInFuture; + protected $dateInPast; public function setUp() { OC_User::clearBackends(); @@ -63,6 +60,12 @@ class Test_Share extends PHPUnit_Framework_TestCase { OC::registerShareHooks(); $this->resharing = OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'); OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes'); + + // 20 Minutes in the past, 20 minutes in the future. + $now = time(); + $dateFormat = 'Y-m-d H:i:s'; + $this->dateInPast = date($dateFormat, $now - 20 * 60); + $this->dateInFuture = date($dateFormat, $now + 20 * 60); } public function tearDown() {