Inital commit
This commit is contained in:
40
tests/phpunit/Thelia/Tests/Controller/ControllerTestBase.php
Normal file
40
tests/phpunit/Thelia/Tests/Controller/ControllerTestBase.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ControllerTestBase
|
||||
* @package Thelia\Tests\ImportExport\Import
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
abstract class ControllerTestBase extends ContainerAwareTestCase
|
||||
{
|
||||
/** @var BaseController */
|
||||
protected $controller;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = $this->getController();
|
||||
$this->controller->setContainer($this->container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Controller\BaseController The controller you want to test
|
||||
*/
|
||||
abstract protected function getController();
|
||||
}
|
||||
100
tests/phpunit/Thelia/Tests/Controller/DefaultControllerTest.php
Executable file
100
tests/phpunit/Thelia/Tests/Controller/DefaultControllerTest.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Controller\Front\DefaultController;
|
||||
|
||||
/**
|
||||
* Class DefaultControllerTest
|
||||
* @package Thelia\Tests\Controller
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNoAction()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request();
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), "index");
|
||||
}
|
||||
|
||||
public function testNoActionWithGetParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(
|
||||
"view" => "foo"
|
||||
));
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithPostParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttribute()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndQuery()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array("view" => "bar"),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndRequest()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "bar"),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
}
|
||||
146
tests/phpunit/Thelia/Tests/Controller/ProductControllerTest.php
Normal file
146
tests/phpunit/Thelia/Tests/Controller/ProductControllerTest.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Controller\Admin\ProductController;
|
||||
use Thelia\Model\ProductDocumentQuery;
|
||||
use Thelia\Model\ProductImageQuery;
|
||||
use Thelia\Model\ProductSaleElementsProductDocumentQuery;
|
||||
use Thelia\Model\ProductSaleElementsProductImageQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
|
||||
/**
|
||||
* Class ProductControllerTest
|
||||
* @package Thelia\Tests\Controller
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductControllerTest extends ControllerTestBase
|
||||
{
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$parser = $this->getMockBuilder("Thelia\\Core\\Template\\ParserInterface")
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$container->set("thelia.parser", $parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Controller\BaseController The controller you want to test
|
||||
*/
|
||||
protected function getController()
|
||||
{
|
||||
$controller = new ProductController();
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
public function testAssociatePSEImage()
|
||||
{
|
||||
/**
|
||||
* Get a product sale elements which has a related product image
|
||||
*/
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->useProductQuery()
|
||||
->joinProductImage()
|
||||
->endUse()
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this image and check if they are associated
|
||||
*/
|
||||
$productImage = ProductImageQuery::create()
|
||||
->findOneByProductId($pse->getProductId())
|
||||
;
|
||||
|
||||
$association = ProductSaleElementsProductImageQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductImageId($productImage->getId())
|
||||
;
|
||||
|
||||
$isAssociated = $association !== null;
|
||||
|
||||
$this->controller
|
||||
->getAssociationResponseData(
|
||||
$pse->getId(),
|
||||
"image",
|
||||
$productImage->getId()
|
||||
);
|
||||
|
||||
$newAssociation = ProductSaleElementsProductImageQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductImageId($productImage->getId())
|
||||
;
|
||||
|
||||
$isNowAssociated = $newAssociation !== null;
|
||||
|
||||
$this->assertFalse($isAssociated === $isNowAssociated);
|
||||
}
|
||||
|
||||
public function testAssociatePSEDocument()
|
||||
{
|
||||
/**
|
||||
* Get a product sale elements which has a related product image
|
||||
*/
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->useProductQuery()
|
||||
->joinProductDocument()
|
||||
->endUse()
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this image and check if they are associated
|
||||
*/
|
||||
$productDocument = ProductDocumentQuery::create()
|
||||
->findOneByProductId($pse->getProductId())
|
||||
;
|
||||
|
||||
$association = ProductSaleElementsProductDocumentQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductDocumentId($productDocument->getId())
|
||||
;
|
||||
|
||||
$isAssociated = $association !== null;
|
||||
|
||||
$this->controller
|
||||
->getAssociationResponseData(
|
||||
$pse->getId(),
|
||||
"document",
|
||||
$productDocument->getId()
|
||||
);
|
||||
|
||||
$newAssociation = ProductSaleElementsProductDocumentQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductDocumentId($productDocument->getId())
|
||||
;
|
||||
|
||||
$isNowAssociated = $newAssociation !== null;
|
||||
|
||||
$this->assertFalse($isAssociated === $isNowAssociated);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user