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);
 }
 /**
  * @return a Navigation instance with the specified information
  */
 protected function createMenuNode(DocumentManager $dm, $parent, $name, $label, $content, $uri = null, $route = null)
 {
     if (!$parent instanceof MenuNode && !$parent instanceof Menu) {
         $menuNode = new Menu();
     } else {
         $menuNode = new MenuNode();
     }
     $menuNode->setParent($parent);
     $menuNode->setName($name);
     $dm->persist($menuNode);
     // do persist before binding translation
     if (null !== $content) {
         $menuNode->setContent($content);
     } else {
         if (null !== $uri) {
             $menuNode->setUri($uri);
         } else {
             if (null !== $route) {
                 $menuNode->setRoute($route);
             }
         }
     }
     if (is_array($label)) {
         foreach ($label as $locale => $l) {
             $menuNode->setLabel($l);
             $dm->bindTranslation($menuNode, $locale);
         }
     } else {
         $menuNode->setLabel($label);
     }
     return $menuNode;
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
 }
 public function testSecondLevelOverwrite()
 {
     $localePrefs = array('en' => array('en', 'de'), 'de' => array('de', 'en'));
     $this->dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en'));
     $secondTrans = new SecondLevelWithDuplicateOverwrite();
     $secondTrans->id = '/functional/secondTrans';
     $secondTrans->text = 'deutsch';
     $this->dm->persist($secondTrans);
     $this->dm->bindTranslation($secondTrans, 'de');
     $secondTrans->text = 'english';
     $this->dm->bindTranslation($secondTrans, 'en');
     $this->dm->flush();
     $tmpDocDe = $this->dm->findTranslation(null, '/functional/secondTrans', 'de');
     $this->assertEquals($tmpDocDe->text, 'deutsch');
     $tmpDocEn = $this->dm->findTranslation(null, '/functional/secondTrans', 'en');
     $this->assertEquals($tmpDocEn->text, 'english');
 }
Exemplo n.º 6
0
 public function testAssocWithNulls()
 {
     $assoc = array('foo' => 'bar', 'test' => null, 2 => 'huhu');
     $a = new Article();
     $a->id = '/functional/' . $this->testNodeName;
     $a->topic = 'Hello';
     $a->text = 'This is an article in English';
     $a->assoc = $assoc;
     $this->dm->persist($a);
     $this->dm->bindTranslation($a, 'de');
     $this->dm->flush();
     $this->dm->clear();
     $a = $this->dm->find(null, '/functional/' . $this->testNodeName);
     $this->assertEquals($assoc, $a->assoc);
 }
 public function testRefreshProxyUsesFallback()
 {
     $parent = new ParentObj();
     $parent->id = '/functional/thename/child';
     $this->dm->persist($parent);
     $child = new ChildObj();
     $child->parent = $parent;
     $child->name = 'c1';
     $child->text = 'french';
     $this->dm->persist($child);
     $this->dm->bindTranslation($child, 'fr');
     $this->dm->flush();
     $this->dm->clear();
     $doc = $this->dm->findTranslation(null, '/functional/thename/child', 'fr');
     $this->assertEquals('french', $doc->children['c1']->text);
     $this->dm->clear();
     $doc = $this->dm->find(null, '/functional/thename');
     $this->assertEquals('french', $doc->child->children['c1']->text);
 }
Exemplo n.º 8
0
 public function testComputeChangeSetForTranslatableDocument()
 {
     $root = $this->dm->find(null, 'functional');
     $c1 = new Comment();
     $c1->name = 'c1';
     $c1->parent = $root;
     $c1->setText('deutsch');
     $this->dm->persist($c1);
     $this->dm->bindTranslation($c1, 'de');
     $c1->setText('english');
     $this->dm->bindTranslation($c1, 'en');
     $this->dm->flush();
     $c2 = new Comment();
     $c2->name = 'c2';
     $c2->parent = $root;
     $c2->setText('deutsch');
     $this->dm->persist($c2);
     $this->dm->bindTranslation($c2, 'de');
     $c2->setText('english');
     $this->dm->bindTranslation($c2, 'en');
     $this->uow->computeChangeSets();
     $this->assertCount(1, $this->uow->getScheduledInserts());
     $this->assertCount(0, $this->uow->getScheduledUpdates());
 }
Exemplo n.º 9
0
 public function migrate($path = '/', $depth = -1)
 {
     if (0 !== strpos($path, $this->basepath)) {
         throw new \RuntimeException("The provided identifier '{$path}' does not start with the base path '{$this->basepath}'");
     }
     $yaml = new Parser();
     $contentPath = substr($path, strlen($this->basepath));
     $data = $yaml->parse(file_get_contents($this->dataDir . $contentPath . '.yml'));
     NodeHelper::createPath($this->session, preg_replace('#/[^/]*$#', '', $this->basepath));
     $class = isset($data['class']) ? $data['class'] : 'Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Doctrine\\Phpcr\\Page';
     $page = $this->dm->find($class, $path);
     if (!$page) {
         $page = $this->createPageInstance($class);
         $page->setId($path);
     }
     if (isset($data['formats'])) {
         $page->setDefault('_format', reset($data['formats']));
         $page->setRequirement('_format', implode('|', $data['formats']));
     }
     if (!empty($data['template'])) {
         $page->setDefault(RouteObjectInterface::TEMPLATE_NAME, $data['template']);
     }
     if (!empty($data['controller'])) {
         $page->setDefault(RouteObjectInterface::CONTROLLER_NAME, $data['controller']);
     }
     if (!empty($data['options'])) {
         $page->setOptions($data['options']);
     }
     $this->dm->persist($page);
     if (is_array($data['title'])) {
         $page->setAddLocalePattern(true);
         foreach ($data['title'] as $locale => $title) {
             $page->setTitle($title);
             if (isset($data['label'][$locale]) && $data['label'][$locale]) {
                 $page->setLabel($data['label'][$locale]);
             } elseif (!isset($data['label'][$locale])) {
                 $page->setLabel($title);
             }
             $page->setBody($data['body'][$locale]);
             $this->dm->bindTranslation($page, $locale);
         }
     } else {
         $page->setTitle($data['title']);
         if (isset($data['label'])) {
             if ($data['label']) {
                 $page->setLabel($data['label']);
             }
         } elseif (!isset($data['label'])) {
             $page->setLabel($data['title']);
         }
         $page->setBody($data['body']);
     }
     if (isset($data['publish_start_date'])) {
         $page->setPublishStartDate(date_create_from_format('U', strtotime($data['publish_start_date'])));
     }
     if (isset($data['publish_end_date'])) {
         $page->setPublishEndDate(date_create_from_format('U', strtotime($data['publish_end_date'])));
     }
     $this->dm->flush();
     return 0;
 }