Ejemplo n.º 1
0
 /**
  * @expectedException \Doctrine\ODM\PHPCR\Exception\InvalidArgumentException
  */
 public function testDetachWithMove()
 {
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $user->username = "******";
     $this->dm->detach($user);
     $this->dm->move($user, '/functional/user2');
 }
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
 public function testReorderAfterMove()
 {
     $parent = $this->dm->find(null, '/functional/source');
     $this->dm->move($parent, '/functional/target/new');
     $this->dm->reorder($parent, 'first', 'second', false);
     $this->dm->flush();
     $parent = $this->dm->find(null, '/functional/target/new');
     $this->assertSame(array('second', 'first', 'third', 'fourth'), $this->getChildrenNames($parent->getChildren()));
 }
Ejemplo n.º 4
0
 /**
  * @expectedException Doctrine\ODM\PHPCR\Exception\OutOfBoundsException
  * @expectedExceptionMessage Document "Doctrine\Tests\Models\CMS\CmsArticleFolder" does not allow children of type "Doctrine\Tests\Models\CMS\CmsGroup". Allowed child classes "Doctrine\Tests\Models\CMS\CmsArticle"
  */
 public function testRequiredClassesInvalidUpdate()
 {
     $articleFolder = new CmsArticleFolder();
     $articleFolder->id = '/functional/articles';
     $article = new CmsGroup();
     $article->id = '/functional/address';
     $article->name = 'invalid-child';
     $this->dm->persist($articleFolder);
     $this->dm->persist($article);
     $this->dm->flush();
     $this->dm->move($article, '/functional/articles/address');
     $this->dm->flush();
 }
Ejemplo n.º 5
0
 /**
  * Move file into another parent dir or rename file.
  * Return new file path or false.
  *
  * @param  string      $source    source file path
  * @param  string      $targetDir target dir path
  * @param  string      $name      file name
  * @return string|bool
  * @author Dmitry (dio) Levashov
  **/
 protected function _move($source, $targetDir, $name)
 {
     $filename = $this->_joinPath($targetDir, $name);
     $sourceDir = $this->_dirname($source);
     try {
         $doc = $this->dm->find(null, $source);
         // move
         $this->dm->move($doc, $filename);
         $this->dm->flush();
     } catch (\Exception $e) {
         return false;
     }
     return $filename;
 }
Ejemplo n.º 6
0
 public function testDepth()
 {
     $object = new DepthMappingObject();
     $object->id = '/functional/test';
     $this->dm->persist($object);
     $this->dm->flush();
     $this->dm->clear();
     $object = $this->dm->find(null, '/functional/test');
     $this->assertEquals(2, $object->depth);
     NodeHelper::createPath($this->dm->getPhpcrSession(), '/functional/newtest/foobar');
     $this->dm->move($object, '/functional/newtest/foobar/test');
     $this->dm->flush();
     $this->assertEquals(4, $object->depth);
 }
Ejemplo n.º 7
0
 /**
  * Move a child out of the children collection
  */
 public function testMoveChildren()
 {
     $this->createChildren();
     $parent = $this->dm->find($this->type, '/functional/parent');
     $child = $parent->allChildren->first();
     $this->dm->move($child, '/functional/elsewhere');
     $this->dm->flush();
     $this->dm->clear();
     $child = $this->dm->find(null, '/functional/elsewhere');
     $this->assertInstanceOf($this->type, $child);
     $parent = $this->dm->find(null, '/functional/parent');
     $this->assertInstanceOf($this->type, $parent);
     $this->assertCount(3, $parent->allChildren);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritDoc}
  */
 public function move($movedPath, $targetPath)
 {
     $resultingPath = $targetPath . '/' . basename($movedPath);
     $document = $this->dm->find(null, $movedPath);
     if (null === $document) {
         return "No document found at {$movedPath}";
     }
     $this->dm->move($document, $resultingPath);
     $this->dm->flush();
     $admin = $this->getAdmin($document);
     if (null !== $admin) {
         $id = $admin->getNormalizedIdentifier($document);
         $urlSafeId = $admin->getUrlsafeIdentifier($document);
     } else {
         $id = $this->defaultModelManager->getNormalizedIdentifier($document);
         $urlSafeId = $this->defaultModelManager->getUrlsafeIdentifier($document);
     }
     return array('id' => $id, 'url_safe_id' => $urlSafeId);
 }
Ejemplo n.º 9
0
 public function testMoveUpdateFields()
 {
     $this->dm->clear();
     $user1 = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertNotNull($user1, 'User must exist');
     $user2 = new CmsTeamUser();
     $user2->username = '******';
     $user2->parent = $user1;
     $user3 = new CmsTeamUser();
     $user3->username = '******';
     $user3->parent = $user2;
     $this->dm->persist($user3);
     $this->dm->flush();
     // property is updated after flush
     $this->assertEquals('beberlei', $user3->nodename);
     $this->assertSame($user2, $user3->parent);
     $this->dm->move($user3, '/functional/lsmith/user');
     $this->dm->flush();
     $this->assertEquals('user', $user3->nodename);
     $this->assertSame($user1, $user3->parent);
 }
Ejemplo n.º 10
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);
 }