コード例 #1
0
ファイル: SegmentTest.php プロジェクト: Maksold/platform
 public function testSettersAndGetters()
 {
     $this->assertNull($this->entity->getId());
     $this->assertNull($this->entity->getName());
     $this->assertNull($this->entity->getDefinition());
     $this->assertNull($this->entity->getDescription());
     $this->assertNull($this->entity->getType());
     $this->assertNull($this->entity->getEntity());
     $this->assertNull($this->entity->getOwner());
     $this->assertNull($this->entity->getCreatedAt());
     $this->assertNull($this->entity->getUpdatedAt());
     $this->assertNull($this->entity->getLastRun());
     $this->assertNull($this->entity->getOrganization());
     $testData = uniqid('name');
     $this->entity->setName($testData);
     $this->assertEquals($testData, $this->entity->getName());
     $testData = uniqid('definition');
     $this->entity->setDefinition($testData);
     $this->assertEquals($testData, $this->entity->getDefinition());
     $testData = uniqid('description');
     $this->entity->setDescription($testData);
     $this->assertEquals($testData, $this->entity->getDescription());
     $testData = $this->getMock('Oro\\Bundle\\SegmentBundle\\Entity\\SegmentType', [], ['testTypeName']);
     $this->entity->setType($testData);
     $this->assertSame($testData, $this->entity->getType());
     $testData = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit');
     $this->entity->setOwner($testData);
     $this->assertSame($testData, $this->entity->getOwner());
     $testData = uniqid('entity');
     $this->entity->setEntity($testData);
     $this->assertEquals($testData, $this->entity->getEntity());
     $testData = new \DateTime();
     $this->entity->setCreatedAt($testData);
     $this->assertSame($testData, $this->entity->getCreatedAt());
     $testData = new \DateTime();
     $this->entity->setUpdatedAt($testData);
     $this->assertSame($testData, $this->entity->getUpdatedAt());
     $testData = new \DateTime();
     $this->entity->setLastRun($testData);
     $this->assertSame($testData, $this->entity->getLastRun());
     $testData = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization');
     $this->entity->setOrganization($testData);
     $this->assertSame($testData, $this->entity->getOrganization());
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var User $user */
     $user = $manager->getRepository('OroUserBundle:User')->findOneByUsername('admin');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     foreach ($this->data as $data) {
         $entity = new Segment();
         $type = $manager->getRepository('OroSegmentBundle:SegmentType')->find($data['type']);
         $entity->setType($type);
         $entity->setDefinition(json_encode($data['definition']));
         $entity->setOrganization($organization);
         $entity->setOwner($user->getBusinessUnits()->first());
         $this->setEntityPropertyValues($entity, $data, ['reference', 'type', 'definition']);
         $this->setReference($data['reference'], $entity);
         $manager->persist($entity);
     }
     $manager->flush();
 }
コード例 #3
0
ファイル: LoadSegmentData.php プロジェクト: Maksold/platform
 public function load(ObjectManager $manager)
 {
     $staticType = $manager->getRepository('OroSegmentBundle:SegmentType')->find(SegmentType::TYPE_STATIC);
     if (!$staticType) {
         $staticType = new SegmentType(SegmentType::TYPE_STATIC);
         $staticType->setLabel('Static');
         $manager->persist($staticType);
     }
     $dynamicType = $manager->getRepository('OroSegmentBundle:SegmentType')->find(SegmentType::TYPE_DYNAMIC);
     if (!$dynamicType) {
         $dynamicType = new SegmentType(SegmentType::TYPE_DYNAMIC);
         $dynamicType->setLabel('Dynamic');
         $manager->persist($dynamicType);
     }
     $organisation = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $owner = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(array('name' => 'Test'));
     if (!$owner) {
         $owner = new BusinessUnit();
         $owner->setName('Test');
         $owner->setOrganization($organisation);
         $manager->persist($owner);
     }
     for ($i = 1; $i <= self::COUNT; $i++) {
         $definition = array('columns' => array('func' => null, 'label' => 'label' . $i, 'name' => '', 'sorting' => ''), 'filters' => array());
         $entity = new Segment();
         $entity->setCreatedAt(new \DateTime('now'));
         $entity->setDefinition(json_encode($definition));
         $entity->setDescription('description_' . $i);
         $entity->setEntity('Oro\\Bundle\\TestFrameworkBundle\\Entity\\WorkflowAwareEntity');
         $entity->setLastRun(new \DateTime('now'));
         $entity->setName('segment_' . $i);
         $entity->setOwner($owner);
         $entity->setType(rand(0, 100) % 2 ? $staticType : $dynamicType);
         $entity->setUpdatedAt(new \DateTime('now'));
         $entity->setOrganization($organisation);
         $manager->persist($entity);
     }
     $manager->flush();
 }