/** * {@inheritdoc} * * @return Category */ protected function createEntity(array $data) { $category = new Category(); $category->setCode($data['code']); foreach ($this->getLabels($data) as $locale => $label) { $translation = $category->getTranslation($locale); $translation->setLabel($label); $category->addTranslation($translation); } if ($data['parent']) { $parent = new Category(); $parent->setCode($data['parent']); $category->setParent($parent); } return $category; }
/** * Test for __toString method */ public function testToString() { // Change value and assert new $newCode = 'code'; $expectedCode = '[' . $newCode . ']'; $this->category->setCode($newCode); $this->assertEquals($expectedCode, $this->category->__toString()); $newLabel = 'test-label'; $this->assertEntity($this->category->setLocale('en_US')); $this->assertEntity($this->category->setLabel($newLabel)); $this->assertEquals($newLabel, $this->category->__toString()); // if no translation, assert the expected code is returned $this->category->setLocale('fr_FR'); $this->assertEquals($expectedCode, $this->category->__toString()); // if empty translation, assert the expected code is returned $this->category->setLabel(''); $this->assertEquals($expectedCode, $this->category->__toString()); }
/** * {@inheritDoc} */ public function setCode($code) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCode', array($code)); return parent::setCode($code); }
/** * Create a category for testing * * @param string $code * * @return \Pim\Bundle\CatalogBundle\Entity\Category */ protected function createCategory($code) { $category = new Category(); $category->setCode($code); return $category; }