Ejemplo n.º 1
0
 public function testMergeRemovedDocument()
 {
     $user = new CmsUser();
     $user->username = "******";
     $user->name = "Benjamin";
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->remove($user);
     $this->setExpectedException('\\Doctrine\\ODM\\PHPCR\\Exception\\InvalidArgumentException', "Removed document detected during merge at '/functional/beberlei'. Cannot merge with a removed document.");
     $this->dm->merge($user);
 }
Ejemplo n.º 2
0
 public function testComputingBetweenEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::prePersist, Event::postPersist, Event::preUpdate, Event::postUpdate, Event::preMove, Event::postMove), $this->listener);
     // Create initial user
     $user = new \Doctrine\Tests\Models\CMS\CmsUser();
     $user->name = 'mdekrijger';
     $user->username = '******';
     $user->status = 'active';
     // In prepersist the name will be changed
     // In postpersist the username will be changed
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     // Post persist data is not saved to document, so check before reloading document
     $this->assertTrue($user->username == 'postpersist');
     // Be sure that document is really saved by refetching it from ODM
     $user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $user->id);
     $this->assertEquals('prepersist', $user->name);
     $this->assertEquals('active', $user->status);
     // Change document
     // In preupdate the name will be changed
     // In postupdate the username will be changed
     $user->status = 'changed';
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     // Post persist data is not saved to document, so check before reloading document
     $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->assertEquals('preupdate', $user->name);
     $this->assertEquals('changed', $user->status);
     // 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();
     $user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $targetPath);
     // 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
     $this->dm->remove($user);
     $this->dm->flush();
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Doctrine\ODM\PHPCR\Exception\InvalidArgumentException
  */
 public function testDetachWithRemove()
 {
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $user->username = "******";
     $this->dm->detach($user);
     $this->dm->remove($user);
 }
