From e62fb0b48efb4c40d2aa7a071b8f550e7d83c209 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 15 Nov 2010 19:03:09 +0100 Subject: [PATCH] DDC-849 - Test verifies all different behaviors, clear contains, remove contains and clear count to be correct. --- .../ORM/Functional/Ticket/DDC849Test.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php new file mode 100644 index 000000000..45ff132cd --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php @@ -0,0 +1,84 @@ +useModelSet('cms'); + parent::setUp(); + + $this->user = new CmsUser(); + $this->user->username = "beberlei"; + $this->user->name = "Benjamin"; + $this->user->status = "active"; + + $this->group1 = new CmsGroup(); + $this->group1->name = "Group 1"; + $this->group2 = new CmsGroup(); + $this->group2->name = "Group 2"; + + $this->user->addGroup($this->group1); + $this->user->addGroup($this->group2); + + $this->_em->persist($this->user); + $this->_em->persist($this->group1); + $this->_em->persist($this->group2); + + $this->_em->flush(); + $this->_em->clear(); + + $this->user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->user->getId()); + } + + public function testRemoveContains() + { + $group1 = $this->user->groups[0]; + $group2 = $this->user->groups[1]; + + $this->assertTrue($this->user->groups->contains($group1)); + $this->assertTrue($this->user->groups->contains($group2)); + + $this->user->groups->removeElement($group1); + $this->user->groups->remove(1); + + $this->assertFalse($this->user->groups->contains($group1)); + $this->assertFalse($this->user->groups->contains($group2)); + } + + public function testClearCount() + { + $this->user->addGroup(new CmsGroup); + $this->assertEquals(3, count($this->user->groups)); + + $this->user->groups->clear(); + + $this->assertEquals(0, $this->user->groups->count()); + $this->assertEquals(0, count($this->user->groups)); + } + + public function testClearContains() + { + $group1 = $this->user->groups[0]; + $group2 = $this->user->groups[1]; + + $this->assertTrue($this->user->groups->contains($group1)); + $this->assertTrue($this->user->groups->contains($group2)); + + $this->user->groups->clear(); + + $this->assertFalse($this->user->groups->contains($group1)); + $this->assertFalse($this->user->groups->contains($group2)); + } +} \ No newline at end of file