Exemplo n.º 1
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());
 }
Exemplo n.º 2
0
 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());
 }