]> source.dussan.org Git - nextcloud-server.git/commitdiff
Do not use uniqid in Group and User tests as it is not unique on windows
authorJoas Schilling <nickvergessen@gmx.de>
Wed, 5 Nov 2014 11:21:02 +0000 (12:21 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Wed, 19 Nov 2014 09:06:05 +0000 (10:06 +0100)
tests/lib/group.php
tests/lib/group/backend.php
tests/lib/group/database.php
tests/lib/group/dummy.php
tests/lib/user/backend.php
tests/lib/user/database.php
tests/lib/user/dummy.php

index 724e723b1871aa922977fcf37ee64e88ebceed32..795de6955131b3a1b45acd5f18f5df072f528fa9 100644 (file)
  *
  */
 
-class Test_Group extends PHPUnit_Framework_TestCase {
-       function setUp() {
+class Test_Group extends \Test\TestCase {
+       protected function setUp() {
+               parent::setUp();
                OC_Group::clearBackends();
                OC_User::clearBackends();
        }
 
-       function testSingleBackend() {
+       public function testSingleBackend() {
                $userBackend = new \OC_User_Dummy();
                \OC_User::getManager()->registerBackend($userBackend);
                OC_Group::useBackend(new OC_Group_Dummy());
 
-               $group1 = uniqid();
-               $group2 = uniqid();
+               $group1 = $this->getUniqueID();
+               $group2 = $this->getUniqueID();
                OC_Group::createGroup($group1);
                OC_Group::createGroup($group2);
 
-               $user1 = uniqid();
-               $user2 = uniqid();
+               $user1 = $this->getUniqueID();
+               $user2 = $this->getUniqueID();
                $userBackend->createUser($user1, '');
                $userBackend->createUser($user2, '');
 
-               $this->assertFalse(OC_Group::inGroup($user1, $group1));
-               $this->assertFalse(OC_Group::inGroup($user2, $group1));
-               $this->assertFalse(OC_Group::inGroup($user1, $group2));
-               $this->assertFalse(OC_Group::inGroup($user2, $group2));
+               $this->assertFalse(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is not in group1');
+               $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1');
+               $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2');
+               $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2');
 
                $this->assertTrue(OC_Group::addToGroup($user1, $group1));
 
-               $this->assertTrue(OC_Group::inGroup($user1, $group1));
-               $this->assertFalse(OC_Group::inGroup($user2, $group1));
-               $this->assertFalse(OC_Group::inGroup($user1, $group2));
-               $this->assertFalse(OC_Group::inGroup($user2, $group2));
+               $this->assertTrue(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is in group1');
+               $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1');
+               $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2');
+               $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2');
 
                $this->assertTrue(OC_Group::addToGroup($user1, $group1));
 
@@ -80,7 +81,7 @@ class Test_Group extends PHPUnit_Framework_TestCase {
 
        public function testNoGroupsTwice() {
                OC_Group::useBackend(new OC_Group_Dummy());
-               $group = uniqid();
+               $group = $this->getUniqueID();
                OC_Group::createGroup($group);
 
                $groupCopy = $group;
@@ -103,7 +104,7 @@ class Test_Group extends PHPUnit_Framework_TestCase {
        public function testDontAddUserToNonexistentGroup() {
                OC_Group::useBackend(new OC_Group_Dummy());
                $groupNonExistent = 'notExistent';
-               $user = uniqid();
+               $user = $this->getUniqueID();
 
                $this->assertEquals(false, OC_Group::addToGroup($user, $groupNonExistent));
                $this->assertEquals(array(), OC_Group::getGroups());
@@ -114,12 +115,12 @@ class Test_Group extends PHPUnit_Framework_TestCase {
                $userBackend = new \OC_User_Dummy();
                \OC_User::getManager()->registerBackend($userBackend);
 
-               $group1 = uniqid();
-               $group2 = uniqid();
-               $group3 = uniqid();
-               $user1 = uniqid();
-               $user2 = uniqid();
-               $user3 = uniqid();
+               $group1 = $this->getUniqueID();
+               $group2 = $this->getUniqueID();
+               $group3 = $this->getUniqueID();
+               $user1 = $this->getUniqueID();
+               $user2 = $this->getUniqueID();
+               $user3 = $this->getUniqueID();
                OC_Group::createGroup($group1);
                OC_Group::createGroup($group2);
                OC_Group::createGroup($group3);
@@ -139,8 +140,7 @@ class Test_Group extends PHPUnit_Framework_TestCase {
                // FIXME: needs more parameter variation
        }
 
-
-       function testMultiBackend() {
+       public function testMultiBackend() {
                $userBackend = new \OC_User_Dummy();
                \OC_User::getManager()->registerBackend($userBackend);
                $backend1 = new OC_Group_Dummy();
@@ -148,8 +148,8 @@ class Test_Group extends PHPUnit_Framework_TestCase {
                OC_Group::useBackend($backend1);
                OC_Group::useBackend($backend2);
 
-               $group1 = uniqid();
-               $group2 = uniqid();
+               $group1 = $this->getUniqueID();
+               $group2 = $this->getUniqueID();
                OC_Group::createGroup($group1);
 
                //groups should be added to the first registered backend
@@ -166,8 +166,8 @@ class Test_Group extends PHPUnit_Framework_TestCase {
                $this->assertTrue(OC_Group::groupExists($group1));
                $this->assertTrue(OC_Group::groupExists($group2));
 
-               $user1 = uniqid();
-               $user2 = uniqid();
+               $user1 = $this->getUniqueID();
+               $user2 = $this->getUniqueID();
 
                $userBackend->createUser($user1, '');
                $userBackend->createUser($user2, '');
index 95a5cf5f49ca351dcdebb7372b1b349db692ef3e..62c189489d7c08c73385fe8c12f5c2aabcd3e68c 100644 (file)
@@ -20,7 +20,7 @@
 *
 */
 
-abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
+abstract class Test_Group_Backend extends \Test\TestCase {
        /**
         * @var OC_Group_Backend $backend
         */
@@ -33,7 +33,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
         */
        public function getGroupName($name = null) {
                if(is_null($name)) {
-                       return uniqid('test_');
+                       return $this->getUniqueID('test_');
                } else {
                        return $name;
                }
@@ -45,7 +45,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
         * @return string
         */
        public function getUserName() {
-               return uniqid('test_');
+               return $this->getUniqueID('test_');
        }
 
        public function testAddRemove() {
@@ -138,6 +138,4 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
                $result = $this->backend->countUsersInGroup($group, 'bar');
                $this->assertSame(2, $result);
        }
-
-
 }
index 9b39ac004524c0384d029ed6525972562fb25d9d..10958a6ccdceaa7d1e383a6b96e1e92a22250534 100644 (file)
 
 class Test_Group_Database extends Test_Group_Backend {
        private $groups=array();
-       
+
        /**
         * get a new unique group name
         * test cases can override this in order to clean up created groups
         * @return string
         */
        public function getGroupName($name = null) {
-               if(is_null($name)) {
-                       $name=uniqid('test_');
-               }
-               $this->groups[]=$name;
+               $name = parent::getGroupName($name);
+               $this->groups[] = $name;
                return $name;
        }
 
-       /**
-        * get a new unique user name
-        * test cases can override this in order to clean up created user
-        * @return string
-        */
-       public function getUserName() {
-               return uniqid('test_');
-       }
-       
-       public function setUp() {
+       protected function setUp() {
+               parent::setUp();
                $this->backend=new OC_Group_Database();
        }
 
-       public function tearDown() {
+       protected function tearDown() {
                foreach($this->groups as $group) {
                        $this->backend->deleteGroup($group);
                }
+               parent::tearDown();
        }
 }
index 287d6f1a977e5bb24350084bbf1eedde8a7ad03a..b4456c8f7e17163a3bc248047089c13a48a74d00 100644 (file)
@@ -21,7 +21,8 @@
 */
 
 class Test_Group_Dummy extends Test_Group_Backend {
-       public function setUp() {
+       protected function setUp() {
+               parent::setUp();
                $this->backend=new OC_Group_Dummy();
        }
 }
index 0d3914c7ca68d19afd58a9f7e2e9ffa7983978a3..c2040f4e3be48c1fe63fb291a4b3c8ef6c56b8c8 100644 (file)
@@ -30,7 +30,7 @@
  * For an example see /tests/lib/user/dummy.php
  */
 
-abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
+abstract class Test_User_Backend extends \Test\TestCase {
        /**
         * @var OC_User_Backend $backend
         */
@@ -42,7 +42,7 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
         * @return string
         */
        public function getUser() {
-               return uniqid('test_');
+               return $this->getUniqueID('test_');
        }
 
        public function testAddRemove() {
@@ -68,29 +68,29 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
                $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
                $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
        }
-       
+
        public function testLogin() {
                $name1=$this->getUser();
                $name2=$this->getUser();
-               
+
                $this->assertFalse($this->backend->userExists($name1));
                $this->assertFalse($this->backend->userExists($name2));
-               
+
                $this->backend->createUser($name1, 'pass1');
                $this->backend->createUser($name2, 'pass2');
-               
+
                $this->assertTrue($this->backend->userExists($name1));
                $this->assertTrue($this->backend->userExists($name2));
-               
+
                $this->assertSame($name1, $this->backend->checkPassword($name1, 'pass1'));
                $this->assertSame($name2, $this->backend->checkPassword($name2, 'pass2'));
-               
+
                $this->assertFalse($this->backend->checkPassword($name1, 'pass2'));
                $this->assertFalse($this->backend->checkPassword($name2, 'pass1'));
-               
+
                $this->assertFalse($this->backend->checkPassword($name1, 'dummy'));
                $this->assertFalse($this->backend->checkPassword($name2, 'foobar'));
-               
+
                $this->backend->setPassword($name1, 'newpass1');
                $this->assertFalse($this->backend->checkPassword($name1, 'pass1'));
                $this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1'));
@@ -112,5 +112,4 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
                $result = $this->backend->getDisplayNames('bar');
                $this->assertSame(2, count($result));
        }
-
 }
index a8e497720c235da83f0927fc61ae531eccdb0aa2..3a6be1ceee539540f6bd561987eef999257cb8a3 100644 (file)
 */
 
 class Test_User_Database extends Test_User_Backend {
+       /** @var array */
+       private $users;
+
        public function getUser() {
                $user = parent::getUser();
                $this->users[]=$user;
                return $user;
        }
-       
-       public function setUp() {
+
+       protected function setUp() {
+               parent::setUp();
                $this->backend=new OC_User_Database();
        }
-       
-       public function tearDown() {
+
+       protected function tearDown() {
                if(!isset($this->users)) {
                        return;
                }
                foreach($this->users as $user) {
                        $this->backend->deleteUser($user);
                }
+               parent::tearDown();
        }
 }
index e417fd97603677b5ee36cdd3e4533973b75bcad3..fcc921de4b12dac6ec847e843efbd1d11ea380ef 100644 (file)
@@ -21,7 +21,8 @@
 */
 
 class Test_User_Dummy extends Test_User_Backend {
-       public function setUp() {
+       protected function setUp() {
+               parent::setUp();
                $this->backend=new OC_User_Dummy();
        }
 }