From 09f634c195c75ab6fca8a8c078a86447f4df5697 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 4 Feb 2014 14:48:29 +0100 Subject: [PATCH] create country listener test suite --- core/lib/Thelia/Tests/Action/CountryTest.php | 157 +++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/CountryTest.php diff --git a/core/lib/Thelia/Tests/Action/CountryTest.php b/core/lib/Thelia/Tests/Action/CountryTest.php new file mode 100644 index 000000000..b150885a4 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CountryTest.php @@ -0,0 +1,157 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Country; +use Thelia\Core\Event\Country\CountryCreateEvent; +use Thelia\Core\Event\Country\CountryDeleteEvent; +use Thelia\Core\Event\Country\CountryToggleDefaultEvent; +use Thelia\Core\Event\Country\CountryUpdateEvent; +use Thelia\Model\Country as CountryModel; +use Thelia\Model\CountryQuery; + + +/** + * Class CountryTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class CountryTest extends \PHPUnit_Framework_TestCase +{ + + protected $dispatcher; + + public static function setUpBeforeClass() + { + + } + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + + + public function testCreate() + { + $event = new CountryCreateEvent(); + + $event + ->setIsocode('001') + ->setIsoAlpha2('AA') + ->setIsoAlpha3('AAA') + ->setLocale('en_US') + ->setTitle('Test') + ->setDispatcher($this->dispatcher) + ; + + $action = new Country(); + $action->create($event); + + $createdCountry = $event->getCountry(); + + $this->assertInstanceOf('Thelia\Model\Country', $createdCountry); + $this->assertFalse($createdCountry->isNew()); + + $this->assertEquals('001', $createdCountry->getIsocode()); + $this->assertEquals('AA', $createdCountry->getIsoalpha2()); + $this->assertEquals('AAA', $createdCountry->getIsoalpha3()); + $this->assertEquals('en_US', $createdCountry->getLocale()); + $this->assertEquals('Test', $createdCountry->getTitle()); + + return $createdCountry; + } + + /** + * @param CountryModel $country + * @depends testCreate + */ + public function testUpdate(CountryModel $country) + { + $event = new CountryUpdateEvent($country->getId()); + + $event + ->setIsocode('002') + ->setIsoAlpha2('BB') + ->setIsoAlpha3('BBB') + ->setLocale('en_US') + ->setTitle('Test') + ->setDispatcher($this->dispatcher) + ; + + $action = new Country(); + $action->update($event); + + $updatedCountry = $event->getCountry(); + + $this->assertInstanceOf('Thelia\Model\Country', $updatedCountry); + + $this->assertEquals('002', $updatedCountry->getIsocode()); + $this->assertEquals('BB', $updatedCountry->getIsoalpha2()); + $this->assertEquals('BBB', $updatedCountry->getIsoalpha3()); + $this->assertEquals('en_US', $updatedCountry->getLocale()); + $this->assertEquals('Test', $updatedCountry->getTitle()); + + return $updatedCountry; + } + + /** + * @param CountryModel $country + * @depends testUpdate + */ + public function testDelete(CountryModel $country) + { + $event = new CountryDeleteEvent($country->getId()); + $event->setDispatcher($this->dispatcher); + + $action = new Country(); + $action->delete($event); + + $deletedCountry = $event->getCountry(); + + $this->assertInstanceOf('Thelia\Model\Country', $deletedCountry); + $this->assertTrue($deletedCountry->isDeleted()); + } + + public function testToggleDefault() + { + $country = CountryQuery::create() + ->filterByByDefault(0) + ->addAscendingOrderByColumn('RAND()') + ->findOne(); + + $event = new CountryToggleDefaultEvent($country->getId()); + $event->setDispatcher($this->dispatcher); + + $action = new Country(); + $action->toggleDefault($event); + + $updatedCountry = $event->getCountry(); + + $this->assertInstanceOf('Thelia\Model\Country', $updatedCountry); + $this->assertEquals(1, $updatedCountry->getByDefault()); + + $this->assertEquals(1, CountryQuery::create()->filterByByDefault(1)->count()); + } +} \ No newline at end of file