fix tests
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user