Exemplo n.º 1
0
 public function testComputingBetweenEventsWithTranslation()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     // Create initial user
     $user = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
     $user->name = 'mdekrijger';
     $user->username = '******';
     $user->status = 'active';
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
     // username should be changed after loading the translation
     $this->assertEquals('loadTranslation', $user->username);
     // name had been changed pre binding translation
     $this->assertEquals('preCreateTranslation', $user->name);
     $this->dm->name = 'neuer Name';
     $this->dm->bindTranslation($user, 'de');
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
     $this->dm->removeTranslation($user, 'en');
     $this->assertEquals('preRemoveTranslation', $user->name);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertEquals('postRemoveTranslation', $user->username);
 }
 public function testLoadMany()
 {
     $user1 = new CmsUser();
     $user1->username = "******";
     $user1->status = "active";
     $user1->name = "Benjamin";
     $user2 = new CmsUser();
     $user2->username = "******";
     $user2->status = "active";
     $user2->name = "Lukas";
     $this->dm->persist($user1);
     $this->dm->persist($user2);
     $this->dm->flush();
     $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
     $this->assertSame($user1, $users['/functional/beberlei']);
     $this->assertSame($user2, $users['/functional/lsmith']);
     $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->node->getIdentifier(), substr($user2->id, 1)));
     $this->assertSame($user1, $users['/functional/beberlei']);
     $this->assertSame($user2, $users['/functional/lsmith']);
     $this->dm->clear();
     $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
     $this->assertTrue(isset($users['/functional/beberlei']));
     $this->assertTrue(isset($users['/functional/lsmith']));
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users['/functional/beberlei']);
     $this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users['/functional/lsmith']);
     $this->assertEquals($user1->username, $users['/functional/beberlei']->username);
     $this->assertEquals($user2->username, $users['/functional/lsmith']->username);
     $this->dm->clear();
     // read second document into memory
     $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->find($user2->id);
     $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
     $this->assertEquals('/functional/beberlei', $users->key(), 'Documents are not returned in the order they were requested');
 }
Exemplo n.º 3
0
 public function testResetEvents()
 {
     $page = new CmsPage();
     $page->title = "my-page";
     $pageContent = new CmsPageContent();
     $pageContent->id = 1;
     $pageContent->content = "long story";
     $pageContent->formatter = "plaintext";
     $page->content = $pageContent;
     $this->dm->persist($page);
     $this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content);
     $this->dm->flush();
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
     // This is required as the originalData in the UnitOfWork doesn’t set the node of the Document
     $this->dm->clear();
     $pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id);
     $pageLoaded->title = "my-page-changed";
     $this->assertEquals('my-page-changed', $pageLoaded->title);
     $this->dm->flush();
     $this->assertEquals('my-page', $pageLoaded->title);
     $pageLoaded->content = $pageContent;
     $this->dm->persist($pageLoaded);
     $this->dm->flush();
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
 }
Exemplo n.º 4
0
 public function testReferenceOneDifferentTargetDocuments()
 {
     $ref1 = new RefType1TestObj();
     $ref1->id = '/functional/ref1';
     $ref1->name = 'Ref1';
     $ref2 = new RefType2TestObj();
     $ref2->id = '/functional/ref2';
     $ref2->name = 'Ref2';
     $this->dm->persist($ref1);
     $this->dm->persist($ref2);
     $referer1 = new ReferenceOneObj();
     $referer1->id = '/functional/referer1';
     $referer1->reference = $ref1;
     $this->dm->persist($referer1);
     $referer2 = new ReferenceOneObj();
     $referer2->id = '/functional/referer2';
     $referer2->reference = $ref2;
     $this->dm->persist($referer2);
     $this->dm->flush();
     $this->dm->clear();
     $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
     $this->assertTrue($referer->reference instanceof RefType1TestObj);
     $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
     $this->assertTrue($referer->reference instanceof RefType2TestObj);
 }
