function it_generates_localizable_indexes_when_saving_enabled_locale($collection, $namingUtility, AttributeInterface $description, LocaleInterface $en_US, LocaleInterface $de_DE, ChannelInterface $ecommerce) { $description->getCode()->willReturn('description'); $description->getBackendType()->willReturn('varchar'); $description->isLocalizable()->willReturn(true); $description->isScopable()->willReturn(false); $description->isUseableAsGridFilter()->willReturn(true); $description->getAttributeType()->willReturn('pim_catalog_text'); $en_US->getCode()->willReturn('en_US'); $en_US->isActivated()->willReturn(true); $de_DE->getCode()->willReturn('de_DE'); $de_DE->isActivated()->willReturn(true); $ecommerce->getCode()->willReturn('ecommerce'); $ecommerce->getLocales()->willReturn([$en_US, $de_DE]); $namingUtility->getChannels()->willReturn([$ecommerce]); $namingUtility->getLocalizableAttributes()->willReturn([$description]); $namingUtility->getAttributeNormFields($description)->willReturn(['normalizedData.description-en_US', 'normalizedData.description-de_DE']); $indexes = array_fill(0, 10, 'fake_index'); $collection->getIndexInfo()->willReturn($indexes); $options = ['background' => true, 'w' => 0]; $collection->ensureIndex(['normalizedData.completenesses.ecommerce-en_US' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.completenesses.ecommerce-de_DE' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.description-en_US' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.description-de_DE' => 1], $options)->shouldBeCalled(); $this->ensureIndexesFromLocale($en_US); }
function let(SecurityContextInterface $securityContext, LocaleManager $localeManager, ChannelManager $channelManager, CategoryManager $categoryManager, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree) { $securityContext->getToken()->willReturn($token); $token->getUser()->willReturn($user); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $de->getCode()->willReturn('de_DE'); $en->isActivated()->willReturn(true); $fr->isActivated()->willReturn(true); $de->isActivated()->willReturn(true); $localeManager->getLocaleByCode('en_US')->willReturn($en); $localeManager->getLocaleByCode('fr_FR')->willReturn($fr); $localeManager->getLocaleByCode('de_DE')->willReturn($de); $localeManager->getActiveLocales()->willReturn([$en, $fr, $de]); $channelManager->getChannels()->willReturn([$mobile, $ecommerce]); $categoryManager->getTrees()->willReturn([$firstTree, $secondTree]); $this->beConstructedWith($securityContext, $localeManager, $channelManager, $categoryManager, 'en_US'); }
function let(TokenStorageInterface $tokenStorage, LocaleRepositoryInterface $localeRepository, ChannelRepositoryInterface $channelRepository, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree, CategoryRepositoryInterface $productCategoryRepo, RequestStack $requestStack, ChoicesBuilderInterface $choicesBuilder) { $tokenStorage->getToken()->willReturn($token); $token->getUser()->willReturn($user); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $de->getCode()->willReturn('de_DE'); $en->isActivated()->willReturn(true); $fr->isActivated()->willReturn(true); $de->isActivated()->willReturn(true); $localeRepository->findOneByIdentifier('en_US')->willReturn($en); $localeRepository->findOneByIdentifier('fr_FR')->willReturn($fr); $localeRepository->findOneByIdentifier('de_DE')->willReturn($de); $localeRepository->getActivatedLocales()->willReturn([$en, $fr, $de]); $channelRepository->findOneBy([])->willReturn($mobile); $productCategoryRepo->getTrees()->willReturn([$firstTree, $secondTree]); $this->beConstructedWith($tokenStorage, $localeRepository, $channelRepository, $productCategoryRepo, $requestStack, $choicesBuilder, 'en_US'); }
function it_throws_an_exception_when_values_data_contains_an_inactive_locale($objectFilter, $attributeRepository, $localeRepository, AttributeInterface $nameAttribute, AttributeInterface $descriptionAttribute, LocaleInterface $enLocale, LocaleInterface $inactiveLocale, ProductInterface $product) { $attributeRepository->findOneByIdentifier('name')->willReturn($nameAttribute); $objectFilter->filterObject($nameAttribute, 'pim.internal_api.attribute.edit')->willReturn(false); $attributeRepository->findOneByIdentifier('description')->willReturn($descriptionAttribute); $objectFilter->filterObject($descriptionAttribute, 'pim.internal_api.attribute.edit')->willReturn(false); $enLocale->isActivated()->willReturn(true); $localeRepository->findOneByIdentifier('en_US')->willReturn($enLocale); $objectFilter->filterObject($enLocale, 'pim.internal_api.locale.edit')->willReturn(true); $inactiveLocale->isActivated()->willReturn(false); $localeRepository->findOneByIdentifier('inactive')->willReturn($inactiveLocale); $data = ['values' => ['name' => [['locale' => 'en_US', 'scope' => 'mobile', 'value' => 'My awesome product']], 'description' => [['locale' => 'inactive', 'scope' => 'mobile', 'value' => '']]]]; $this->shouldThrow('\\Pim\\Bundle\\CatalogBundle\\Exception\\ObjectNotFoundException')->during('filterCollection', [$data, null, ['product' => $product]]); }
function it_removes_obsolete_localizable_indexes_when_locale_is_disabled($collection, LocaleInterface $en_US) { $en_US->getCode()->willReturn('en_US'); $en_US->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]], ["key" => ["normalizedData.completenesses-ecommerce-en_US" => 1]], ["key" => ["normalizedData.completenesses-ecommerce-de_DE" => 1]]]); $collection->deleteIndex('normalizedData.title-ecommerce-en_US')->shouldBeCalled(); $collection->deleteIndex('normalizedData.title_left-en_US')->shouldBeCalled(); $collection->deleteIndex('normalizedData.cost-en_US.USD.data')->shouldBeCalled(); $collection->deleteIndex('normalizedData.color-ecommerce-en_US.id')->shouldBeCalled(); $collection->deleteIndex('normalizedData.completenesses-ecommerce-en_US')->shouldBeCalled(); $this->purgeIndexesFromLocale($en_US); }
/** * Checks if a locale is activated * * @param LocaleInterface $locale * * @return boolean */ protected function isLocaleAvailable(LocaleInterface $locale) { return $locale->isActivated(); }
function it_removes_indexes_for_locale_when_disabling_it($indexPurger, LocaleInterface $en_US, LifecycleEventArgs $args) { $en_US->isActivated()->willReturn(false); $args->getEntity()->willReturn($en_US); $indexPurger->purgeIndexesFromLocale($en_US)->shouldBeCalled(); $this->postUpdate($args); }