test toggle visiblity on category

This commit is contained in:
Manuel Raynaud
2014-02-04 11:23:24 +01:00
parent 67365af88e
commit ba1af80987
2 changed files with 36 additions and 0 deletions

View File

@@ -137,6 +137,8 @@ class Category extends BaseAction implements EventSubscriberInterface
->setVisible($category->getVisible() ? false : true)
->save()
;
$event->setCategory($category);
}
/**

View File

@@ -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());
}
}