/** * {@inheritdoc} * * @return Group */ protected function createEntity(array $data) { $group = new Group(); $group->setCode($data['code']); $type = new GroupType(); $type->setCode($data['type']); $type->setVariant($data['type'] === 'VARIANT'); $group->setType($type); foreach ($this->getLabels($data) as $locale => $label) { $translation = $group->getTranslation($locale); $translation->setLabel($label); $group->addTranslation($translation); } foreach ($this->getAttributes($data) as $attribute) { $group->addAttribute($attribute); } return $group; }
function it_skips_a_group_when_object_is_invalid($groupConverter, $repository, $groupUpdater, $validator, GroupInterface $group, ConstraintViolationListInterface $violationList) { $repository->getIdentifierProperties()->willReturn(['code']); $repository->findOneByIdentifier(Argument::any())->willReturn($group); $groupType = new GroupType(); $groupType->setVariant(false); $group->getType()->willReturn($groupType); $group->getId()->willReturn(42); $group->getProductTemplate()->willReturn(null); $values = $this->getValues(); $groupConverter->convert($values['original_values'])->willReturn($values['converted_values']); $groupUpdater->update($group, $values['converted_values'])->shouldBeCalled(); $validator->validate($group)->willReturn($violationList); $this->process($values['original_values'])->shouldReturn($group); $groupUpdater->update($group, $values['converted_values'])->willThrow(new \InvalidArgumentException()); $violation = new ConstraintViolation('Error', 'foo', [], 'bar', 'code', 'mycode'); $violations = new ConstraintViolationList([$violation]); $validator->validate($group)->willReturn($violations); $this->shouldThrow('Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->during('process', [$values['original_values']]); }
function it_skips_a_variant_group_when_object_is_invalid($repository, $variantUpdater, $validator, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ConstraintViolationListInterface $violationList) { $repository->getIdentifierProperties()->willReturn(['code']); $repository->findOneByIdentifier(Argument::any())->willReturn($variantGroup); $groupType = new GroupType(); $groupType->setVariant(true); $productTemplate->getValues()->willReturn(new ArrayCollection()); $variantGroup->getType()->willReturn($groupType); $variantGroup->getId()->willReturn(42); $variantGroup->getProductTemplate()->willReturn($productTemplate); $values = $this->getValues(); $variantUpdater->update($variantGroup, $values)->shouldBeCalled(); $validator->validate($variantGroup)->willReturn($violationList); $this->process($values)->shouldReturn($variantGroup); $variantUpdater->update($variantGroup, $values)->willThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.')); $violation = new ConstraintViolation('Error', 'foo', [], 'bar', 'code', 'mycode'); $violations = new ConstraintViolationList([$violation]); $validator->validate($variantGroup)->willReturn($violations); $this->shouldThrow('Akeneo\\Component\\Batch\\Item\\InvalidItemException')->during('process', [$values]); }
/** * Test getter/setter for translations property */ public function testTranslations() { $this->assertCount(0, $this->type->getTranslations()); // Change value and assert new $newTranslation = new GroupTypeTranslation(); $this->assertEntity($this->type->addTranslation($newTranslation)); $this->assertCount(1, $this->type->getTranslations()); $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\GroupTypeTranslation', $this->type->getTranslations()->first()); $this->type->addTranslation($newTranslation); $this->assertCount(1, $this->type->getTranslations()); $this->assertEntity($this->type->removeTranslation($newTranslation)); $this->assertCount(0, $this->type->getTranslations()); }
/** * @param string $code * @param string $label * @param bool $isVariant * * @return \Pim\Bundle\CatalogBundle\Model\GroupTypeInterface */ protected function createGroupType($code, $label, $isVariant) { $type = new GroupType(); $type->setCode($code); $type->setVariant($isVariant); $type->setLocale('en_US')->setLabel($label); $this->validate($type); $this->persist($type); return $type; }
/** * Remove a group type * @param GroupType $groupType * * @AclAncestor("pim_enrich_group_type_remove") * @return Response|RedirectResponse */ public function removeAction(GroupType $groupType) { if ($groupType->isVariant()) { throw new DeleteException($this->getTranslator()->trans('flash.group type.cant remove variant')); } elseif (count($groupType->getGroups()) > 0) { throw new DeleteException($this->getTranslator()->trans('flash.group type.cant remove used')); } else { $this->remove($groupType); } if ($this->getRequest()->isXmlHttpRequest()) { return new Response('', 204); } else { return $this->redirectToRoute('pim_enrich_group_type_index'); } }
/** * {@inheritDoc} */ public function getReference() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array()); return parent::getReference(); }
/** * @param GroupType $groupType * * @Given /^I should be on the ("([^"]*)" group type) page$/ */ public function iShouldBeOnTheGroupTypePage(GroupType $groupType) { $expectedAddress = $this->getPage('GroupType edit')->getUrl(array('id' => $groupType->getId())); $this->assertAddress($expectedAddress); }
/** * @param string $code * @param string $label * @param bool $isVariant * * @return \Pim\Component\Catalog\Model\GroupTypeInterface */ protected function createGroupType($code, $label, $isVariant) { $type = new GroupType(); $type->setCode($code); $type->setVariant($isVariant); $type->setLocale('en_US')->setLabel($label); $this->validate($type); $this->getContainer()->get('pim_catalog.saver.group_type')->save($type); return $type; }