Esempio n. 1
0
 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());
 }
 /**
  * @param bool|string $entity
  * @param array|bool  $definition
  * @param bool|int    $identifier
  *
  * @return Segment
  */
 public function getSegment($entity = false, $definition = false, $identifier = false)
 {
     $segment = new Segment();
     $segment->setEntity(false === $entity ? self::TEST_ENTITY : $entity);
     $segment->setDefinition(json_encode(false === $definition ? $this->getDefaultDefinition() : $definition));
     $refProperty = new \ReflectionProperty(get_class($segment), 'id');
     $refProperty->setAccessible(true);
     $refProperty->setValue($segment, false === $identifier ? self::TEST_IDENTIFIER : $identifier);
     return $segment;
 }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
 public function testStaticApply()
 {
     $staticSegmentStub = new Segment();
     $staticSegmentStub->setType(new SegmentType(SegmentType::TYPE_STATIC));
     $staticSegmentStub->setEntity('Oro\\Bundle\\SegmentBundle\\Tests\\Unit\\Stub\\Entity\\CmsUser');
     $filterData = ['value' => $staticSegmentStub];
     $em = $this->getEM();
     $qb = $em->createQueryBuilder()->select(['t1.name'])->from('OroSegmentBundle:CmsUser', 't1');
     $queryBuilder = new QueryBuilder($em);
     $queryBuilder->select(['ts1.id'])->from('OroSegmentBundle:SegmentSnapshot', 'ts1')->andWhere('ts1.segmentId = :segment')->setParameter('segment', self::TEST_PARAM_VALUE);
     $ds = new OrmFilterDatasourceAdapter($qb);
     $this->staticSegmentQueryBuilder->expects(static::once())->method('getQueryBuilder')->with($staticSegmentStub)->will(static::returnValue($queryBuilder));
     $this->filter->init('someName', [FilterUtility::DATA_NAME_KEY => self::TEST_FIELD_NAME]);
     $this->filter->apply($ds, $filterData);
     $expectedResult = ['SELECT t1.name FROM OroSegmentBundle:CmsUser t1 WHERE', 'EXISTS(SELECT ts1.id FROM OroSegmentBundle:SegmentSnapshot ts1 ' . 'WHERE ts1.segmentId = :segment AND ts1.integerEntityId = t1.id)'];
     $expectedResult = implode(' ', $expectedResult);
     static::assertEquals($expectedResult, $ds->getQueryBuilder()->getDQL());
     $params = $ds->getQueryBuilder()->getParameters();
     static::assertCount(1, $params, 'Should pass params to main query builder');
     static::assertEquals(self::TEST_PARAM_VALUE, $params[0]->getValue());
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function setEntity($entity)
 {
     $this->segment->setEntity($entity);
 }