diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc233a9b..8b1515eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ #2.0.0-beta5 - Remove container from BaseAction. - fix sending mail on order creation +- less files in default templates are already compile in css. #2.0.0-beta4 - Tinymce is now a dedicated module. You need to activate it. diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index dfdeeb3b7..2029af138 100644 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -137,6 +137,8 @@ class Category extends BaseAction implements EventSubscriberInterface ->setVisible($category->getVisible() ? false : true) ->save() ; + + $event->setCategory($category); } /** diff --git a/core/lib/Thelia/Tests/Action/CategoryTest.php b/core/lib/Thelia/Tests/Action/CategoryTest.php index 50d60f01a..b7e839bdd 100644 --- a/core/lib/Thelia/Tests/Action/CategoryTest.php +++ b/core/lib/Thelia/Tests/Action/CategoryTest.php @@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Routing\Router; use Thelia\Action\Category; use Thelia\Core\Event\Category\CategoryDeleteEvent; +use Thelia\Core\Event\Category\CategoryToggleVisibilityEvent; use Thelia\Core\Event\Category\CategoryUpdateEvent; use Thelia\Core\Event\UpdateSeoEvent; use Thelia\Model\Category as CategoryModel; @@ -44,6 +45,9 @@ use Thelia\Tools\URL; class CategoryTest extends TestCaseWithURLToolSetup { + /** + * @return \Thelia\Model\Category + */ protected function getRandomCategory() { $category = CategoryQuery::create() @@ -57,59 +61,6 @@ class CategoryTest extends TestCaseWithURLToolSetup return $category; } - public function getUpdateEvent(&$category) - { - if (!$category instanceof \Thelia\Model\Category) { - $category = $this->getRandomCategory(); - } - - $event = new CategoryUpdateEvent($category->getId()); - - $event - ->setLocale('en_US') - ->setTitle('bar') - ->setDescription('bar description') - ->setChapo('bar chapo') - ->setPostscriptum('bar postscriptum') - ->setVisible(0) - ->setParent(0) - ->setDispatcher($this->getDispatcher()) - ; - } - - public function getUpdateSeoEvent(&$category) - { - if (!$category instanceof \Thelia\Model\Category) { - $category = $this->getRandomCategory(); - } - - $event = new UpdateSeoEvent($category->getId()); - $event->setDispatcher($this->getDispatcher()); - $event - ->setLocale($category->getLocale()) - ->setMetaTitle($category->getMetaTitle()) - ->setMetaDescription($category->getMetaDescription()) - ->setMetaKeywords($category->getMetaKeywords()); - - return $event; - } - - public function processUpdateAction($event) - { - $action = new Category(); - $action->update($event); - - return $event->getCategory(); - } - - public function processUpdateSeoAction($event) - { - $action = new Category(); - - return $action->updateSeo($event); - - } - public function testCreate() { $event = new CategoryCreateEvent(); @@ -194,4 +145,21 @@ class CategoryTest extends TestCaseWithURLToolSetup $this->assertInstanceOf('Thelia\Model\Category', $deletedCategory); $this->assertTrue($deletedCategory->isDeleted()); } + + public function testToggleVisibility() + { + $category = $this->getRandomCategory(); + $expectedVisibility = !$category->getVisible(); + + $event = new CategoryToggleVisibilityEvent($category); + $event->setDispatcher($this->getDispatcher()); + + $action = new Category(); + $action->toggleVisibility($event); + + $updatedCategory = $event->getCategory(); + + $this->assertInstanceOf('Thelia\Model\Category', $updatedCategory); + $this->assertEquals($expectedVisibility, $updatedCategory->getVisible()); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/ConfigTest.php b/core/lib/Thelia/Tests/Action/ConfigTest.php new file mode 100644 index 000000000..cff430894 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/ConfigTest.php @@ -0,0 +1,173 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Config; +use Thelia\Core\Event\Config\ConfigCreateEvent; +use Thelia\Core\Event\Config\ConfigDeleteEvent; +use Thelia\Core\Event\Config\ConfigUpdateEvent; +use Thelia\Model\Config as ConfigModel; +use Thelia\Model\ConfigQuery; + + +/** + * Class ConfigTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class ConfigTest extends \PHPUnit_Framework_TestCase +{ + protected $dispatcher; + + public static function setUpBeforeClass() + { + ConfigQuery::create() + ->filterByName('foo') + ->delete(); + } + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + + public function testCreate() + { + $event = new ConfigCreateEvent(); + + $event + ->setEventName('foo') + ->setValue('bar') + ->setLocale('en_US') + ->setTitle('test config foo bar') + ->setHidden(true) + ->setSecured(true) + ->setDispatcher($this->dispatcher) + ; + + $action = new Config(); + $action->create($event); + + $createdConfig = $event->getConfig(); + + $this->assertInstanceOf('Thelia\Model\Config', $createdConfig); + + $this->assertFalse($createdConfig->isNew()); + + $this->assertEquals('foo', $createdConfig->getName()); + $this->assertEquals('bar', $createdConfig->getValue()); + $this->assertEquals('en_US', $createdConfig->getLocale()); + $this->assertEquals('test config foo bar', $createdConfig->getTitle()); + $this->assertEquals(1, $createdConfig->getHidden()); + $this->assertEquals(1, $createdConfig->getSecured()); + + return $createdConfig; + } + + /** + * @depends testCreate + */ + public function testSetValue(ConfigModel $config) + { + $event = new ConfigUpdateEvent($config->getId()); + $event + ->setValue('baz') + ->setDispatcher($this->dispatcher); + + $action = new Config(); + $action->setValue($event); + + $updatedConfig = $event->getConfig(); + + $this->assertInstanceOf('Thelia\Model\Config', $updatedConfig); + + $this->assertEquals($config->getName(), $updatedConfig->getName()); + $this->assertEquals('baz', $updatedConfig->getValue()); + $this->assertEquals($config->getLocale(), $updatedConfig->getLocale()); + $this->assertEquals($config->getTitle(), $updatedConfig->getTitle()); + $this->assertEquals($config->getHidden(), $updatedConfig->getHidden()); + $this->assertEquals($config->getSecured(), $updatedConfig->getSecured()); + + return $updatedConfig; + } + + /** + * @param ConfigModel $config + * @depends testSetValue + */ + public function testModify(ConfigModel $config) + { + $event = new ConfigUpdateEvent($config->getId()); + $event + ->setEventName('foo') + ->setValue('update baz') + ->setLocale('en_US') + ->setTitle('config title') + ->setDescription('config description') + ->setChapo('config chapo') + ->setPostscriptum('config postscriptum') + ->setHidden(0) + ->setSecured(0) + ->setDispatcher($this->dispatcher) + ; + + $action = new Config(); + $action->modify($event); + + $updatedConfig = $event->getConfig(); + + $this->assertInstanceOf('Thelia\Model\Config', $updatedConfig); + + $this->assertEquals('foo', $updatedConfig->getName()); + $this->assertEquals('update baz', $updatedConfig->getValue()); + $this->assertEquals('en_US', $updatedConfig->getLocale()); + $this->assertEquals('config title', $updatedConfig->getTitle()); + $this->assertEquals('config description', $updatedConfig->getDescription()); + $this->assertEquals('config chapo', $updatedConfig->getChapo()); + $this->assertEquals('config postscriptum', $updatedConfig->getPostscriptum()); + $this->assertEquals(0, $updatedConfig->getHidden()); + $this->assertEquals(0, $updatedConfig->getSecured()); + + return $updatedConfig; + } + + /** + * @param ConfigModel $config + * @depends testModify + */ + public function testDelete(ConfigModel $config) + { + $event = new ConfigDeleteEvent($config->getId()); + $event->setDispatcher($this->dispatcher); + + $action = new Config(); + $action->delete($event); + + $deletedConfig = $event->getConfig(); + + $this->assertInstanceOf('Thelia\Model\Config', $deletedConfig); + $this->assertTrue($deletedConfig->isDeleted()); + } + +} \ No newline at end of file