Exemplo n.º 5
0
 public function testMenuNode()
 {
     $data = array('name' => 'test-node', 'label' => 'label_foobar', 'uri' => 'http://www.example.com/foo', 'route' => 'foo_route', 'linkType' => 'route', 'content' => $this->content, 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), 'attributes' => array('attr_foobar_1' => 'barfoo', 'attr_foobar_2' => 'barfoo'), 'childrenAttributes' => array('child_foobar_1' => 'barfoo', 'child_foobar_2' => 'barfoo'), 'linkAttributes' => array('link_foobar_1' => 'barfoo', 'link_foobar_2' => 'barfoo'), 'labelAttributes' => array('label_foobar_1' => 'barfoo', 'label_foobar_2' => 'barfoo'), 'extras' => array('extra_foobar_1' => 'barfoo', 'extra_foobar_2' => 'barfoo'), 'routeParameters' => array('route_param_foobar_1' => 'barfoo', 'route_param_foobar_2' => 'barfoo'), 'routeAbsolute' => true, 'display' => false, 'displayChildren' => false);
     $startDateString = $data['publishStartDate']->format('Y-m-d');
     $endDateString = $data['publishEndDate']->format('Y-m-d');
     $menuNode = new MenuNode();
     $refl = new \ReflectionClass($menuNode);
     $menuNode->setParentDocument($this->rootDocument);
     foreach ($data as $key => $value) {
         $refl = new \ReflectionClass($menuNode);
         $prop = $refl->getProperty($key);
         $prop->setAccessible(true);
         $prop->setValue($menuNode, $value);
     }
     $menuNode->addChild($this->child1);
     $this->dm->persist($menuNode);
     $this->dm->flush();
     $this->dm->clear();
     $menuNode = $this->dm->find(null, '/test/test-node');
     $this->assertNotNull($menuNode);
     foreach ($data as $key => $value) {
         $prop = $refl->getProperty($key);
         $prop->setAccessible(true);
         $v = $prop->getValue($menuNode);
         if (!is_object($value)) {
             $this->assertEquals($value, $v);
         }
     }
     // test objects
     $prop = $refl->getProperty('content');
     $prop->setAccessible(true);
     $content = $prop->getValue($menuNode);
     $this->assertEquals('fake_weak_content', $content->getName());
     // test children
     $this->assertCount(1, $menuNode->getChildren());
     // test publish start and end
     $publishStartDate = $menuNode->getPublishStartDate();
     $publishEndDate = $menuNode->getPublishEndDate();
     $this->assertInstanceOf('\\DateTime', $publishStartDate);
     $this->assertInstanceOf('\\DateTime', $publishEndDate);
     $this->assertEquals($startDateString, $publishStartDate->format('Y-m-d'));
     $this->assertEquals($endDateString, $publishEndDate->format('Y-m-d'));
     // test multi-lang
     $menuNode->setLocale('fr');
     $this->dm->persist($menuNode);
     $this->dm->flush();
     $this->dm->clear();
     $menuNode = $this->dm->findTranslation(null, '/test/test-node', 'fr');
     $this->assertEquals('fr', $menuNode->getLocale());
     $child = $this->dm->find(null, '/test/test-node/child1');
     $menuNode = $child->getParent();
     $this->assertCount(1, $menuNode->getChildren());
     $menuNode->removeChild($child);
     $this->dm->flush();
     $this->dm->clear();
     $menuNode = $this->dm->find(null, '/test/test-node');
     $this->assertCount(0, $menuNode->getChildren());
 }
Exemplo n.º 6
0
 public function testDetach()
 {
     $user = $this->dm->find($this->type, '/functional/lsmith');
     $user->username = "******";
     $this->dm->detach($user);
     $this->dm->flush();
     $this->dm->clear();
     $newUser = $this->dm->find($this->type, '/functional/lsmith');
     $this->assertEquals('lsmith', $newUser->username);
 }
Exemplo n.º 7
0
 public function testCreateFromFile()
 {
     $parent = new FixPHPCR1TestObj();
     $parent->id = '/functional/filetest';
     $this->dm->persist($parent);
     $parent->file = new File();
     $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
     $this->dm->flush();
     $this->dm->clear();
     $this->assertTrue($this->node->getNode('filetest')->hasNode('file'));
     $this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content'));
     $this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data'));
 }
Exemplo n.º 8
0
 public function testCreateCascade()
 {
     $folder = new Folder();
     $folder->setId('/functional/folder');
     $file = new File();
     $file->setFileContent(self::FILE_CONTENT);
     $file->setNodename('file');
     $folder->addChild($file);
     $this->dm->persist($folder);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertFolderAndFile($this->node);
 }
