public function testApplyPriceListLimitationsNotApplied() { /** @var \PHPUnit_Framework_MockObject_MockObject|QueryBuilder $qb */ $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $this->priceListTreeHandler->expects($this->never())->method($this->anything()); $this->modifier->applyPriceListLimitations($qb); }
/** * {@inheritdoc} */ protected function searchEntities($search, $firstResult, $maxResults) { $currency = null; if ($this->request) { $currency = $this->request->get('currency'); } $queryBuilder = $this->entityRepository->createQueryBuilder('p'); $queryBuilder->innerJoin('p.names', 'pn', 'WITH', $queryBuilder->expr()->isNull('pn.locale'))->where($queryBuilder->expr()->like('LOWER(p.sku)', ':search'))->orWhere($queryBuilder->expr()->like('LOWER(pn.string)', ':search'))->setParameter('search', '%' . strtolower($search) . '%')->setFirstResult($firstResult)->setMaxResults($maxResults); $this->productListModifier->applyPriceListLimitations($queryBuilder, $currency); $query = $this->aclHelper->apply($queryBuilder); return $query->getResult(); }
/** * {@inheritdoc} */ public function visitDatasource(DatagridConfiguration $config, DatasourceInterface $datasource) { if (!$this->isApplicable($config) || !$datasource instanceof OrmDatasource) { return; } if ($this->request) { $currency = $this->request->get(self::CURRENCY_KEY, null); } else { $currency = null; } /** @var OrmDatasource $datasource */ $qb = $datasource->getQueryBuilder(); $this->productListModifier->applyPriceListLimitations($qb, $currency); $this->applied = true; }
/** * @dataProvider applyPriceListLimitationsDataProvider * @param string|null $currency * @param array $expectedProductSku */ public function testApplyPriceListLimitations($currency, array $expectedProductSku) { /** @var PriceList $priceList */ $priceList = $this->getReference('price_list_2'); $user = new AccountUser(); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->any())->method('getUser')->will($this->returnValue($user)); /** @var \PHPUnit_Framework_MockObject_MockObject|TokenStorageInterface $tokenStorage */ $tokenStorage = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface'); $tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token)); /** @var \PHPUnit_Framework_MockObject_MockObject|PriceListTreeHandler $priceListTreeHandler */ $priceListTreeHandler = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Model\\PriceListTreeHandler')->disableOriginalConstructor()->getMock(); $priceListTreeHandler->expects($this->once())->method('getPriceList')->with($user)->will($this->returnValue($priceList)); $modifier = new FrontendProductListModifier($tokenStorage, $priceListTreeHandler); /** @var EntityManager $em */ $em = $this->getContainer()->get('doctrine')->getManager(); $qb = $em->createQueryBuilder()->select('p')->from('OroB2BProductBundle:Product', 'p')->orderBy('p.sku'); $modifier->applyPriceListLimitations($qb, $currency); /** @var Product[] $result */ $result = $qb->getQuery()->getResult(); $this->assertCount(count($expectedProductSku), $result); $sku = array_map(function (Product $product) { return $product->getSku(); }, $result); $this->assertEquals($expectedProductSku, $sku); }