From d61f3a6a1ec29c5d352757b4440377593808865f Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 12 Sep 2013 10:48:27 +0200 Subject: [PATCH] product loop test --- .../Core/Template/Element/BaseLoopTestor.php | 24 +++++++++++++++++++ .../Tests/Core/Template/Loop/ProductTest.php | 20 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php index 4a9cb4158..544e06bb0 100755 --- a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php +++ b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php @@ -29,6 +29,7 @@ use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Security\SecurityContext; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Tools\URL; /** * @@ -82,9 +83,32 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase $this->securityContext = new SecurityContext($this->request);*/ + $stubRouterAdmin = $this->getMockBuilder('\Symfony\Component\Routing\Router') + ->disableOriginalConstructor() + ->setMethods(array('getContext')) + ->getMock(); + + $stubRequestContext = $this->getMockBuilder('\Symfony\Component\Routing\RequestContext') + ->disableOriginalConstructor() + ->setMethods(array('getHost')) + ->getMock(); + + $stubRequestContext->expects($this->any()) + ->method('getHost') + ->will($this->returnValue('localhost')); + + $stubRouterAdmin->expects($this->any()) + ->method('getContext') + ->will($this->returnValue( + $stubRequestContext + )); + + $this->container->set('request', $request); $this->container->set('event_dispatcher', new EventDispatcher()); $this->container->set('thelia.securityContext', new SecurityContext($request)); + $this->container->set('router.admin', $stubRouterAdmin); + $this->container->set('thelia.url.manager', new URL($this->container)); $this->instance = $this->getTestedInstance(); $this->instance->initializeArgs($this->getMandatoryArguments()); diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php index 8fc7d5ae5..4fb6e7874 100755 --- a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php @@ -23,6 +23,7 @@ namespace Thelia\Tests\Core\Template\Loop; +use Thelia\Model\ProductQuery; use Thelia\Tests\Core\Template\Element\BaseLoopTestor; use Thelia\Core\Template\Loop\Product; @@ -48,4 +49,23 @@ class ProductTest extends BaseLoopTestor { return array(); } + + public function testSearchById() + { + $product = ProductQuery::create()->findOne(); + + $loop = new Product($this->container); + $loop->initializeArgs(array( + "type" => "product", + "name" => "product", + "id" => $product->getId(), + )); + $loopResults = $loop->exec($pagination); + + $this->assertEquals(1, $loopResults->getCount()); + + $substitutions = $loopResults->current()->getVarVal(); + + $this->assertEquals($product->getId(), $substitutions['ID']); + } }