From 38bf62a81b77d3080e713dd2941bd567b3cbf375 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 11 Feb 2014 10:05:46 +0100 Subject: [PATCH] create test suite for FeatureAv object --- .../lib/Thelia/Tests/Action/FeatureAvTest.php | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/FeatureAvTest.php diff --git a/core/lib/Thelia/Tests/Action/FeatureAvTest.php b/core/lib/Thelia/Tests/Action/FeatureAvTest.php new file mode 100644 index 000000000..e2058f89c --- /dev/null +++ b/core/lib/Thelia/Tests/Action/FeatureAvTest.php @@ -0,0 +1,140 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\FeatureAv; +use Thelia\Core\Event\Feature\FeatureAvCreateEvent; +use Thelia\Core\Event\Feature\FeatureAvDeleteEvent; +use Thelia\Core\Event\Feature\FeatureAvUpdateEvent; +use Thelia\Model\FeatureAvQuery; +use Thelia\Model\FeatureAv as FeatureAvModel; + + +/** + * Class FeatureAvTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class FeatureAvTest extends \PHPUnit_Framework_TestCase +{ + protected $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + + /** + * @return \Thelia\Model\Feature + */ + protected function getRandomFeature() + { + $feature = FeatureAvQuery::create() + ->addAscendingOrderByColumn('RAND()') + ->findOne(); + + if (null === $feature) { + $this->fail('use fixtures before launching test, there is no feature in database'); + } + + return $feature; + } + + public function testCreate() + { + $feature = $this->getRandomFeature(); + + $event = new FeatureAvCreateEvent(); + $event + ->setFeatureId($feature->getId()) + ->setLocale('en_US') + ->setTitle('test') + ->setDispatcher($this->dispatcher); + + $action = new FeatureAv(); + $action->create($event); + + $createdFeatureAv = $event->getFeatureAv(); + + $this->assertInstanceOf('Thelia\Model\FeatureAv', $createdFeatureAv); + + $this->assertFalse($createdFeatureAv->isNew()); + + $this->assertEquals('en_US', $createdFeatureAv->getLocale()); + $this->assertEquals('test', $createdFeatureAv->getTitle()); + $this->assertEquals($feature->getId(), $createdFeatureAv->getFeatureId()); + + return $createdFeatureAv; + } + + /** + * @param FeatureAvModel $featureAv + * @depends testCreate + */ + public function testUpdate(FeatureAvModel $featureAv) + { + $event = new FeatureAvUpdateEvent($featureAv->getId()); + $event + ->setLocale('en_uS') + ->setTitle('test update') + ->setDescription('test description') + ->setChapo('test chapo') + ->setPostscriptum('test postscriptum') + ->setDispatcher($this->dispatcher); + + $action = new FeatureAv(); + $action->update($event); + + $updatedFeatureAv = $event->getFeatureAv(); + + $this->assertInstanceOf('Thelia\Model\FeatureAv', $updatedFeatureAv); + + $this->assertEquals('en_US', $updatedFeatureAv->getLocale()); + $this->assertEquals('test update', $updatedFeatureAv->getTitle()); + $this->assertEquals('test chapo', $updatedFeatureAv->getChapo()); + $this->assertEquals('test description', $updatedFeatureAv->getDescription()); + $this->assertEquals('test postscriptum', $updatedFeatureAv->getPostscriptum()); + + return $updatedFeatureAv; + } + + /** + * @param FeatureAvModel $featureAv + * @depends testUpdate + */ + public function testDelete(FeatureAvModel $featureAv) + { + $event = new FeatureAvDeleteEvent($featureAv->getId()); + $event->setDispatcher($this->dispatcher); + + $action = new FeatureAv(); + $action->delete($event); + + $deletedFeatureAv = $event->getFeatureAv(); + + $this->assertInstanceOf('Thelia\Model\FeatureAv', $deletedFeatureAv); + + $this->assertTrue($deletedFeatureAv->isDeleted()); + } +} \ No newline at end of file