/** * Delete a currencyuration entry * * @param \Thelia\Core\Event\Currency\CurrencyDeleteEvent $event */ public function delete(CurrencyDeleteEvent $event) { if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) { $currency->setDispatcher($event->getDispatcher())->delete(); $event->setCurrency($currency); } }
/** * @expectedException \RuntimeException * @expectedExceptionMessage It is not allowed to delete the default currency */ public function testDeleteDefault() { CurrencyQuery::create()->addAscendingOrderByColumn('RAND()')->limit(1)->update(array('ByDefault' => true)); $currency = CurrencyQuery::create()->findOneByByDefault(1); $event = new CurrencyDeleteEvent($currency->getId()); $event->setDispatcher($this->dispatcher); $action = new Currency($this->getCurrencyConverter()); $action->delete($event); }
/** * Delete a currencyuration entry * * @param \Thelia\Core\Event\Currency\CurrencyDeleteEvent $event */ public function delete(CurrencyDeleteEvent $event) { if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) { if ($currency->getByDefault()) { throw new \RuntimeException(Translator::getInstance()->trans('It is not allowed to delete the default currency')); } $currency->setDispatcher($event->getDispatcher())->delete(); $event->setCurrency($currency); } }
/** * @param CurrencyModel $currency * @depends testSetDefault */ public function testDelete(CurrencyModel $currency) { $event = new CurrencyDeleteEvent($currency->getId()); $event->setDispatcher($this->dispatcher); $action = new Currency(); $action->delete($event); $deletedCurrency = $event->getCurrency(); $this->assertInstanceOf('Thelia\\Model\\Currency', $deletedCurrency); $this->assertTrue($deletedCurrency->isDeleted()); }