fix tests

This commit is contained in:
Etienne Roudeix
2013-12-09 15:31:27 +01:00
parent 28d2add37d
commit 95d327f976
4 changed files with 56 additions and 49 deletions

View File

@@ -35,13 +35,14 @@ use Thelia\Model\ContentFolder;
use Thelia\Model\ContentFolderQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\FolderQuery;
use Thelia\Tests\TestCaseWithURLToolSetup;
/**
* Class ContentTest
* @package Thelia\Tests\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ContentTest extends BaseAction
class ContentTest extends TestCaseWithURLToolSetup
{
use RewrittenUrlTestTrait;

View File

@@ -30,14 +30,45 @@ use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
use Thelia\Core\Event\Folder\FolderUpdateEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\FolderQuery;
use Thelia\Tests\TestCaseWithURLToolSetup;
/**
* Class FolderTest
* @package Thelia\Tests\Action\ImageTest
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class FolderTest extends BaseAction
class FolderTest extends TestCaseWithURLToolSetup
{
use RewrittenUrlTestTrait;
public function getUpdateEvent(&$folder)
{
if(!$folder instanceof \Thelia\Model\Folder) {
$folder = $this->getRandomFolder();
}
$event = new FolderUpdateEvent($folder->getId());
$event
->setVisible(1)
->setLocale($folder->getLocale())
->setTitle($folder->getTitle())
->setChapo($folder->getChapo())
->setDescription($folder->getDescription())
->setPostscriptum($folder->getPostscriptum())
->setParent($folder->getParent())
;
return $event;
}
public function processUpdateAction($event)
{
$contentAction = new Folder($this->getContainer());
$contentAction->update($event);
return $event->getFolder();
}
/**
* test folder creation
* @covers Thelia\Action\Folder::create

View File

@@ -8,53 +8,17 @@ use Thelia\Model\ConfigQuery;
use Thelia\Rewriting\RewritingResolver;
use Thelia\Tools\URL;
/**
* Class RewrittenUrlTestTrait
* @package Thelia\Tests\Action
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
trait RewrittenUrlTestTrait
{
abstract public function getUpdateEvent(&$object);
abstract public function processUpdateAction($event);
public function setUp()
{
$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
));
$container = $this->getContainer();
$container->set('router.admin', $stubRouterAdmin);
new URL($container);
}
/**
* @expectedException \Thelia\Form\Exception\FormValidationException
* @expectedExceptionCode 100
*/
public function testUpdateEmptyUrl()
{
$object = null;
$event = $this->getUpdateEvent($object);
$event->setUrl('');
$updatedObject = $this->processUpdateAction($event);
}
/**
* @expectedException \Thelia\Form\Exception\FormValidationException
* @expectedExceptionCode 100
@@ -77,7 +41,7 @@ trait RewrittenUrlTestTrait
$event->setUrl($existingUrl->getUrl());
$updatedObject = $this->processUpdateAction($event);
$this->processUpdateAction($event);
}
public function testUpdateUrl()

View File

@@ -30,15 +30,21 @@ namespace Thelia\Tests;
*/
class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase
{
private $container = null;
public function __construct()
{
$this->container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
$this->container->set("event_dispatcher", $dispatcher);
$this->setupURLTool();
}
protected function setupURLTool()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$context = new \Symfony\Component\Routing\RequestContext(
'/thelia/index.php',
'GET',
@@ -57,8 +63,13 @@ class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase
->method('getContext')
->will($this->returnValue($context));
$container->set("router.admin", $router);
$this->container->set("router.admin", $router);
new \Thelia\Tools\URL($container);
new \Thelia\Tools\URL($this->container);
}
public function getContainer()
{
return $this->container;
}
}