/** * @param AreaModel $area * @depends testCreate */ public function testUpdatePostage(AreaModel $area) { $event = new AreaUpdatePostageEvent($area->getId()); $event->setPostage(20)->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface")); $areaAction = new Area(); $areaAction->updatePostage($event); $updatedArea = $event->getArea(); $this->assertInstanceOf('Thelia\\Model\\Area', $updatedArea); $this->assertEquals(20, $updatedArea->getPostage()); return $updatedArea; }
/** * @param AreaModel $area * @depends testCreate * @return AreaModel */ public function testUpdatePostage(AreaModel $area) { $event = new AreaUpdatePostageEvent($area->getId()); $event->setPostage(20); $areaAction = new Area(); $areaAction->updatePostage($event, null, $this->getMockEventDispatcher()); $updatedArea = $event->getArea(); $this->assertInstanceOf('Thelia\\Model\\Area', $updatedArea); $this->assertEquals(20, $updatedArea->getPostage()); return $updatedArea; }
public function updatePostageAction() { if (null !== ($response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))) { return $response; } $areaUpdateForm = $this->createForm(AdminForm::AREA_POSTAGE); $error_msg = null; try { $form = $this->validateForm($areaUpdateForm); $event = new AreaUpdatePostageEvent($form->get('area_id')->getData()); $event->setPostage($form->get('postage')->getData()); $this->dispatch(TheliaEvents::AREA_POSTAGE_UPDATE, $event); if (!$this->eventContainsObject($event)) { throw new \LogicException($this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName))); } // Log object modification if (null !== ($changedObject = $this->getObjectFromEvent($event))) { $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)), $this->getObjectId($changedObject)); } // Redirect to the success URL return $this->generateSuccessRedirect($areaUpdateForm); } catch (FormValidationException $ex) { // Form cannot be validated $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $error_msg = $ex->getMessage(); } $this->setupFormErrorContext($this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $areaUpdateForm); // At this point, the form has errors, and should be redisplayed. return $this->renderEditionTemplate(); }