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 c33bd66ac..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,22 @@ use Thelia\Tools\URL; class CategoryTest extends TestCaseWithURLToolSetup { + /** + * @return \Thelia\Model\Category + */ + protected function getRandomCategory() + { + $category = CategoryQuery::create() + ->addAscendingOrderByColumn('RAND()') + ->findOne(); + + if (null === $category) { + $this->fail('use fixtures before launching test, there is no category in database'); + } + + return $category; + } + public function testCreate() { $event = new CategoryCreateEvent(); @@ -128,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