diff options
author | Chris Cornutt <chris.cornutt@hp.com> | 2015-01-30 15:52:48 -0600 |
---|---|---|
committer | Chris Cornutt <chris.cornutt@hp.com> | 2015-01-30 15:52:48 -0600 |
commit | e909cd236d24dd4ab3e286b7083cefcab1cc8320 (patch) | |
tree | e050ee8c67d0de173155fee46cb1455d5fafa0f2 | |
parent | fc9b34d8882a77d6be2a3fcf006200c1e81cf195 (diff) | |
download | gatekeeper-e909cd236d24dd4ab3e286b7083cefcab1cc8320.zip gatekeeper-e909cd236d24dd4ab3e286b7083cefcab1cc8320.tar.gz gatekeeper-e909cd236d24dd4ab3e286b7083cefcab1cc8320.tar.bz2 |
adding more tests for the group model child handling
-rw-r--r-- | tests/Psecio/Gatekeeper/GroupModelTest.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/Psecio/Gatekeeper/GroupModelTest.php b/tests/Psecio/Gatekeeper/GroupModelTest.php index c71a296..ef25e90 100644 --- a/tests/Psecio/Gatekeeper/GroupModelTest.php +++ b/tests/Psecio/Gatekeeper/GroupModelTest.php @@ -128,4 +128,54 @@ class GroupModelTest extends \Psecio\Gatekeeper\Base $this->assertFalse($group1->addChild($group2)); } + + /** + * Remove a valid child of the group by ID + */ + public function testRemoveChildByIdValid() + { + $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Stub') + ->disableOriginalConstructor() + ->setMethods(array('find', 'delete')) + ->getMock(); + + $group = new GroupModel($ds, array('id' => 1234)); + $ds->method('find')->willReturn($group); + $ds->method('delete')->willReturn(true); + + $this->assertTrue($group->removeChild(1)); + } + + /** + * Remove a valid child of the group by model instance + */ + public function testRemoveChildByModelValid() + { + $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Stub') + ->disableOriginalConstructor() + ->setMethods(array('find', 'delete')) + ->getMock(); + + $group1 = new GroupModel($ds, array('id' => 1234)); + $group2 = new GroupModel($ds, array('id' => 4321)); + + $ds->method('find')->willReturn($group1); + $ds->method('delete')->willReturn(true); + + $this->assertTrue($group1->removeChild($group2)); + } + + /** + * Test the false return of tyring to remove a child when no ID + * is set on the parent group + */ + public function testRemoveChildNoId() + { + $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql') + ->disableOriginalConstructor() + ->getMock(); + + $group = new GroupModel($ds); + $this->assertFalse($group->removeChild(1)); + } } |