Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
    public function createAction()
    {
        // bind form to page model
        $page = new Page();
        $this->form->bind($this->request, $page);

        if ($this->form->isValid()) {

            try {

                // path for page
                $parent = $this->form->get('parent')->getData();
                $path = $parent . '/' . $page->name;

                // save page
                $this->dm->persist($page, $path);
                $this->dm->flush();

                // redirect with message
                $this->request->getSession()->setFlash('notice', 'Page created!');
                return $this->redirect($this->generateUrl('admin'));

            } catch (HTTPErrorException $e) {

                $path = new PropertyPath('name');
                $this->form->addError(new DataError('Name already in use.'), $path->getIterator());

            }
        }

        return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form));
    }
 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);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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 persistGreetingAction()
 {
     $greeting = new Greeting();
     $greeting->setContent('Hello World!');
     $this->documentManager->persist($greeting);
     $this->documentManager->flush();
     return array('greeting' => $greeting);
 }
Ejemplo n.º 7
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());
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
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'));
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
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());
 }
Ejemplo n.º 12
0
 public function testModificationWithProtectedProperty()
 {
     $object = new ProtectedPropertyTestObj();
     $object->id = '/functional/pp';
     try {
         $this->dm->persist($object);
         $this->dm->flush();
         $object->changeme = 'changed';
         $this->dm->flush();
         $this->dm->clear();
     } catch (\PHPCR\NodeType\ConstraintViolationException $e) {
         $this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage()));
     }
     $this->assertTrue(true);
 }
 /**
  * Try to access the children of a specific version of a document and assert they
  * are hydrated properly
  */
 public function testUnversionedChildrenOnParentVersion()
 {
     $versionableArticle = new FullVersionableArticleWithChildren();
     $versionableArticle->author = 'mellowplace';
     $versionableArticle->topic = 'children test';
     $versionableArticle->id = '/functional/children-test';
     $versionableArticle->setText('Parent article text');
     $this->dm->persist($versionableArticle);
     $childArticle = new NonVersionableArticle();
     $childArticle->setText("This is the child");
     $childArticle->id = '/functional/children-test/child';
     $childArticle->author = 'mellowplace';
     $childArticle->topic = 'children test - child';
     $versionableArticle->addChildArticle($childArticle);
     // checkin the first version (1.0)
     $this->dm->flush();
     $this->dm->checkpoint($versionableArticle);
     // now modify the child nodes text and checkin the second version (1.1)
     $childArticle->setText('modified text');
     $this->dm->flush();
     $this->dm->checkpoint($versionableArticle);
     $firstVersion = $this->dm->findVersionByName('Doctrine\\Tests\\Models\\Versioning\\FullVersionableArticleWithChildren', $versionableArticle->id, '1.0');
     $secondVersion = $this->dm->findVersionByName('Doctrine\\Tests\\Models\\Versioning\\FullVersionableArticleWithChildren', $versionableArticle->id, '1.1');
     $this->assertEquals('This is the child', $firstVersion->childArticles->first()->getText(), 'The expected child article text is correct');
     $this->assertEquals('modified text', $secondVersion->childArticles->first()->getText(), 'The expected, modified, child article text is correct');
 }
 /**
  * Caution : Jackalope\Property guess the property type on the first element
  * So if it's an boolean, all your array will be set to true
  * The Array has to be an array of string
  */
 public function testTranslationArrayProperties()
 {
     // First save some translations
     $data = array();
     $data['topic'] = 'Some interesting subject';
     $data['text'] = 'Lorem ipsum...';
     $data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html');
     $node = $this->getTestNode();
     $node->setProperty('author', 'John Doe');
     $strategy = new AttributeTranslationStrategy($this->dm);
     $strategy->saveTranslation($data, $node, $this->metadata, 'en');
     // Save translation in another language
     $data['topic'] = 'Un sujet intéressant';
     $data['settings'] = array('is-active' => 'true', 'url' => 'super-article-en-francais.html');
     $strategy->saveTranslation($data, $node, $this->metadata, 'fr');
     $this->dm->flush();
     $doc = new Article();
     $doc->author = 'John Doe';
     $doc->topic = $data['topic'];
     $doc->setText($data['text']);
     $strategy->loadTranslation($doc, $node, $this->metadata, 'en');
     $this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
     $this->assertEquals(array('is-active' => 'true', 'url' => 'great-article-in-english.html'), $doc->getSettings());
     $strategy->loadTranslation($doc, $node, $this->metadata, 'fr');
     $this->assertEquals(array('is-active', 'url'), array_keys($doc->getSettings()));
     $this->assertEquals(array('is-active' => 'true', 'url' => 'super-article-en-francais.html'), $doc->getSettings());
 }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
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);
 }
Ejemplo n.º 17
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);
 }
Ejemplo n.º 18
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);
 }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
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);
 }
Ejemplo n.º 21
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);
 }
Ejemplo n.º 22
0
 /**
  * @expectedException \Doctrine\ODM\PHPCR\PHPCRException
  */
 public function testMoveByUpdateId()
 {
     $this->createChildren();
     $parent = $this->dm->find($this->type, '/functional/parent');
     $child = $parent->allChildren->first();
     $child->id = '/functional/elsewhere';
     $this->dm->flush();
 }
Ejemplo n.º 23
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));
 }
Ejemplo n.º 24
0
 public function testReorderParentProxy()
 {
     $first = $this->dm->find(null, '/functional/source/first');
     $parent = $first->getParentDocument();
     $this->dm->reorder($parent, 'first', 'second', false);
     $this->dm->flush();
     $this->assertSame(array('second', 'first', 'third', 'fourth'), $this->getChildrenNames($parent->getChildren()));
 }
Ejemplo n.º 25
0
 /**
  * Create a node with a bad name and allow it to be discovered
  * among its parent node's children while also explicitly
  * persisting it.
  *
  * @expectedException \Doctrine\ODM\PHPCR\Id\IdException
  */
 public function testIllegalNameManagedChild()
 {
     $parent = $this->dm->find($this->type, '/functional/thename');
     $child = new NameDoc();
     $child->nodename = 'bad/name';
     $child->parent = $parent;
     $parent->children->add($child);
     $this->dm->persist($child);
     $this->dm->flush();
 }
Ejemplo n.º 26
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);
 }
Ejemplo n.º 27
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));
 }
Ejemplo n.º 28
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);
 }
Ejemplo n.º 29
0
 public function testAdditionalFindCallsDoNotRefresh()
 {
     $a = new Article();
     $a->id = '/functional/' . $this->testNodeName;
     $a->topic = 'Hello';
     $a->text = 'Some text';
     $this->dm->persist($a);
     $this->dm->flush();
     $a->topic = 'Guten tag';
     $trans = $this->dm->findTranslation(null, '/functional/' . $this->testNodeName, 'en');
     $this->assertEquals('Guten tag', $trans->topic);
 }
Ejemplo n.º 30
0
 /**
  * Write a string to a file
  *
  * @param  string $path    file path
  * @param  string $content new file content
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function _filePutContents($path, $content)
 {
     /** @var File $doc */
     $doc = $this->dm->find(null, $path);
     if (!$doc instanceof File) {
         return false;
     }
     $doc->setContentFromString($content);
     $this->dm->persist($doc);
     $this->dm->flush();
     return true;
 }