diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 58baea153..a9b61e1db 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -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 */ -class ContentTest extends BaseAction +class ContentTest extends TestCaseWithURLToolSetup { use RewrittenUrlTestTrait; diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index fe24cc994..fbe4e0e1a 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -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 */ -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 diff --git a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php index e6ec58df8..567fbe3d9 100644 --- a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php +++ b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php @@ -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 + */ 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() diff --git a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php index e0fd3f678..41a955f87 100644 --- a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php +++ b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php @@ -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; } }