Exemplo n.º 9
0
 public function testCreatedDate()
 {
     $parent = new FileTestObj();
     $parent->file = new File();
     $parent->id = '/functional/filetest';
     $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
     $this->dm->persist($parent);
     $this->dm->flush();
     $this->dm->clear();
     $file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file');
     $this->assertNotNull($file);
     $this->assertNotNull($file->getCreated());
 }
Exemplo n.º 10
0
 public function testTriggerTranslationEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
     $page = new CmsPageTranslatable();
     $page->title = "my-page";
     $page->content = "long story";
     $this->dm->persist($page);
     $this->assertFalse($this->listener->preCreateTranslation);
     $this->assertFalse($this->listener->postLoadTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->dm->bindTranslation($page, 'en');
     $this->assertTrue($this->listener->preCreateTranslation);
     $this->assertFalse($this->listener->postLoadTranslation);
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->dm->flush();
     $this->dm->clear();
     $page = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsPageTranslatable', $page->id, 'en');
     $this->assertTrue($this->listener->postLoadTranslation);
     $page->title = 'neuer Titel';
     $this->dm->bindTranslation($page, 'de');
     $this->dm->flush();
     $this->dm->removeTranslation($page, 'en');
     $this->assertFalse($this->listener->postRemoveTranslation);
     $this->assertTrue($this->listener->preRemoveTranslation);
     $this->dm->flush();
     $this->assertTrue($this->listener->postRemoveTranslation);
 }
Exemplo n.º 11
0
 public function testComputeChangesetTranslatableFind()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::postUpdate), $this->listener);
     // Create initial user
     $user1 = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
     $user1->name = 'david';
     $user1->username = '******';
     $user1->status = 'activ';
     $this->dm->persist($user1);
     $this->dm->bindTranslation($user1, 'en');
     $user1->status = 'actif';
     $this->dm->bindTranslation($user1, 'fr');
     $this->dm->flush();
     $this->assertEquals(0, $this->listener->count);
     $this->dm->clear();
     $user1 = $this->dm->findTranslation(null, $user1->id, 'en');
     $this->dm->findTranslation(null, $user1->id, 'fr');
     $this->dm->flush();
     $this->assertEquals(0, $this->listener->count);
     $user1 = $this->dm->findTranslation(null, $user1->id, 'en');
     $user1->status = 'active';
     $this->dm->findTranslation(null, $user1->id, 'fr');
     $this->dm->flush();
     $this->assertEquals(1, $this->listener->count);
     $this->dm->clear();
     $user1 = $this->dm->findTranslation(null, $user1->id, 'en');
     $this->assertEquals('active', $user1->status);
 }
 protected function getTranslationNode($parentNode, $locale)
 {
     $subNode = $parentNode->addNode(Translation::LOCALE_NAMESPACE . ":{$locale}");
     $this->session->save();
     $this->dm->clear();
     return $subNode;
 }
Exemplo n.º 13
0
 public function testProxyImplicit()
 {
     $user = new CmsUser();
     $user->name = 'Dominik';
     $user->username = '******';
     $user->status = 'developer';
     $assistant = new CmsUser();
     $assistant->username = '******';
     $user->child = $assistant;
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find(null, $user->id);
     $assistant = $this->dm->find(null, $user->id . '/assistant');
     $this->assertSame($assistant, $user->child);
 }
Exemplo n.º 14
0
 public function testCascadeRemoveByCollection()
 {
     $referrerRefManyTestObj = new ReferrerRefTestObj2();
     $referrerRefManyTestObj->id = "/functional/referrerRefManyTestObj";
     $max = 5;
     for ($i = 0; $i < $max; $i++) {
         $newReferrerTestObj = new ReferrerTestObj2();
         $newReferrerTestObj->id = "/functional/referrerTestObj{$i}";
         $newReferrerTestObj->name = "referrerTestObj{$i}";
         $newReferrerTestObj->reference = $referrerRefManyTestObj;
         $this->dm->persist($newReferrerTestObj);
     }
     $this->dm->persist($referrerRefManyTestObj);
     $this->dm->flush();
     $this->dm->clear();
     $referenced = $this->dm->find(null, "/functional/referrerRefManyTestObj");
     $this->assertCount($max, $referenced->referrers);
     $referenced->referrers->remove(0);
     $referenced->referrers->remove(3);
     $this->assertCount($max - 2, $referenced->referrers);
     $this->dm->flush();
     $this->dm->clear();
     $referenced = $this->dm->find(null, "/functional/referrerRefManyTestObj");
     $this->assertCount($max - 2, $referenced->referrers);
 }
