From c52ec3dbaf62397fc9e5c8258abc6beab78f9144 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 5 Feb 2014 10:47:11 +0100 Subject: [PATCH] create currency test suite --- core/lib/Thelia/Action/Order.php | 4 +- core/lib/Thelia/Tests/Action/CurrencyTest.php | 160 ++++++++++++++++++ .../MatchForTotalAmountTest.php | 3 +- 3 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 core/lib/Thelia/Tests/Action/CurrencyTest.php diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index f7e0afa01..ece908a96 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -40,7 +40,7 @@ use Thelia\Mailer\MailerFactory; use Thelia\Model\AddressQuery; use Thelia\Model\Cart as CartModel; use Thelia\Model\ConfigQuery; -use Thelia\Model\Currency; +use Thelia\Model\Currency as CurrencyModel; use Thelia\Model\Customer as CustomerModel; use Thelia\Model\Lang; use Thelia\Model\Map\OrderTableMap; @@ -149,7 +149,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setOrder($order); } - protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) + protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, Lang $lang, CartModel $cart, CustomerModel $customer) { $con = \Propel\Runtime\Propel::getConnection( OrderTableMap::DATABASE_NAME diff --git a/core/lib/Thelia/Tests/Action/CurrencyTest.php b/core/lib/Thelia/Tests/Action/CurrencyTest.php new file mode 100644 index 000000000..1dad3c982 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CurrencyTest.php @@ -0,0 +1,160 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Currency; +use Thelia\Core\Event\Currency\CurrencyDeleteEvent; +use Thelia\Core\Event\Currency\CurrencyUpdateEvent; +use Thelia\Model\Currency as CurrencyModel; +use Thelia\Core\Event\Currency\CurrencyCreateEvent; +use Thelia\Model\CurrencyQuery; + + +/** + * Class CurrencyTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class CurrencyTest extends \PHPUnit_Framework_TestCase +{ + + protected $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + + public function testCreate() + { + $event = new CurrencyCreateEvent(); + + $event + ->setCurrencyName('test') + ->setCode('AZE') + ->setRate('1.35') + ->setLocale('en_US') + ->setSymbol('ù') + ->setDispatcher($this->dispatcher) + ; + + $action = new Currency(); + $action->create($event); + + $createdCurrency = $event->getCurrency(); + + $this->assertInstanceOf('Thelia\Model\Currency', $createdCurrency); + $this->assertFalse($createdCurrency->isNew()); + + $this->assertEquals('test', $createdCurrency->getName()); + $this->assertEquals('AZE', $createdCurrency->getCode()); + $this->assertEquals('1.35', $createdCurrency->getRate()); + $this->assertEquals('en_US', $createdCurrency->getLocale()); + $this->assertEquals('ù', $createdCurrency->getSymbol()); + + return $createdCurrency; + } + + /** + * @depends testCreate + */ + public function testUpdate(CurrencyModel $currency) + { + $event = new CurrencyUpdateEvent($currency->getId()); + + $event + ->setCurrencyName('test update') + ->setCode('AZER') + ->setRate('2.35') + ->setLocale('en_US') + ->setSymbol('ù') + ->setDispatcher($this->dispatcher) + ; + + $action = new Currency(); + $action->update($event); + + $updatedCurrency = $event->getCurrency(); + + $this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency); + $this->assertEquals('test update', $updatedCurrency->getName()); + $this->assertEquals('AZER', $updatedCurrency->getCode()); + $this->assertEquals('2.35', $updatedCurrency->getRate()); + $this->assertEquals('en_US', $updatedCurrency->getLocale()); + $this->assertEquals('ù', $updatedCurrency->getSymbol()); + + return $updatedCurrency; + } + + /** + * @param CurrencyModel $currency + * @depends testUpdate + */ + public function testSetDefault(CurrencyModel $currency) + { + $event = new CurrencyUpdateEvent($currency->getId()); + $event + ->setIsDefault(1) + ->setDispatcher($this->dispatcher); + + $action = new Currency(); + $action->setDefault($event); + + $updatedCurrency = $event->getCurrency(); + + $this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency); + + $this->assertEquals(1, $updatedCurrency->getByDefault()); + $this->assertEquals(1, CurrencyQuery::create()->filterByByDefault(true)->count()); + + return $updatedCurrency; + } + + /** + * @param CurrencyModel $currency + * @depends testSetDefault + */ + public function testDelete(CurrencyModel $currency) + { + $event = new CurrencyDeleteEvent($currency->getId()); + $event->setDispatcher($this->dispatcher); + + $action = new Currency(); + $action->delete($event); + + $deletedCurrency = $event->getCurrency(); + + $this->assertInstanceOf('Thelia\Model\Currency', $deletedCurrency); + + $this->assertTrue($deletedCurrency->isDeleted()); + } + + public static function tearDownAfterClass() + { + CurrencyQuery::create() + ->addAscendingOrderByColumn('RAND()') + ->limit(1) + ->update(array('ByDefault' => true)); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php index cd6d67364..4f28f32e4 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php @@ -21,10 +21,11 @@ /* */ /**********************************************************************************/ -namespace Thelia\Condition\Implementation; +namespace Thelia\Tests\Condition\Implementation; use Thelia\Condition\ConditionEvaluator; use Thelia\Condition\ConditionFactory; +use Thelia\Condition\Implementation\MatchForTotalAmount; use Thelia\Condition\Operators; use Thelia\Condition\ConditionCollection; use Thelia\Coupon\FacadeInterface;