/** * Test related method */ public function testToString() { $this->assertEquals('', $this->currency->__toString()); $expectedCode = 'test-code'; $this->currency->setCode($expectedCode); $this->assertEquals($expectedCode, $this->currency->__toString()); }
/** * Create currency entity and persist it * @param string $code Currency code * @param boolean $activated Define if currency is activated or not * * @return \Pim\Bundle\CatalogBundle\Entity\Currency */ protected function createCurrency($code, $activated = false) { $currency = new Currency(); $currency->setCode($code); $currency->setActivated($activated); return $currency; }
function let(CurrencyRepository $repository, Currency $eur, Currency $usd, Currency $gbp) { $this->beConstructedWith($repository); $repository->findBy(array('activated' => true))->willReturn([$eur, $usd]); $repository->findBy(array())->willReturn([$eur, $usd, $gbp]); $eur->getCode()->willReturn('EUR'); $usd->getCode()->willReturn('USD'); $gbp->getCode()->willReturn('GBP'); }
/** * Activate/Deactivate a currency * * @param Currency $currency * * @AclAncestor("pim_enrich_currency_toggle") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function toggleAction(Currency $currency) { try { $currency->toggleActivation(); $this->getManagerForClass('PimCatalogBundle:Currency')->flush(); $this->addFlash('success', 'flash.currency.updated'); } catch (\Exception $e) { $this->addFlash('error', 'flash.error ocurred'); } return $this->redirect($this->generateUrl('pim_enrich_currency_index')); }
/** * Activate/Deactivate a currency * * @param Currency $currency * * @AclAncestor("pim_enrich_currency_toggle") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function toggleAction(Currency $currency) { try { $currency->toggleActivation(); $this->currencySaver->save($currency); $this->addFlash('success', 'flash.currency.updated'); } catch (\Exception $e) { $this->addFlash('error', 'flash.error ocurred'); } return $this->redirect($this->generateUrl('pim_enrich_currency_index')); }
function it_fails_if_the_currency_is_not_valid($context, $channelManager, AbstractProductProcessor $value, HasValidCurrency $constraint, Channel $channel, Currency $currency) { $value->getChannel()->willReturn('channel'); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getCurrencies()->willReturn([$currency]); $currency->getCode()->willReturn('dollar'); $value->getCurrency()->willReturn('euro'); $constraint->message = 'The given currency is not valid (check that the selected currency is in channel\'s currencies)'; $context->addViolationAt('currency', 'The given currency is not valid (check that the selected currency is in channel\'s currencies)', ['currency'])->shouldBeCalled(); $this->validate($value, $constraint); }
/** * Activate/Deactivate a currency * * @param Currency $currency * * @AclAncestor("pim_enrich_currency_toggle") * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function toggleAction(Currency $currency) { try { $currency->toggleActivation(); $this->currencySaver->save($currency); $this->request->getSession()->getFlashBag()->add('success', new Message('flash.currency.updated')); } catch (LinkedChannelException $e) { $this->request->getSession()->getFlashBag()->add('error', new Message('flash.currency.error.linked_to_channel')); } catch (\Exception $e) { $this->request->getSession()->getFlashBag()->add('error', new Message('flash.error ocurred')); } return new RedirectResponse($this->router->generate('pim_enrich_currency_index')); }
function it_generates_prices_indexes_when_saving_enabled_currency($collection, $namingUtility, Currency $eur, AbstractAttribute $price) { $eur->getCode()->willReturn('EUR'); $eur->isActivated()->willReturn(true); $price->getCode()->willReturn('price'); $price->getBackendType()->willReturn('prices'); $price->isLocalizable()->willReturn(false); $price->isScopable()->willReturn(false); $price->isUseableAsGridFilter()->willReturn(true); $price->getAttributeType()->willReturn('pim_catalog_price_collection'); $namingUtility->getPricesAttributes()->willReturn([$price]); $namingUtility->getCurrencyCodes()->willReturn(['EUR', 'USD']); $namingUtility->appendSuffixes(['normalizedData.price', 'normalizedData.price'], ['EUR', 'USD'], '.')->willReturn(['normalizedData.price.EUR', 'normalizedData.price.USD']); $namingUtility->appendSuffixes(['normalizedData.price', 'normalizedData.price'], ['data'], '.')->willReturn(['normalizedData.price.EUR.data', 'normalizedData.price.USD.data']); $namingUtility->getAttributeNormFields($price)->willReturn(['normalizedData.price', 'normalizedData.price']); $options = ['background' => true, 'w' => 0]; $collection->ensureIndex(['normalizedData.price.EUR.data' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.price.USD.data' => 1], $options)->shouldBeCalled(); $this->ensureIndexesFromCurrency($eur); }
function getChannel() { $channel = new Channel(); $channel->setCode('catalog'); $currency = new Currency(); $currency->setCode('EUR'); $channel->addCurrency($currency); return $channel; }
/** * Create a currency for testing * * @param string $code * * @return \Pim\Bundle\CatalogBundle\Entity\Currency */ protected function createCurrency($code) { $currency = new Currency(); $currency->setCode($code); return $currency; }
function it_removes_obsolete_price_indexes_when_currency_is_disabled($collection, Currency $usd) { $usd->getCode()->willReturn('USD'); $usd->isActivated()->willReturn(false); $collection->getIndexInfo()->willReturn([["key" => ["_id" => 1]], ["key" => ["normalizedData.title-ecommerce-en_US" => 1]], ["key" => ["normalizedData.title-ecommerce-de_DE" => 1]], ["key" => ["normalizedData.title-mobile-de_DE" => 1]], ["key" => ["normalizedData.manufacturer_title" => 1]], ["key" => ["normalizedData.title_left-en_US" => 1]], ["key" => ["normalizedData.title_left-de_DE" => 1]], ["key" => ["normalizedData.price-ecommerce.EUR.data" => 1]], ["key" => ["normalizedData.price-mobile.USD.data" => 1]], ["key" => ["normalizedData.name-mobile" => 1]], ["key" => ["normalizedData.name-ecommerce" => 1]], ["key" => ["normalizedData.mobile_support.id" => 1]], ["key" => ["normalizedData.cost-en_US.USD.data" => 1]], ["key" => ["normalizedData.color-ecommerce-en_US.id" => 1]]]); $collection->deleteIndex('normalizedData.price-mobile.USD.data')->shouldBeCalled(); $collection->deleteIndex('normalizedData.cost-en_US.USD.data')->shouldBeCalled(); $this->purgeIndexesFromCurrency($usd); }
function it_returns_empty_array_when_active_code_choices_not_found(CurrencyRepository $currencyRepository, Currency $currency) { $currencyRepository->findBy(['activated' => true])->willReturn([]); $currency->getCode()->willReturn([]); $this->getActiveCodeChoices()->shouldReturn([]); }
/** * Remove indexes associated with the provided currency * * @param Currency $currency */ public function purgeIndexesFromCurrency(Currency $currency) { $currencyPattern = sprintf('/%s\\..+\\.%s\\.data/', ProductQueryUtility::NORMALIZED_FIELD, $currency->getCode()); $indexesToRemove = $this->getIndexesMatching($currencyPattern); $this->removeIndexes($indexesToRemove); }
/** * {@inheritDoc} */ public function getReference() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array()); return parent::getReference(); }
function it_removes_indexes_for_currency_when_disabling_it($indexPurger, Currency $usd, LifecycleEventArgs $args) { $usd->isActivated()->willReturn(false); $args->getEntity()->willReturn($usd); $indexPurger->purgeIndexesFromCurrency($usd)->shouldBeCalled(); $this->postUpdate($args); }