Exemplo n.º 15
0
 /**
  * TypeUser is a superclass of TypeTeamUser
  */
 public function testInheritance()
 {
     $user = new TypeTeamUser();
     $user->username = "******";
     $user->numbers = array(1, 2, 3);
     $user->id = '/functional/test';
     $user->name = 'inheritance';
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $userNew = $this->dm->find($this->type, '/functional/test');
     $this->assertNotNull($userNew, "Have to hydrate user object!");
     $this->assertEquals($user->username, $userNew->username);
     $this->assertEquals($user->numbers, $userNew->numbers);
     $this->assertEquals($user->name, $userNew->name);
 }
Exemplo n.º 16
0
 /**
  * Test Referrers ManyToMany cascade Flush
  */
 public function testCascadeManagedDocumentReferrerMtoMDuringFlush()
 {
     $article1 = new \Doctrine\Tests\Models\CMS\CmsArticle();
     $article1->text = "foo";
     $article1->topic = "bar";
     $article1->id = '/functional/article_m2m_referrer_1';
     $this->dm->persist($article1);
     $article2 = new \Doctrine\Tests\Models\CMS\CmsArticle();
     $article2->text = "foo2";
     $article2->topic = "bar2";
     $article2->id = '/functional/article_m2m_referrer_2';
     $this->dm->persist($article2);
     $superman = new \Doctrine\Tests\Models\CMS\CmsArticlePerson();
     $superman->name = "superman";
     $this->dm->persist($superman);
     $article1->addPerson($superman);
     $this->dm->flush();
     $this->dm->refresh($superman);
     $this->assertEquals($superman, $article1->getPersons()->first());
     // we want to attach article2 to superman
     // in the form of edition, we will submit article1 and article2 at the same time
     $superman->getArticlesReferrers()->add($article1);
     $superman->getArticlesReferrers()->add($article2);
     $this->dm->flush();
     $this->dm->refresh($superman);
     $this->assertEquals(1, $article1->getPersons()->count());
     $this->assertEquals(2, $superman->getArticlesReferrers()->count());
     $this->dm->clear();
 }
Exemplo n.º 17
0
 public function testFetchingMultipleHierarchicalObjectsWithChildIdFirst()
 {
     $parent = new ParentTestObj();
     $parent->nodename = 'parent';
     $parent->name = 'parent';
     $parent->parent = $this->dm->find(null, 'functional');
     $child = new ParentTestObj();
     $child->nodename = 'child';
     $child->name = 'child';
     $child->parent = $parent;
     $this->dm->persist($parent);
     $this->dm->persist($child);
     $parentId = $this->uow->getDocumentId($parent);
     $childId = $this->uow->getDocumentId($child);
     $this->dm->flush();
     $this->dm->clear();
     // this forces the objects to be loaded in an order where the $parent will become a proxy
     $documents = $this->dm->findMany('Doctrine\\Tests\\Models\\References\\ParentTestObj', array($childId, $parentId));
     $this->assertCount(2, $documents);
     /* @var $child ParentTestObj */
     /* @var $parent ParentTestObj */
     $child = $documents->first();
     $parent = $documents->last();
     $this->assertSame($child->parent, $parent);
     $this->assertSame('parent', $parent->nodename);
 }
Exemplo n.º 18
0
 public function testFindManyWithNonExistingUuuid()
 {
     $user = new TestUser();
     $user->username = '******';
     $user->id = '/functional/test';
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $actualUuid = $user->uuid;
     $unusedUuid = UUIDHelper::generateUUID();
     $this->assertNotNull($this->dm->find(get_class($user), $user->id));
     $this->assertNotNull($this->dm->find(get_class($user), $actualUuid));
     $this->assertNull($this->dm->find(get_class($user), $unusedUuid));
     $uuids = array($actualUuid, $unusedUuid);
     $documents = $this->dm->findMany(get_class($user), $uuids);
     $this->assertEquals(1, count($documents));
 }
 protected function getTestNode()
 {
     $this->removeTestNode();
     $node = $this->session->getRootNode()->addNode($this->testNodeName);
     $this->session->save();
     $this->dm->clear();
     return $node;
 }
