/** * {@inheritdoc} * * @return Family */ protected function createEntity(array $data) { $family = new Family(); $family->setCode('mycode'); foreach ($this->getLabels($data) as $locale => $label) { $translation = $family->getTranslation($locale); $translation->setLabel($label); $family->addTranslation($translation); } $codes = array('attribute1', 'attribute2', 'attribute3'); $attributes = array(); foreach ($codes as $code) { $attribute = new Attribute(); $attribute->setCode($code); $family->addAttribute($attribute); $attributes[] = $attribute; } $family->setAttributeAsLabel(current($attributes)); $channel1 = new Channel(); $channel1->setCode('channel1'); $channel2 = new Channel(); $channel2->setCode('channel2'); $requirements = array(array('attribute' => $attributes[0], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[2], 'channel' => $channel1, 'required' => false), array('attribute' => $attributes[0], 'channel' => $channel2, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel2, 'required' => false), array('attribute' => $attributes[2], 'channel' => $channel2, 'required' => true)); $attrRequirements = array(); foreach ($requirements as $requirement) { $attrRequirement = new AttributeRequirement(); $attrRequirement->setAttribute($requirement['attribute']); $attrRequirement->setChannel($requirement['channel']); $attrRequirement->setRequired($requirement['required']); $attrRequirements[] = $attrRequirement; } $family->setAttributeRequirements($attrRequirements); return $family; }
/** * Test getter/setter for translations property */ public function testTranslations() { $this->assertCount(0, $this->family->getTranslations()); // Change value and assert new $newTranslation = new FamilyTranslation(); $this->assertEntity($this->family->addTranslation($newTranslation)); $this->assertCount(1, $this->family->getTranslations()); $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\FamilyTranslation', $this->family->getTranslations()->first()); $this->family->addTranslation($newTranslation); $this->assertCount(1, $this->family->getTranslations()); $this->assertEntity($this->family->removeTranslation($newTranslation)); $this->assertCount(0, $this->family->getTranslations()); }
/** * {@inheritDoc} */ public function addTranslation(\Pim\Bundle\TranslationBundle\Entity\AbstractTranslation $translation) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addTranslation', array($translation)); return parent::addTranslation($translation); }