Permalink
Browse files

cleanup tests a bit

  • Loading branch information...
1 parent efe8417 commit a19a5cf52a906da887ca6c0f04126fbcf7553ad0 @dbu dbu committed Feb 23, 2013
@@ -43,7 +43,7 @@ public function testComputingBetweenEvents()
// Be sure that document is really saved by refetching it from ODM
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
- $this->assertTrue($user->name=='prepersist');
+ $this->assertEquals('prepersist', $user->name);
// Change document
// In preupdate the name will be changed
@@ -54,24 +54,28 @@ public function testComputingBetweenEvents()
$this->dm->clear();
// Post persist data is not saved to document, so check before reloading document
- $this->assertTrue($user->username=='postupdate');
+ $this->assertEquals('postupdate', $user->username);
// Be sure that document is really saved by refetching it from ODM
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
- $this->assertTrue($user->name=='preupdate');
+ $this->assertEquals('preupdate', $user->name);
- // Move test, Before move the path is /functional/preudpate and I move to /preupdate
- $targetPath = '/' . $user->name;
+ // Move from /functional/preudpate to /functional/moved
+ $targetPath = '/functional/moved';
$this->dm->move($user, $targetPath);
$this->dm->flush();
+ // we overwrote the name and username fields during the move event, so the object changed
+ $this->assertEquals('premove', $user->name);
+ $this->assertEquals('premove-postmove', $user->username);
+
$this->dm->clear();
- $this->assertTrue($user->username == 'premove-postmove');
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $targetPath);
- // The document is moved and do not be modified
- $this->assertTrue($user->name == 'preupdate');
+ // the document was moved but the only changes applied in preUpdate are persisted,
+ // pre/postMove changes are not persisted in that flush
+ $this->assertEquals('preupdate', $user->name);
$this->assertTrue($this->listener->preMove);
// Clean up
@@ -59,13 +59,22 @@ public function testTriggerEvents()
$this->assertFalse($this->listener->pagePreRemove);
$this->assertFalse($this->listener->pagePostRemove);
$this->assertFalse($this->listener->itemPreRemove);
- $this->assertFalse($this->listener->itemPostRemove);
+ $this->assertFalse($this->listener->pagePreMove);
+ $this->assertFalse($this->listener->pagePostMove);
+ $this->assertFalse($this->listener->itemPreMove);
+ $this->assertFalse($this->listener->itemPostMove);
$this->dm->move($page, '/' . $page->title);
+
+ $this->assertFalse($this->listener->pagePreMove);
+ $this->assertFalse($this->listener->pagePostMove);
+
$this->dm->flush();
- $this->assertTrue($this->listener->preMove);
- $this->assertTrue($this->listener->postMove);
+ $this->assertTrue($this->listener->pagePreMove);
+ $this->assertTrue($this->listener->pagePostMove);
+ $this->assertFalse($this->listener->itemPreMove);
+ $this->assertFalse($this->listener->itemPostMove);
$item = new CmsItem();
$item->name = "my-item";
@@ -115,8 +124,10 @@ class TestPersistenceListener
public $onFlush = false;
public $postFlush = false;
public $preFlush = false;
- public $preMove = false;
- public $postMove = false;
+ public $itemPreMove = false;
+ public $itemPostMove = false;
+ public $pagePreMove = false;
+ public $pagePostMove = false;
public function prePersist(EventArgs $e)
{
@@ -179,12 +190,22 @@ public function postRemove(EventArgs $e)
public function preMove(EventArgs $e)
{
- $this->preMove = true;
+ $document = $e->getDocument();
+ if ($document instanceof CmsPage){
+ $this->pagePreMove = true;
+ } else if ($document instanceof CmsItem){
+ $this->itemPreMove = true;
+ }
}
public function postMove(EventArgs $e)
{
- $this->postMove = true;
+ $document = $e->getDocument();
+ if ($document instanceof CmsPage){
+ $this->pagePostMove = true;
+ } else if ($document instanceof CmsItem){
+ $this->itemPostMove = true;
+ }
}
public function onFlush(EventArgs $e)

0 comments on commit a19a5cf

Please sign in to comment.