Exemplo n.º 20
0
 public function testPropertyname()
 {
     $doc = new TestObj();
     $doc->id = '/functional/pn';
     $doc->name = 'Testname';
     $doc->othername = 'Testothername';
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertTrue($this->node->getNode('pn')->hasProperty('name'));
     $this->assertTrue($this->node->getNode('pn')->hasProperty('myname'));
     $doc = $this->dm->find($this->type, '/functional/pn');
     $this->assertNotNull($doc->name);
     $this->assertEquals('Testname', $doc->name);
     $this->assertNotNull($doc->othername);
     $this->assertEquals('Testothername', $doc->othername);
 }
Exemplo n.º 21
0
 /**
  * Remove a PHPCR node under the root node
  *
  * @param string $name The name of the node to remove
  *
  * @return void
  */
 protected function removeTestNode($name)
 {
     $root = $this->session->getNode('/');
     if ($root->hasNode($name)) {
         $root->getNode($name)->remove();
         $this->session->save();
         $this->dm->clear();
     }
 }
Exemplo n.º 22
0
 public function testRefreshProxy()
 {
     $parent = new ParentTestObj();
     $parent->id = '/functional/parent';
     $parent->name = 'parent';
     $child = new ParentTestObj();
     $child->id = '/functional/parent/child';
     $child->name = 'child';
     $this->dm->persist($parent);
     $this->dm->persist($child);
     $this->dm->flush();
     $this->dm->clear();
     $child = $this->dm->find(null, '/functional/parent/child');
     $this->assertInstanceOf('Doctrine\\Common\\Proxy\\Proxy', $child->parent);
     $child->parent->name = 'x';
     $this->dm->refresh($child->parent);
     $this->assertEquals('parent', $child->parent->name);
 }
Exemplo n.º 23
0
 public function testChildWithoutId()
 {
     $node = $this->resetFunctionalNode($this->dm);
     $parentId = $node->getPath() . '/parent';
     $parent = new ParentDoc();
     $parent->id = $parentId;
     $doc = new DocWithoutId();
     $doc->parent = $parent;
     $doc->nodename = 'foo';
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find(null, $parentId);
     $doc = $parent->children->current();
     $this->assertInstanceOf('Doctrine\\Common\\Proxy\\Proxy', $doc);
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\DocWithoutId', $doc);
     $this->assertEquals('foo', $doc->nodename);
     $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ParentDoc', $doc->parent);
 }
Exemplo n.º 24
0
 public function testPersistRepository()
 {
     $doc = new RepositoryIdStrategy();
     $doc->title = 'repository strategy';
     $this->dm->persist($doc);
     $this->dm->flush();
     $id = $this->dm->getUnitOfWork()->getDocumentId($doc);
     $this->dm->clear();
     $this->assertInstanceOf('\\Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Mapping\\RepositoryIdStrategy', $this->dm->find(null, $id));
 }
Exemplo n.º 25
0
 public function testPage()
 {
     $page = new Page(array('add_locale_pattern' => true));
     $page->setParentDocument($this->baseDocument);
     $page->setName('page-name');
     $page->setTitle('Page Title');
     $page->setLabel('Page Label');
     $page->setBody('This is body');
     $page->setPublishable(false);
     $page->setPublishStartDate(new \DateTime('2013-06-18'));
     $page->setPublishEndDate(new \DateTime('2013-06-18'));
     $page->setExtras(array('extra_1' => 'foobar', 'extra_2' => 'barfoo'));
     $this->dm->persist($page);
     $this->dm->flush();
     $this->dm->clear();
     $page = $this->dm->find(null, '/test/page-name');
     $this->assertNotNull($page);
     $this->assertTrue($page->getOption('add_locale_pattern'));
     $this->assertEquals('Page Title', $page->getTitle());
     $this->assertEquals('Page Label', $page->getLabel());
     $this->assertEquals('This is body', $page->getBody());
     $this->assertEquals(array('extra_1' => 'foobar', 'extra_2' => 'barfoo'), $page->getExtras());
     // test publish start and end
     $publishStartDate = $page->getPublishStartDate();
     $publishEndDate = $page->getPublishEndDate();
     $this->assertInstanceOf('\\DateTime', $publishStartDate);
     $this->assertInstanceOf('\\DateTime', $publishEndDate);
     $this->assertEquals('2013-06-18', $publishStartDate->format('Y-m-d'));
     $this->assertEquals('2013-06-18', $publishEndDate->format('Y-m-d'));
     // test multi-lang
     $page->setLocale('fr');
     $page->setTitle('french');
     $this->dm->persist($page);
     $this->dm->flush();
     $this->dm->clear();
     $page = $this->dm->findTranslation(null, '/test/page-name', 'fr');
     $this->assertEquals('fr', $page->getLocale());
     $this->assertEquals('french', $page->getTitle());
     // test node
     $node = $page->getNode();
     $this->assertInstanceOf('PHPCR\\NodeInterface', $node);
 }