Ejemplo n.º 4
0
 /**
  * Remove the parent node of multiple child level
  */
 public function testRemove3()
 {
     $parent = new ChildTestObj();
     $parent->name = 'Parent';
     $parent->id = '/functional/childtest';
     // Lv1
     $childLv1 = new ChildReferenceableTestObj();
     $childLv1->name = 'Child-Lv1';
     $parent->child = $childLv1;
     // Lv2
     $childLv2 = new ChildChildTestObj();
     $childLv2->name = 'Child-Lv2';
     $childLv1->aChild = $childLv2;
     $this->dm->persist($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find($this->type, '/functional/childtest');
     $this->assertTrue($this->node->hasNode('childtest'));
     $this->assertTrue($this->node->getNode('childtest')->hasNode('test'));
     $this->assertTrue($this->node->getNode('childtest')->getNode('test')->hasNode('test'));
     $this->dm->remove($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find($this->type, '/functional/childtest');
     $this->assertNull($parent);
 }
Ejemplo n.º 5
0
 /**
  * @expectedException \Doctrine\ODM\PHPCR\Exception\InvalidArgumentException
  */
 public function testRemoveAndInsertBeforeFlush()
 {
     $this->dm->clear();
     $user = $this->dm->find($this->type, '/functional/user');
     $this->assertNotNull($user, 'User must exist');
     $this->dm->remove($user);
     $user = new User2();
     $user->username = "******";
     $user->id = '/functional/user';
     $this->dm->persist($user);
 }
Ejemplo n.º 6
0
 public function testRemoveChildParent()
 {
     $this->createChildren();
     $parent = $this->dm->find($this->type, '/functional/parent');
     $this->assertCount(4, $parent->allChildren);
     $this->dm->remove($parent);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find($this->type, '/functional/parent');
     $this->assertNull($parent);
 }
Ejemplo n.º 7
0
 /**
  * Remove file
  *
  * @param  string $path file path
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function _unlink($path)
 {
     if ($doc = $this->dm->find(null, $path)) {
         try {
             $this->dm->remove($doc);
             $this->dm->flush();
             return true;
         } catch (\Exception $e) {
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 8
0
 public function testRemoveThenMove()
 {
     $this->dm->clear();
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertNotNull($user, 'User must exist');
     $this->dm->remove($user);
     $this->dm->move($user, '/functional/user2');
     $this->dm->flush();
     $user = $this->dm->find($this->type, '/functional/user2');
     $this->assertNotNull($user, 'User must exist');
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertNull($user, 'User must be null after deletion');
 }
Ejemplo n.º 9
0
 public function testDeleteByRef()
 {
     $referrerTestObj = new ReferrerTestObj();
     $referrerRefTestObj = new ReferrerRefTestObj();
     $referrerTestObj->id = "/functional/referrerTestObj";
     $referrerTestObj->name = 'referrer';
     $referrerRefTestObj->id = "/functional/referrerRefTestObj";
     $referrerTestObj->reference = $referrerRefTestObj;
     $this->dm->persist($referrerTestObj);
     $this->dm->flush();
     $this->dm->clear();
     $reference = $this->dm->find(null, "/functional/referrerRefTestObj");
     $this->dm->remove($reference->referrers[0]);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertCount(0, $this->dm->find(null, "/functional/referrerRefTestObj")->referrers);
     $this->assertFalse($this->session->getNode("/functional")->hasNode("referrerTestObj"));
 }
 /**
  * {@inheritDoc}
  *
  * @throws ModelManagerException if anything goes wrong during query execution.
  */
 public function batchDelete($class, ProxyQueryInterface $queryProxy)
 {
     try {
         $i = 0;
         $res = $queryProxy->execute();
         foreach ($res as $object) {
             $this->dm->remove($object);
             if (++$i % 20 == 0) {
                 $this->dm->flush();
                 $this->dm->clear();
             }
         }
         $this->dm->flush();
         $this->dm->clear();
     } catch (\Exception $e) {
         throw new ModelManagerException('', 0, $e);
     }
 }
Ejemplo n.º 11
0
 public function testFindVersionByNameWithReference()
 {
     $doc = $this->dm->find($this->typeVersion, '/functional/versionTestObjWithReference');
     $this->dm->checkpoint($doc);
     // Create a new version 1.0
     // Delete the reference in the doc, persist and checkpoint the doc
     $doc->reference = null;
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->checkpoint($doc);
     // Create a new version 1.1
     // Remove the reference obj
     $referenceDoc = $this->dm->find($this->typeReference, '/functional/referenceTestObj');
     $this->dm->remove($referenceDoc);
     $this->dm->flush();
     $this->dm->clear();
     $frozenDocument = $this->dm->findVersionByName($this->typeVersion, '/functional/versionTestObjWithReference', '1.0');
     $this->assertNull($frozenDocument->reference);
 }
Ejemplo n.º 12
0
 public function testRemove()
 {
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->dm->bindTranslation($this->doc, 'fr');
     $this->dm->flush();
     $this->dm->remove($this->doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->doc = $this->dm->find($this->class, '/functional/' . $this->testNodeName);
     $this->assertNull($this->doc, 'Document must be null after deletion');
     $this->doc = new Article();
     $this->doc->id = '/functional/' . $this->testNodeName;
     $this->doc->author = 'John Doe';
     $this->doc->topic = 'Some interesting subject';
     $this->doc->setText('Lorem ipsum...');
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->dm->flush();
     $locales = $this->dm->getLocalesFor($this->doc);
     $this->assertEquals(array('en'), $locales, 'Removing a document must remove all translations');
 }
Ejemplo n.º 13
0
 public function testManyCascadeWithParentDelete()
 {
     $refManyTestObjForCascade = new RefManyWithParentTestObjForCascade();
     $refManyTestObjForCascade->id = "/functional/refManyWithParentTestObjForCascade";
     $references = array();
     for ($i = 0; $i < 3; $i++) {
         $newRefCascadeManyTestObj = new ParentTestObj();
         $newRefCascadeManyTestObj->nodename = "ref{$i}";
         $newRefCascadeManyTestObj->name = "refCascadeWithParentManyTestObj{$i}";
         $references[] = $newRefCascadeManyTestObj;
     }
     $refManyTestObjForCascade->setReferences($references);
     $this->dm->persist($refManyTestObjForCascade);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertTrue($this->session->getNode("/functional")->hasNode("refManyWithParentTestObjForCascade"));
     for ($i = 0; $i < 3; $i++) {
         $this->assertTrue($this->session->getNode("/functional/refManyWithParentTestObjForCascade")->hasNode("ref{$i}"));
     }
     $referrer = $this->dm->find($this->referrerManyWithParentForCascadeType, '/functional/refManyWithParentTestObjForCascade');
     $this->dm->remove($referrer);
     $this->dm->flush();
     $this->assertFalse($this->session->getNode("/functional")->hasNode("refManyWithParentTestObjForCascade"));
 }
Ejemplo n.º 14
0
 /**
  * @expectedException \Doctrine\ODM\PHPCR\Exception\InvalidArgumentException
  */
 public function testReorderAfterRemove()
 {
     $parent = $this->dm->find(null, '/functional/source');
     $this->dm->remove($parent);
     $this->dm->reorder($parent, 'first', 'second', false);
 }
Ejemplo n.º 15
0
 public function testTriggerEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::prePersist, Event::postPersist, Event::preUpdate, Event::postUpdate, Event::preRemove, Event::postRemove, Event::onFlush, Event::postFlush, Event::preFlush, Event::preMove, Event::postMove, Event::endFlush), $this->listener);
     $page = new CmsPage();
     $page->title = "my-page";
     $page->content = "long story";
     $this->dm->persist($page);
     $this->assertTrue($this->listener->pagePrePersist);
     $this->assertFalse($this->listener->itemPrePersist);
     $this->assertFalse($this->listener->postFlush);
     $this->assertFalse($this->listener->endFlush);
     $this->assertFalse($this->listener->preFlush);
     $this->dm->flush();
     $this->assertTrue($this->listener->onFlush);
     $this->assertTrue($this->listener->postFlush);
     $this->assertTrue($this->listener->endFlush);
     $this->assertTrue($this->listener->preFlush);
     $this->assertFalse($this->listener->preUpdate);
     $this->assertFalse($this->listener->postUpdate);
     $this->assertTrue($this->listener->pagePostPersist);
     $this->assertFalse($this->listener->itemPostPersist);
     $this->assertFalse($this->listener->pagePreRemove);
     $this->assertFalse($this->listener->pagePostRemove);
     $this->assertFalse($this->listener->itemPreRemove);
     $this->assertFalse($this->listener->pagePreMove);
     $this->assertFalse($this->listener->pagePostMove);
     $this->assertFalse($this->listener->itemPreMove);
     $this->assertFalse($this->listener->itemPostMove);
     $this->dm->move($page, '/functional/moved-' . $page->title);
     $this->assertFalse($this->listener->pagePreMove);
     $this->assertFalse($this->listener->pagePostMove);
     $this->dm->flush();
     $this->assertTrue($this->listener->pagePreMove);
     $this->assertTrue($this->listener->pagePostMove);
     $this->assertFalse($this->listener->itemPreMove);
     $this->assertFalse($this->listener->itemPostMove);
     $this->dm->flush();
     $item = new CmsItem();
     $item->name = "my-item";
     $item->documentTarget = $page;
     $page->content = "short story";
     $this->dm->persist($item);
     $page->addItem($item);
     $this->dm->flush();
     $this->assertTrue($this->listener->preUpdate);
     $this->assertTrue($this->listener->itemPrePersist);
     $this->assertTrue($this->listener->postUpdate);
     $this->assertTrue($this->listener->itemPostPersist);
     $this->assertEquals('long story is now short story', $page->content);
     $pageId = $this->dm->getUnitOfWork()->getDocumentId($page);
     $itemId = $this->dm->getUnitOfWork()->getDocumentId($item);
     $this->dm->clear();
     $page = $this->dm->find(null, $pageId);
     $item = $this->dm->find(null, $itemId);
     $this->assertEquals('long story is now short story', $page->content);
     $this->dm->remove($item);
     $this->dm->remove($page);
     $this->assertTrue($this->listener->pagePreRemove);
     $this->assertTrue($this->listener->itemPreRemove);
     $this->assertFalse($this->listener->pagePostRemove);
     $this->assertFalse($this->listener->itemPostRemove);
     $this->assertFalse($this->dm->contains($page));
     $this->assertFalse($this->dm->contains($item));
     $this->dm->flush();
     $this->assertFalse($this->dm->contains($page));
     $this->assertFalse($this->dm->contains($item));
     $this->assertTrue($this->listener->pagePostRemove);
     $this->assertTrue($this->listener->itemPostRemove);
 }