aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/opencart/system
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
committerJesús <heckyel@hyperbola.info>2019-08-18 21:14:58 -0500
commit2eed7b082f83630301e51f57ca8394de228a8605 (patch)
tree1d19962d22d30f99317d9276e4bae7744fc93fc2 /tests/phpunit/opencart/system
downloadlibrecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz
librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip
first commit
Diffstat (limited to 'tests/phpunit/opencart/system')
-rw-r--r--tests/phpunit/opencart/system/engine/EventTest.php38
-rw-r--r--tests/phpunit/opencart/system/library/CurrencyTest.php59
-rw-r--r--tests/phpunit/opencart/system/library/UrlTest.php36
3 files changed, 133 insertions, 0 deletions
diff --git a/tests/phpunit/opencart/system/engine/EventTest.php b/tests/phpunit/opencart/system/engine/EventTest.php
new file mode 100644
index 0000000..3fb8fb7
--- /dev/null
+++ b/tests/phpunit/opencart/system/engine/EventTest.php
@@ -0,0 +1,38 @@
+<?php
+
+class EventTest extends OpenCartTest {
+ public function testEventOrderedExecution() {
+ $eventMock = $this->getMockBuilder('Event')
+ ->setMethods(array('createAction'))
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $actionMock = $this->getMockBuilder('Action')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $actionMock->expects($this->exactly(3))
+ ->method('execute');
+
+ $eventMock->expects($this->at(0))
+ ->method('createAction')
+ ->with($this->equalTo('SomeExtraAction'), $this->equalTo(array()))
+ ->will($this->returnValue($actionMock));
+
+ $eventMock->expects($this->at(1))
+ ->method('createAction')
+ ->with($this->equalTo('SomeAction'), $this->equalTo(array()))
+ ->will($this->returnValue($actionMock));
+
+ $eventMock->expects($this->at(2))
+ ->method('createAction')
+ ->with($this->equalTo('SomeAnotherAction'), $this->equalTo(array()))
+ ->will($this->returnValue($actionMock));
+
+ $eventMock->register('some.event', 'SomeAction', 10);
+ $eventMock->register('some.event', 'SomeAnotherAction', 1);
+ $eventMock->register('some.event', 'SomeExtraAction', 100);
+
+ $eventMock->trigger('some.event');
+ }
+} \ No newline at end of file
diff --git a/tests/phpunit/opencart/system/library/CurrencyTest.php b/tests/phpunit/opencart/system/library/CurrencyTest.php
new file mode 100644
index 0000000..fbb7352
--- /dev/null
+++ b/tests/phpunit/opencart/system/library/CurrencyTest.php
@@ -0,0 +1,59 @@
+<?php
+class CurrencyTest extends OpenCartTest {
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "currency");
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "currency SET currency_id = '1', title = 'Pound Sterling', code = 'GBP', symbol_left = '£', symbol_right = '', decimal_place = '2', value = '0.61979997', status = '1', date_modified = '2011-07-16 10:30:52'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "currency SET currency_id = '2', title = 'US Dollar', code = 'USD', symbol_left = '$', symbol_right = '', decimal_place = '2', value = '1.00000000', status = '1', date_modified = '2011-07-16 16:55:46'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "currency SET currency_id = '3', title = 'Euro', code = 'EUR', symbol_left = '', symbol_right = '€', decimal_place = '2', value = '0.70660001', status = '1', date_modified = '2011-07-16 10:30:52'");
+ }
+
+ /*
+ public function testCurrencySet() {
+ $this->currency->set('EUR');
+ $this->assertEquals('EUR', $this->session->data['currency']);
+ }
+ */
+
+ public function testCurrencyFormat() {
+ $this->assertEquals('7.06€', $this->currency->format('9.99', 'EUR'));
+ }
+
+ public function testCurrencyConvert() {
+ $value = $this->currency->convert('7.06', 'EUR', 'USD');
+
+ // 9.9915084914872843
+ $this->assertEquals(9.9915, round($value, 4));
+ }
+
+ public function testCurrencyGetId() {
+ $this->assertEquals(3, $this->currency->getId('EUR'));
+ }
+
+ public function testCurrencyGetSymbolLeft() {
+ $this->assertEquals('£', $this->currency->getSymbolLeft('GBP'));
+ }
+
+ public function testCurrencyGetSymbolRight() {
+ $this->assertEquals('€', $this->currency->getSymbolRight('EUR'));
+ }
+
+ public function testCurrencyGetDecimalPlace() {
+ $this->assertEquals(2, $this->currency->getDecimalPlace('GBP'));
+ }
+
+ /*
+ public function testCurrencyGetCode() {
+ $this->currency->set('GBP');
+ $this->assertEquals('GBP', $this->currency->getCode());
+ }
+ */
+
+ public function testCurrencyHas() {
+ $this->assertTrue($this->currency->has('USD'));
+ $this->assertFalse($this->currency->has('AUD'));
+ }
+} \ No newline at end of file
diff --git a/tests/phpunit/opencart/system/library/UrlTest.php b/tests/phpunit/opencart/system/library/UrlTest.php
new file mode 100644
index 0000000..110efe2
--- /dev/null
+++ b/tests/phpunit/opencart/system/library/UrlTest.php
@@ -0,0 +1,36 @@
+<?php
+
+class UrlTest extends OpenCartTest {
+
+ public function testHomeUrl() {
+ $link = $this->url->link('common/home');
+ $this->assertEquals(HTTP_SERVER . 'index.php?route=common/home', $link, "Could not construct homepage's URL");
+ }
+
+ public function testSecureHomeUrl() {
+ $link = $this->url->link('common/home', '', true);
+ $this->assertEquals(HTTPS_SERVER . 'index.php?route=common/home', $link, "Could not construct secure homepage's URL");
+ }
+
+ public function testProductUrl() {
+ $link = $this->url->link('product/product', 'product_id=1');
+ $this->assertEquals(HTTP_SERVER . 'index.php?route=product/product&amp;product_id=1', $link, "Could not construct product's URL");
+ }
+
+ public function testSecureProductUrl() {
+ $link = $this->url->link('product/product', 'product_id=1');
+ $this->assertEquals(HTTPS_SERVER . 'index.php?route=product/product&amp;product_id=1', $link, "Could not construct product's URL");
+ }
+
+ public function testProductUrlRewrite() {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "url_alias` SET query = 'product_id=1', keyword = 'product-1'");
+ $this->config->set('config_seo_url', 1);
+ $urlAction = new Action('common/seo_url');
+ $urlAction->execute($this->registry);
+
+ $link = $this->url->link('product/product', 'product_id=1');
+ $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=1'");
+ $this->assertEquals(HTTPS_SERVER . 'product-1', $link, "Could not construct URL's alias");
+ }
+
+}