public function testUpdateBrand() { $brand = $this->getRandomBrand(); $event = new BrandUpdateEvent($brand->getId()); $event->setVisible(1)->setLocale('en_US')->setTitle('test update brand title')->setChapo('test update brand short description')->setDescription('test update brand description')->setPostscriptum('test update brand postscriptum'); $brandAction = new Brand(); $brandAction->update($event, null, $this->getMockEventDispatcher()); $updatedBrand = $event->getBrand(); $this->assertInstanceOf('Thelia\\Model\\Brand', $updatedBrand); $this->assertEquals(1, $updatedBrand->getVisible()); $this->assertEquals('test update brand title', $updatedBrand->getTitle()); $this->assertEquals('test update brand short description', $updatedBrand->getChapo()); $this->assertEquals('test update brand description', $updatedBrand->getDescription()); $this->assertEquals('test update brand postscriptum', $updatedBrand->getPostscriptum()); }
/** * Creates the update event with the provided form data * * @param array $formData * @return BrandUpdateEvent */ protected function getUpdateEvent($formData) { $brandUpdateEvent = new BrandUpdateEvent($formData['id']); $brandUpdateEvent->setLogoImageId($formData['logo_image_id'])->setVisible($formData['visible'])->setLocale($formData['locale'])->setTitle($formData['title'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum']); return $brandUpdateEvent; }
/** * process update brand * * @param BrandUpdateEvent $event * @param $eventName * @param EventDispatcherInterface $dispatcher */ public function update(BrandUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher) { if (null !== ($brand = BrandQuery::create()->findPk($event->getBrandId()))) { $brand->setDispatcher($dispatcher); $brand->setVisible($event->getVisible())->setLogoImageId(intval($event->getLogoImageId()) == 0 ? null : $event->getLogoImageId())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save(); $event->setBrand($brand); } }