From 1a7b4c538347b9d9f1f55f96f3af8da7fedb6dd3 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Thu, 12 Jun 2014 10:52:36 +0200 Subject: [PATCH] added testcase of @UncleCoder https://github.com/UncleCoder/yii2/commit/e43c503c2d8408f46fb4ff09330db4e5a9f1cf01 issue #3817 --- tests/unit/framework/rbac/ManagerTestCase.php | 12 +++++++ tests/unit/framework/rbac/PhpManagerTest.php | 40 ++++++++++++++++++++++++ tests/unit/framework/rbac/PhpManagerTestCase.php | 40 ------------------------ 3 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 tests/unit/framework/rbac/PhpManagerTest.php delete mode 100644 tests/unit/framework/rbac/PhpManagerTestCase.php diff --git a/tests/unit/framework/rbac/ManagerTestCase.php b/tests/unit/framework/rbac/ManagerTestCase.php index d837f8f..335c05a 100644 --- a/tests/unit/framework/rbac/ManagerTestCase.php +++ b/tests/unit/framework/rbac/ManagerTestCase.php @@ -45,6 +45,18 @@ abstract class ManagerTestCase extends TestCase // todo: check duplication of name } + + public function testGetChildren() + { + $user = $this->auth->createRole('user'); + $this->auth->add($user); + $this->assertCount(0, $this->auth->getChildren($user->name)); + + $changeName = $this->auth->createPermission('changeName'); + $this->auth->add($changeName); + $this->auth->addChild($user, $changeName); + $this->assertCount(1, $this->auth->getChildren($user->name)); + } /* public function testRemove() { diff --git a/tests/unit/framework/rbac/PhpManagerTest.php b/tests/unit/framework/rbac/PhpManagerTest.php new file mode 100644 index 0000000..561905f --- /dev/null +++ b/tests/unit/framework/rbac/PhpManagerTest.php @@ -0,0 +1,40 @@ +mockApplication(); + $authFile = Yii::$app->getRuntimePath() . '/rbac.php'; + @unlink($authFile); + $this->auth = new PhpManager(); + $this->auth->authFile = $authFile; + $this->auth->init(); + } + + protected function tearDown() + { + parent::tearDown(); + @unlink($this->auth->authFile); + } + + public function testSaveLoad() + { + $this->prepareData(); + $this->auth->save(); + $this->auth->removeAll(); + $this->auth->load(); + // TODO : Check if loaded and saved data are the same. + } + +} \ No newline at end of file diff --git a/tests/unit/framework/rbac/PhpManagerTestCase.php b/tests/unit/framework/rbac/PhpManagerTestCase.php deleted file mode 100644 index 9c98b24..0000000 --- a/tests/unit/framework/rbac/PhpManagerTestCase.php +++ /dev/null @@ -1,40 +0,0 @@ -mockApplication(); - $authFile = Yii::$app->getRuntimePath() . '/rbac.php'; - @unlink($authFile); - $this->auth = new PhpManager(); - $this->auth->authFile = $authFile; - $this->auth->init(); - } - - protected function tearDown() - { - parent::tearDown(); - @unlink($this->auth->authFile); - } - - public function testSaveLoad() - { - $this->prepareData(); - $this->auth->save(); - $this->auth->clearAll(); - $this->auth->load(); - // TODO : Check if loaded and saved data are the same. - } - -} \ No newline at end of file