test area listener (#198]

This commit is contained in:
Manuel Raynaud
2014-02-03 11:40:12 +01:00
parent 0c87b7606c
commit c18718254c
2 changed files with 97 additions and 0 deletions

View File

@@ -56,6 +56,8 @@ class Area extends BaseAction implements EventSubscriberInterface
public function removeCountry(AreaRemoveCountryEvent $event)
{
if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) {
$event->setArea($country->getArea());
$country->setDispatcher($event->getDispatcher());
$country->setAreaId(null)
->save();

View File

@@ -24,7 +24,13 @@
namespace Thelia\Tests\Action;
use Thelia\Action\Area;
use Thelia\Core\Event\Area\AreaAddCountryEvent;
use Thelia\Core\Event\Area\AreaCreateEvent;
use Thelia\Core\Event\Area\AreaDeleteEvent;
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
use Thelia\Model\Area as AreaModel;
use Thelia\Model\CountryQuery;
/**
@@ -52,6 +58,95 @@ class AreaTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($event->hasArea());
$this->assertEquals('foo', $createdArea->getName());
return $createdArea;
}
/**
* @param AreaModel $area
* @depends testCreate
*/
public function testUpdatePostage(AreaModel $area)
{
$event = new AreaUpdatePostageEvent($area->getId());
$event
->setPostage(20)
->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$areaAction = new Area();
$areaAction->updatePostage($event);
$updatedArea = $event->getArea();
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
$this->assertEquals(20, $updatedArea->getPostage());
return $updatedArea;
}
/**
* @param AreaModel $area
* @depends testUpdatePostage
*/
public function testAddCountry(AreaModel $area)
{
$country = CountryQuery::create()->findOne();
$event = new AreaAddCountryEvent($area->getId(), $country->getId());
$event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$areaAction = new Area();
$areaAction->addCountry($event);
$updatedArea = $event->getArea();
$updatedCountry = CountryQuery::create()->findOneByAreaId($updatedArea->getId());
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
$this->assertEquals($country->getId(), $updatedCountry->getId());
return $updatedArea;
}
/**
* @param AreaModel $area
* @depends testAddCountry
*/
public function testRemoveCountry(AreaModel $area)
{
$country = CountryQuery::create()->filterByArea($area)->find()->getFirst();
$event = new AreaRemoveCountryEvent($area->getId(), $country->getId());
$event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$areaAction = new Area();
$areaAction->removeCountry($event);
$updatedCountry = CountryQuery::create()->findPk($country->getId());
$updatedArea = $event->getArea();
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
$this->assertNull($updatedCountry->getAreaId());
return $event->getArea();
}
/**
* @depends testRemoveCountry
*/
public function testDelete(AreaModel $area)
{
$event = new AreaDeleteEvent($area->getId());
$event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$areaAction = new Area();
$areaAction->delete($event);
$deletedArea = $event->getArea();
$this->assertInstanceOf('Thelia\Model\Area', $deletedArea);
$this->assertTrue($deletedArea->isDeleted());
}
}