public function setUp() { $this->listener = new TestResetListener(); $this->dm = $this->createDocumentManager(); $this->node = $this->resetFunctionalNode($this->dm); $this->dm->getEventManager()->addEventListener(array('prePersist', 'postPersist', 'preUpdate', 'postUpdate'), $this->listener); }
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); }
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); }
/** * Creates a new factory instance that uses the given DocumentManager instance. * * @param DocumentManager $dm The DocumentManager instance */ public function __construct(DocumentManager $dm) { $this->dm = $dm; $conf = $this->dm->getConfiguration(); $this->setCacheDriver($conf->getMetadataCacheImpl()); $this->driver = $conf->getMetadataDriverImpl(); $this->evm = $this->dm->getEventManager(); }
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 testLoadClassMetadataEvent() { $listener = new Listener(); $evm = $this->dm->getEventManager(); $evm->addEventListener(array(Event::loadClassMetadata), $listener); $meta = $this->getMetadataFor('Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\DefaultMappingObject'); $this->assertTrue($listener->called); $this->assertSame($this->dm, $listener->dm); $this->assertSame($meta, $listener->meta); }
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'); }
/** * Reorder the children but reset the order in the preUpdate event * Tests that the previously compute document change set gets overwritten * * @depends testReorderChildren */ public function testResetReorderChildren() { $this->createChildren(); $this->listener = new TestResetReorderingListener(); $this->dm->getEventManager()->addEventListener(array('preUpdate'), $this->listener); /** @var $parent ChildrenTestObj */ $parent = $this->dm->find($this->type, '/functional/parent'); $this->assertEquals("Child A", $parent->allChildren->first()->name); $parent->allChildren->remove('Child A'); $newChild = new ChildrenTestObj(); $newChild->name = 'Child A'; $parent->allChildren->add($newChild); $this->dm->flush(); $this->dm->clear(); $parent = $this->dm->find($this->type, '/functional/parent'); $this->assertEquals("Child A", $parent->allChildren->first()->name); $this->dm->getEventManager()->removeEventListener(array('preUpdate'), $this->listener); }
/** * @param DocumentManager $dm */ public function __construct(DocumentManager $dm) { $this->dm = $dm; $this->session = $dm->getPhpcrSession(); $this->eventListenersInvoker = new ListenersInvoker($dm); $this->eventManager = $dm->getEventManager(); $config = $dm->getConfiguration(); $this->documentClassMapper = $config->getDocumentClassMapper(); $this->validateDocumentName = $config->getValidateDoctrineMetadata(); $this->writeMetadata = $config->getWriteDoctrineMetadata(); $this->uuidGenerator = $config->getUuidGenerator(); if ($this->session instanceof JackalopeSession) { $this->useFetchDepth = 'jackalope.fetch_depth'; } }
/** * @param DocumentManager $dm */ public function __construct(DocumentManager $dm) { $this->dm = $dm; $this->session = $dm->getPhpcrSession(); $this->evm = $dm->getEventManager(); $config = $dm->getConfiguration(); $this->documentClassMapper = $config->getDocumentClassMapper(); $this->validateDocumentName = $config->getValidateDoctrineMetadata(); $this->writeMetadata = $config->getWriteDoctrineMetadata(); }
/** * Initializes a new ListenersInvoker instance. * * @param DocumentManager $dm */ public function __construct(DocumentManager $dm) { $this->eventManager = $dm->getEventManager(); $this->dm = $dm; }