function it_reloads_variant_group_products_if_submit_fails($form, $request, $saver, $repository, GroupInterface $group, ProductInterface $product, GroupTypeInterface $groupType)
 {
     $form->setData($group)->shouldBeCalled();
     $request->isMethod('POST')->willReturn(true);
     $group->getProducts()->willReturn([$product]);
     $form->submit($request)->shouldBeCalled();
     $form->isValid()->willReturn(false);
     $groupType->isVariant()->willReturn(true);
     $group->getId()->willReturn(123);
     $repository->findAllForVariantGroup($group)->shouldBeCalled()->willReturn([]);
     $group->setProducts([])->shouldBeCalled();
     $group->getType()->willReturn($groupType);
     $saver->save($group)->shouldNotBeCalled();
     $this->process($group)->shouldReturn(false);
 }
 function it_normalizes_a_variant_group_with_its_values($transNormalizer, $valuesDenormalizer, $group, GroupTypeInterface $groupType, AttributeInterface $attr, ProductTemplateInterface $productTemplate)
 {
     $groupType->getCode()->willReturn('VARIANT');
     $groupType->isVariant()->willReturn(true);
     $group->getCode()->willReturn('laser_sabers');
     $valuesData = ['name' => 'Light saber model', 'size' => '120'];
     $context = ['with_variant_group_values' => true];
     $format = 'csv';
     $productTemplate->getValuesData()->willReturn($valuesData);
     $group->getProductTemplate()->willReturn($productTemplate);
     $group->getType()->willReturn($groupType);
     $attr->getCode()->willReturn('light_color');
     $group->getAxisAttributes()->willReturn([$attr]);
     $transNormalizer->normalize($group, $format, $context)->willReturn([]);
     $this->normalize($group, $format, $context)->shouldReturn(['code' => 'laser_sabers', 'type' => 'VARIANT', 'axis' => ['light_color'], 'values' => ['name' => 'Light saber model', 'size' => '120']]);
 }
 function it_adds_violation_when_validating_group_containing_products_with_non_unique_combination_of_axis_attributes($context, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, ProductInterface $redTShirtProduct, ProductInterface $redTShirtProduct2, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation)
 {
     $tShirtGroupType->isVariant()->willReturn(true);
     $tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
     $tShirtVariantGroup->getProducts()->willReturn([$redTShirtProduct, $redTShirtProduct2]);
     $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $sizeAttribute->getCode()->willReturn('size');
     $colorAttribute->getCode()->willReturn('color');
     $sizeProductValue->getOption()->willReturn('XL');
     $colorProductValue->getOption()->willReturn('Red');
     $redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct->getValue('color')->willReturn($colorProductValue);
     $redTShirtProduct2->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct2->getValue('color')->willReturn($colorProductValue);
     $tShirtVariantGroup->getLabel()->willReturn('Groupe TShirt');
     $context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'Groupe TShirt', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation);
     $this->validate($tShirtVariantGroup, $uniqueVariantAxisConstraint);
 }
Пример #4
0
 function it_is_not_attribute_removable_with_group_containing_attribute(AttributeInterface $attribute, GroupInterface $group, GroupTypeInterface $groupType, ArrayCollection $groupAttributes)
 {
     $groupType->isVariant()->willReturn(true);
     $groupAttributes->contains($attribute)->willReturn(true);
     $group->getType()->willReturn($groupType);
     $group->getAxisAttributes()->willReturn($groupAttributes);
     $group->addProduct($this)->willReturn($this);
     $this->addGroup($group);
     $this->isAttributeRemovable($attribute)->shouldReturn(false);
 }
 /**
  * @param GroupTypeInterface $groupType
  *
  * @Given /^I should be on the ("([^"]*)" group type) page$/
  */
 public function iShouldBeOnTheGroupTypePage(GroupTypeInterface $groupType)
 {
     $expectedAddress = $this->getPage('GroupType edit')->getUrl(['id' => $groupType->getId()]);
     $this->assertAddress($expectedAddress);
 }
 function it_normalizes_a_variant_group_with_its_values_on_versioning_context($transNormalizer, $valuesDenormalizer, $group, CustomSerializer $serializer, GroupTypeInterface $groupType, AttributeInterface $attr, ProductTemplateInterface $productTemplate, ProductValueInterface $productValue1)
 {
     $groupType->getCode()->willReturn('VARIANT');
     $groupType->isVariant()->willReturn(true);
     $group->getCode()->willReturn('lego');
     $valuesData = ['name' => 'Light saber model', 'size' => '120'];
     $context = ['versioning' => true];
     $format = 'csv';
     $productTemplate->getValuesData()->willReturn($valuesData);
     $valuesDenormalizer->denormalize($valuesData, 'ProductValue[]', 'json')->willReturn([$productValue1]);
     $newContext = array_merge($context, ['with_variant_group_values' => true]);
     $serializer->normalize($productValue1, $format, ['entity' => 'product'] + $newContext)->willReturn(['age' => '6+']);
     $group->getProductTemplate()->willReturn($productTemplate);
     $group->getType()->willReturn($groupType);
     $attr->getCode()->willReturn('model');
     $group->getAxisAttributes()->willReturn([$attr]);
     $transNormalizer->normalize($group, $format, $context)->willReturn([]);
     $this->setSerializer($serializer);
     $this->normalize($group, $format, $context)->shouldReturn(['code' => 'lego', 'type' => 'VARIANT', 'axis' => 'model', 'age' => '6+']);
 }