Exemplo n.º 26
0
 public function testReorderUpdatesChildren()
 {
     $parent = $this->dm->find(null, '/functional/source');
     $children = $parent->getChildren();
     $this->assertSame($this->childrenNames, $this->getChildrenNames($children));
     $this->dm->reorder($parent, 'first', 'second', false);
     $this->dm->flush();
     $this->dm->clear();
     $parent = $this->dm->find(null, '/functional/source');
     $this->assertSame(array('second', 'first', 'third', 'fourth'), $this->getChildrenNames($parent->getChildren()));
 }
Exemplo n.º 27
0
 public function resetFunctionalNode(DocumentManager $dm)
 {
     $session = $dm->getPhpcrSession();
     $root = $session->getNode('/');
     if ($root->hasNode('functional')) {
         $root->getNode('functional')->remove();
         $session->save();
     }
     $node = $root->addNode('functional');
     $session->save();
     $dm->clear();
     return $node;
 }
Exemplo n.º 28
0
 public function testComputingBetweenEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::postLoad, Event::prePersist, Event::preUpdate, Event::postPersist, Event::postUpdate), $this->listener);
     $entity = new SomeEntity();
     $entity->id = '/functional/test';
     $entity->status = new \stdClass();
     $entity->status->value = 'active';
     $entity->status->foo = 'bar';
     $entity->text = 'test1';
     $this->dm->persist($entity);
     $this->dm->flush();
     $this->assertInstanceOf('stdClass', $entity->status);
     $this->assertAttributeNotEmpty('value', $entity->status);
     $this->assertEquals($entity->status->value, 'active');
     $this->assertObjectNotHasAttribute('foo', $entity->status);
     $entity->status->value = 'inactive';
     $entity->status->foo = 'bar2';
     $entity->text = 'test2';
     $this->dm->flush();
     $this->assertInstanceOf('stdClass', $entity->status);
     $this->assertAttributeNotEmpty('value', $entity->status);
     $this->assertEquals($entity->status->value, 'inactive');
     $this->assertObjectNotHasAttribute('foo', $entity->status);
     $this->assertEquals($entity->text, 'test2');
     $this->dm->clear();
     $entity = $this->dm->find(null, $entity->id);
     $this->assertInstanceOf('stdClass', $entity->status);
     $this->assertAttributeNotEmpty('value', $entity->status);
     $this->assertEquals($entity->status->value, 'inactive');
     $this->assertObjectNotHasAttribute('foo', $entity->status);
     $this->assertEquals($entity->text, 'test2');
     $entity->status->value = 'active';
     $this->dm->flush();
     $this->assertInstanceOf('stdClass', $entity->status);
     $this->assertAttributeNotEmpty('value', $entity->status);
     $this->assertEquals($entity->status->value, 'active');
     $this->assertEquals($entity->text, 'test2');
 }
Exemplo n.º 29
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);
 }
Exemplo n.º 30
0
 /**
  * @expectedException \PHPCR\NodeType\ConstraintViolationException
  */
 public function testChangingProtectedPropertyToNullThrowsException()
 {
     $test = new TestObject();
     $test->id = '/functional/protected';
     $test->changeMe = 'test';
     $this->dm->persist($test);
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->find(null, '/functional/protected');
     $test->changeMe = 'changed';
     $test->created = null;
     $this->dm->flush();
     $this->assertEquals('changed', $this->node->getNode('protected')->getProperty('change_me')->getString());
 }