Ejemplo n.º 1
0
 public function testRemoveTranslation()
 {
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->dm->flush();
     $this->assertEquals(array('en'), $this->dm->getLocalesFor($this->doc));
     $this->doc->topic = 'Un sujet intéressant';
     $this->dm->bindTranslation($this->doc, 'fr');
     $this->dm->flush();
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation(null, $this->doc->id, 'fr');
     $this->assertEquals(array('en', 'fr'), $this->dm->getLocalesFor($this->doc));
     $this->dm->removeTranslation($this->doc, 'en');
     $this->assertEquals(array('fr'), $this->dm->getLocalesFor($this->doc));
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation(null, $this->doc->id, 'fr');
     $this->assertEquals(array('en', 'fr'), $this->dm->getLocalesFor($this->doc));
     $this->dm->removeTranslation($this->doc, 'en');
     $this->dm->flush();
     $this->assertEquals(array('fr'), $this->dm->getLocalesFor($this->doc));
     $this->dm->clear();
     $this->doc = $this->dm->find(null, $this->doc->id);
     $this->assertEquals(array('fr'), $this->dm->getLocalesFor($this->doc));
     try {
         $this->dm->removeTranslation($this->doc, 'fr');
         $this->fail('Last translation should not be removable');
     } catch (PHPCRException $e) {
     }
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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 testFindTranslationPropagateLocale()
 {
     $child = new Article();
     $child->id = '/functional/thename/child';
     $child->author = 'John Doe';
     $child->text = 'Lorem ipsum...';
     $child->topic = 'Interesting Topic';
     $this->dm->persist($child);
     $this->dm->bindTranslation($child, 'en');
     $child->topic = 'Sujet interessant';
     $this->dm->bindTranslation($child, 'fr');
     $related = new Article();
     $related->id = '/functional/thename/related';
     $related->author = 'John Doe';
     $related->text = 'Lorem ipsum...';
     $related->topic = 'Interesting Topic';
     $this->dm->persist($related);
     $this->dm->bindTranslation($related, 'en');
     $related->topic = 'Sujet interessant';
     $this->dm->bindTranslation($related, 'fr');
     $child->relatedArticles[] = $related;
     $this->dm->flush();
     $this->dm->clear();
     // we find document "thename" with a specific locale. the child proxy
     // object must be the same locale
     $doc = $this->dm->findTranslation($this->type, '/functional/thename', 'fr');
     $this->assertInstanceOf('Doctrine\\Common\\Proxy\\Proxy', $doc->child);
     $this->assertEquals('fr', $doc->locale);
     $this->assertEquals('fr', $doc->child->locale);
     $this->assertEquals('fr', $doc->child->relatedArticles[0]->locale);
     $this->assertEquals('Sujet interessant', $doc->child->topic);
     $this->dm->clear();
     $doc = $this->dm->findTranslation($this->type, '/functional/thename', 'en');
     $this->assertInstanceOf('Doctrine\\Common\\Proxy\\Proxy', $doc->child);
     $this->assertEquals('en', $doc->locale);
     $this->assertEquals('en', $doc->child->locale);
     $this->assertEquals('Interesting Topic', $doc->child->topic);
     $this->dm->removeTranslation($doc->child->relatedArticles[0], 'en');
     $this->dm->removeTranslation($doc, 'en');
     $this->dm->flush();
     $this->dm->clear();
     // if we remove the english translation from the doc and the related, loading the child
     // should give the doc and the related in french
     $child = $this->dm->findTranslation($this->type, '/functional/thename/child', 'en');
     $this->assertInstanceOf('Doctrine\\Common\\Proxy\\Proxy', $child->parent);
     $this->assertEquals('en', $child->locale);
     $this->assertEquals('fr', $child->parent->locale);
     $this->assertEquals('french', $child->parent->topic);
     $this->assertEquals('fr', $child->relatedArticles[0]->locale);
 }