function it_builds_versions_for_versionable_entities($normalizer, AbstractProduct $product) { $product->getId()->willReturn(1); $normalizer->normalize($product, 'csv', ['versioning' => true])->willReturn(['bar' => 'baz']); $version = $this->buildVersion($product, 'foo'); $version->shouldBeAnInstanceOf('Pim\\Bundle\\VersioningBundle\\Model\\Version'); $version->getAuthor()->shouldReturn('foo'); $version->isPending()->shouldReturn(false); $version->getVersion()->shouldReturn(1); $version->getResourceId()->shouldReturn(1); $version->getSnapshot()->shouldReturn(['bar' => 'baz']); $version->getChangeset()->shouldReturn(['bar' => ['old' => '', 'new' => 'baz']]); }
function it_builds_pending_versions_when_versioning_an_entity(AbstractProduct $product, $builder, $repo) { $product->getId()->willReturn(1); $pending1 = new Version('Product', 1, 'julia'); $pending1->setChangeset(['foo' => 'bar']); $pending2 = new Version('Product', 1, 'julia'); $pending2->setChangeset(['foo' => 'fubar']); $repo->findBy(Argument::cetera())->willReturn([$pending1, $pending2]); $builder->buildPendingVersion($pending1, null)->willReturn($pending1); $builder->buildPendingVersion($pending2, $pending1)->willReturn($pending2); $builder->buildVersion(Argument::cetera())->willReturn(new Version('Product', 1, 'julia')); $versions = $this->buildVersion($product); $versions->shouldHaveCount(3); }
function it_initializes_the_operation_with_common_attributes_of_the_products($productRepository, AbstractProduct $product1, AbstractProduct $product2, AbstractAttribute $name, $productManager, $massActionManager) { $this->setObjectsToMassEdit([$product1, $product2]); $product1->getId()->willReturn(1); $product2->getId()->willReturn(2); $name->setLocale(Argument::any())->willReturn($name); $name->getAttributeType()->willReturn('pim_catalog_text'); $name->isScopable()->willReturn(false); $name->isLocalizable()->willReturn(false); $name->getCode()->willReturn('name'); $name->getGroup()->willReturn(new AttributeGroup()); $massActionManager->findCommonAttributes([1, 2])->willReturn([$name]); $this->initialize(); $this->getCommonAttributes()->shouldReturn([$name]); $this->getValues()->shouldHaveCount(1); }
function it_applies_a_filter_on_product_when_its_in_an_expected_association(FilterDatasourceAdapterInterface $datasource, $utility, ProductRepositoryInterface $prodRepository, ProductQueryBuilderInterface $pqb, QueryBuilder $qb, $extractor, $assocRepository, ProductManager $productManager, AssociationType $assocType, AbstractAssociation $association, AbstractProduct $productOwner, AbstractProduct $productAssociatedOne, AbstractProduct $productAssociatedTwo) { $extractor->getDatagridParameter('_parameters', [])->willReturn([]); $extractor->getDatagridParameter('associationType')->willReturn(1); $assocRepository->findOneBy(Argument::any())->willReturn($assocType); $extractor->getDatagridParameter('product')->willReturn(11); $utility->getProductManager()->willReturn($productManager); $productManager->find(11)->willReturn($productOwner); $productOwner->getAssociationForType($assocType)->willReturn($association); $association->getProducts()->willReturn([$productAssociatedOne, $productAssociatedTwo]); $productAssociatedOne->getId()->willReturn(12); $productAssociatedTwo->getId()->willReturn(13); $datasource->getQueryBuilder()->willReturn($qb); $utility->getProductRepository()->willReturn($prodRepository); $prodRepository->getProductQueryBuilder($qb)->willReturn($pqb); $pqb->addFieldFilter('id', 'IN', [12, 13])->shouldBeCalled(); $this->apply($datasource, ['type' => null, 'value' => 1]); }
/** * @param AbstractProduct $product * @param AssociationType $type * * @return array */ protected function getAssociatedProductIds(AbstractProduct $product, AssociationType $type) { $productIds = []; $association = $product->getAssociationForType($type); if ($association) { foreach ($association->getProducts() as $product) { $productIds[] = $product->getId(); } } return $productIds ?: [0]; }