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()); }
/** * {@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(); }
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(); }
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()); }
public function testStaticApply() { $staticSegmentStub = new Segment(); $staticSegmentStub->setType(new SegmentType(SegmentType::TYPE_STATIC)); $filterData = ['value' => $staticSegmentStub]; $subquery = 'SELECT ts1.entity_id FROM OroSegmentBundle:SegmentSnapshot ts1 WHERE ts1.segmentId = :segment'; $em = $this->getTestEntityManager(); $qb = new QueryBuilder($em); $qb->select(['t1.name'])->from('OroSegmentBundle:CmsUser', 't1'); $ds = new OrmFilterDatasourceAdapter($qb); $query = new Query($em); $query->setDQL($subquery); $query->setParameter('segment', $staticSegmentStub); $this->staticSegmentQueryBuilder->expects($this->once())->method('build')->with($staticSegmentStub)->will($this->returnValue($query)); $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 t1.id', 'IN(SELECT ts1.entity_id FROM OroSegmentBundle:SegmentSnapshot ts1 WHERE ts1.segmentId = :segment)']; $expectedResult = implode(' ', $expectedResult); $this->assertEquals($expectedResult, $ds->getQueryBuilder()->getDQL()); $params = $ds->getQueryBuilder()->getParameters(); $this->assertCount(1, $params, 'Should pass params to main query builder'); $this->assertEquals($staticSegmentStub, $params[0]->getValue()); }