/**
  * {@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;
 }
예제 #2
0
 /**
  * Test for __toString method
  */
 public function testToString()
 {
     // Change value and assert new
     $newCode = 'toStringCode';
     $expectedCode = '[' . $newCode . ']';
     $this->family->setCode($newCode);
     $this->assertEquals($expectedCode, $this->family->__toString());
     $newLabel = 'toStringLabel';
     $this->assertEntity($this->family->setLocale('en_US'));
     $this->assertEntity($this->family->setLabel($newLabel));
     $this->assertEquals($newLabel, $this->family->__toString());
     // if no translation, assert the expected code is returned
     $this->family->setLocale('fr_FR');
     $this->assertEquals($expectedCode, $this->family->__toString());
     // if empty translation, assert the expected code is returned
     $this->family->setLabel('');
     $this->assertEquals($expectedCode, $this->family->__toString());
 }
 function it_does_not_add_violation_when_a_immutable_property_has_not_been_modified($context, $entityManager, UnitOfWork $unitOfWork, Immutable $constraint)
 {
     $family = new Family();
     $family->setCode('MyOriginalCode');
     $entityManager->getUnitOfWork()->willReturn($unitOfWork);
     $unitOfWork->getOriginalEntityData($family)->willReturn(['code' => 'MyOriginalCode']);
     $context->buildViolation(Argument::any(), Argument::any())->shouldNotBeCalled();
     $constraint->properties = ['code'];
     $this->validate($family, $constraint);
 }
 /**
  * Test related methods
  */
 public function testGuessUpdates()
 {
     $versionables = array('Pim\\Bundle\\CatalogBundle\\Entity\\Attribute', 'Pim\\Bundle\\CatalogBundle\\Entity\\Family');
     $attribute = new Attribute();
     $attribute->setCode('my code');
     $guesser = new VersionableUpdateGuesser($versionables);
     $em = $this->getEntityManagerMock();
     $updates = $guesser->guessUpdates($em, $attribute, UpdateGuesserInterface::ACTION_UPDATE_ENTITY);
     $this->assertEquals(1, count($updates));
     $this->assertEquals($attribute, $updates[0]);
     $family = new Family();
     $family->setCode('my code');
     $updates = $guesser->guessUpdates($em, $family, UpdateGuesserInterface::ACTION_UPDATE_ENTITY);
     $this->assertEquals(1, count($updates));
     $this->assertEquals($family, $updates[0]);
 }
 /**
  * {@inheritDoc}
  */
 public function setCode($code)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCode', array($code));
     return parent::setCode($code);
 }
 /**
  * Return the generated families as Family object
  *
  * @return array
  */
 public function getFamilyObjects()
 {
     $familyObjects = [];
     foreach ($this->families as $code => $family) {
         $familyObject = new Family();
         $familyObject->setCode($code);
         $familyObjects[] = $familyObject;
     }
     return $familyObjects;
 }