aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/bootstrap-dist.php33
-rw-r--r--tests/phpunit/composer.json11
-rw-r--r--tests/phpunit/opencart/admin/controller/extension/ModificationTest.php15
-rw-r--r--tests/phpunit/opencart/catalog/controller/checkout/CartTest.php22
-rw-r--r--tests/phpunit/opencart/catalog/model/account/ActivityTest.php36
-rw-r--r--tests/phpunit/opencart/catalog/model/account/AddressTest.php208
-rw-r--r--tests/phpunit/opencart/catalog/model/account/CustomerGroupTest.php21
-rw-r--r--tests/phpunit/opencart/catalog/model/account/CustomerTest.php173
-rw-r--r--tests/phpunit/opencart/catalog/model/account/DownloadTest.php191
-rw-r--r--tests/phpunit/opencart/catalog/model/account/OrderTest.php258
-rw-r--r--tests/phpunit/opencart/catalog/model/catalog/CategoryTest.php27
-rw-r--r--tests/phpunit/opencart/catalog/model/catalog/InformationTest.php33
-rw-r--r--tests/phpunit/opencart/catalog/model/catalog/ManufacturerTest.php35
-rw-r--r--tests/phpunit/opencart/catalog/model/catalog/ProductTest.php76
-rw-r--r--tests/phpunit/opencart/catalog/model/catalog/ReviewTest.php74
-rw-r--r--tests/phpunit/opencart/catalog/model/checkout/OrderTest.php204
-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
-rw-r--r--tests/phpunit/selenium/catalog/AccountTest.php320
-rw-r--r--tests/phpunit/selenium/catalog/CategoryTest.php39
-rw-r--r--tests/phpunit/selenium/catalog/CheckoutTest.php64
-rw-r--r--tests/phpunit/selenium/catalog/PayPalExpressTest.php173
-rw-r--r--tests/phpunit/selenium/catalog/ProductTest.php79
-rw-r--r--tests/phpunit/selenium/catalog/SagePayDirectTest.php153
-rw-r--r--tests/phpunit/selenium/openbay/SetupTest.php91
26 files changed, 2469 insertions, 0 deletions
diff --git a/tests/phpunit/bootstrap-dist.php b/tests/phpunit/bootstrap-dist.php
new file mode 100644
index 0000000..5452163
--- /dev/null
+++ b/tests/phpunit/bootstrap-dist.php
@@ -0,0 +1,33 @@
+<?php
+define('VERSION', '2.3.0.3_rc');
+
+define('ADMIN_USERNAME', '');
+define('ADMIN_PASSWORD', '');
+
+define('CONFIG_ADMIN', __DIR__ . '/../../upload/admin/config.php');
+define('CONFIG_CATALOG', __DIR__ . '/../../upload/config.php');
+define('SQL_FILE', __DIR__ . '/../../upload/install/opencart.sql');
+
+// Settings for Amazon Payments' Selenium tests
+define('AMAZON_PAYMENTS_SELLER_ID', '');
+define('AMAZON_PAYMENTS_ACCESS_KEY', '');
+define('AMAZON_PAYMENTS_ACCESS_SECRET', '');
+define('AMAZON_PAYMENTS_COUNTRY', '');
+define('AMAZON_PAYMENTS_USERNAME', '');
+define('AMAZON_PAYMENTS_PASSWORD', '');
+define('AMAZON_PAYMENTS_ADDRESS_POSITION', 1);
+define('AMAZON_PAYMENTS_CARDS_POSITION', 1);
+
+// Settings for PayPal Express Checkout's Selenium tests
+define('PP_EXPRESS_API_USERNAME', '');
+define('PP_EXPRESS_API_PASSWORD', '');
+define('PP_EXPRESS_API_SIGNATURE', '');
+define('PP_EXPRESS_USERNAME', '');
+define('PP_EXPRESS_PASSWORD', '');
+
+// Settings for SagePay Direct's selenium tests
+define('SAGEPAY_DIRECT_VENDOR', '');
+
+// Settings for OpenBay Pro
+define('OPENBAY_EBAY_TOKEN', '');
+define('OPENBAY_EBAY_SECRET', '');
diff --git a/tests/phpunit/composer.json b/tests/phpunit/composer.json
new file mode 100644
index 0000000..e4a3aaa
--- /dev/null
+++ b/tests/phpunit/composer.json
@@ -0,0 +1,11 @@
+{
+ "repositories": [
+ {
+ "type": "vcs",
+ "url": "https://github.com/openbaypro/opencart-test-suite.git"
+ }
+ ],
+ "require": {
+ "openbaypro/opencart-test-suite": "dev-master"
+ }
+} \ No newline at end of file
diff --git a/tests/phpunit/opencart/admin/controller/extension/ModificationTest.php b/tests/phpunit/opencart/admin/controller/extension/ModificationTest.php
new file mode 100644
index 0000000..d4d0221
--- /dev/null
+++ b/tests/phpunit/opencart/admin/controller/extension/ModificationTest.php
@@ -0,0 +1,15 @@
+<?php
+
+class AdminControllerExtensionModificationTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ }
+
+ public function testIndex() {
+ $this->request->server['REQUEST_METHOD'] = 'GET';
+ $out = $this->dispatchAction("extension/modification")->getOutput();
+ }
+} \ No newline at end of file
diff --git a/tests/phpunit/opencart/catalog/controller/checkout/CartTest.php b/tests/phpunit/opencart/catalog/controller/checkout/CartTest.php
new file mode 100644
index 0000000..5db180d
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/controller/checkout/CartTest.php
@@ -0,0 +1,22 @@
+<?php
+
+class CatalogControllerCheckoutCartTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->cart->clear();
+ }
+
+ public function testAddProduct() {
+ $this->request->post['product_id'] = 28;
+ $this->request->post['quantity'] = 1;
+
+ $response = json_decode($this->dispatchAction("checkout/cart/add")->getOutput(), true);
+
+ $this->assertTrue(!empty($response['success']) && !empty($response['total']));
+ $this->assertEquals(1, preg_match('/HTC Touch HD/', $response['success']));
+ $this->assertEquals(1, preg_match('/122\.00/', $response['total']));
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/ActivityTest.php b/tests/phpunit/opencart/catalog/model/account/ActivityTest.php
new file mode 100644
index 0000000..9c8b665
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/ActivityTest.php
@@ -0,0 +1,36 @@
+<?php
+
+class CatalogModelAccountActivityTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('account/activity');
+
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_activity");
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_activity");
+ }
+
+ public function testAddActivity() {
+ $key = 'key';
+ $data = array(
+ 'customer_id' => 0,
+ );
+
+ $this->request->server['REMOTE_ADDR'] = '127.0.0.1';
+
+ $this->model_account_activity->addActivity($key, $data);
+
+ $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_activity")->row;
+
+ $this->assertEquals($key, $result['key']);
+ $this->assertEquals($data, unserialize($result['data']));
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/AddressTest.php b/tests/phpunit/opencart/catalog/model/account/AddressTest.php
new file mode 100644
index 0000000..e012ee3
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/AddressTest.php
@@ -0,0 +1,208 @@
+<?php
+
+class CatalogModelAccountAddressTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('account/address');
+ $this->customerLogout();
+ $this->emptyTables();
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET customer_id = 1, email = 'customer@localhost', `status` = 1, customer_group_id = 1, date_added = '1970-01-01 00:00:00', ip = '127.0.0.1'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET ip = '127.0.0.1', customer_id = 1");
+
+ $this->customerLogin('customer@localhost', '', true);
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->emptyTables();
+ $this->customerLogout();
+ }
+
+ private function emptyTables() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ban_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "address");
+ }
+
+ public function testAddAddress() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ $addressId = $this->model_account_address->addAddress($address);
+
+ $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "address")->row;
+
+ foreach ($address as $key => $value) {
+ $this->assertEquals($value, $address[$key]);
+ }
+
+ $customer = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = 1")->row;
+ $this->assertEquals($addressId, $customer['address_id']);
+
+ $address['default'] = false;
+
+ $this->model_account_address->addAddress($address);
+ $customer = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = 1")->row;
+ $this->assertEquals($addressId, $customer['address_id'], 'Changed default address unnecessarily');
+ }
+
+ public function testEditAddress() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ $addressId = $this->model_account_address->addAddress($address);
+
+ $address = array(
+ 'firstname' => 'firstname',
+ 'lastname' => 'lastname',
+ 'company' => 'company',
+ 'address_1' => 'address_1',
+ 'address_2' => 'address_2',
+ 'postcode' => 'postcode',
+ 'city' => 'city',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ $this->model_account_address->editAddress($addressId, $address);
+
+ $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "address")->row;
+
+ foreach ($address as $key => $value) {
+ $this->assertEquals($value, $address[$key]);
+ }
+
+ $addressId = $this->model_account_address->addAddress($address);
+ $address['default'] = false;
+ $this->model_account_address->editAddress($addressId, $address);
+ $customer = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = 1")->row;
+ $this->assertEquals($addressId, $customer['address_id'], 'Changed default address unnecessarily');
+ }
+
+ public function testDeleteAddress() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ $addressId = $this->model_account_address->addAddress($address);
+
+ $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "address")->row;
+ $this->assertNotEmpty($result);
+
+ $this->model_account_address->deleteAddress($addressId);
+
+ $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "address")->row;
+ $this->assertEmpty($result);
+ }
+
+ public function testGetAddress() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ $addressId = $this->model_account_address->addAddress($address);
+
+ $address = $this->model_account_address->getAddress($addressId);
+ $this->assertNotFalse($address);
+
+ $address = $this->model_account_address->getAddress(0);
+ $this->assertFalse($address);
+ }
+
+ public function testGetAddresses() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->model_account_address->addAddress($address);
+ }
+
+ $addresses = $this->model_account_address->getAddresses();
+ $this->assertCount(5, $addresses);
+ }
+
+ public function testGetTotalAddresses() {
+ $address = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'postcode' => '',
+ 'city' => '',
+ 'zone_id' => 0,
+ 'country_id' => 0,
+ 'custom_data' => array(),
+ 'default' => true,
+ );
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->model_account_address->addAddress($address);
+ }
+
+ $addressCount = $this->model_account_address->getTotalAddresses();
+ $this->assertEquals(5, $addressCount);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/CustomerGroupTest.php b/tests/phpunit/opencart/catalog/model/account/CustomerGroupTest.php
new file mode 100644
index 0000000..38a6c41
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/CustomerGroupTest.php
@@ -0,0 +1,21 @@
+<?php
+
+class CatalogModelAccountCustomerGroupTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('account/customer_group');
+ }
+
+ public function testGetCustomerGroup() {
+ $result = $this->model_account_customer_group->getCustomerGroup(1);
+ $this->assertNotEmpty($result);
+ }
+
+ public function testGetCustomerGroups() {
+ $result = $this->model_account_customer_group->getCustomerGroups();
+ $this->assertCount(1, $result);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/CustomerTest.php b/tests/phpunit/opencart/catalog/model/account/CustomerTest.php
new file mode 100644
index 0000000..3a7ca42
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/CustomerTest.php
@@ -0,0 +1,173 @@
+<?php
+
+class CatalogModelAccountCustomerTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('account/customer');
+ $this->customerLogout();
+ $this->emptyTables();
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET customer_id = 1, email = 'customer@localhost', `status` = 1, customer_group_id = 1, date_added = '1970-01-01 00:00:00', ip = '127.0.0.1'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET ip = '127.0.0.1', customer_id = 1");
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->emptyTables();
+ $this->customerLogout();
+ }
+
+ private function emptyTables() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ban_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "address");
+ }
+
+
+
+ public function testEditCustomer() {
+ $this->customerLogin('customer@localhost', '', true);
+
+ $customerData = array(
+ 'firstname' => 'firstname',
+ 'lastname' => 'lastname',
+ 'email' => 'email',
+ 'telephone' => 'telephone',
+ 'fax' => 'fax',
+ 'custom_field' => array(),
+ );
+
+ $this->model_account_customer->editCustomer($customerData);
+ $customer = $this->model_account_customer->getCustomer(1);
+
+ $customerData['custom_field'] = serialize(array());
+
+ foreach ($customerData as $key => $value) {
+ $this->assertEquals($value, $customer[$key]);
+ }
+ }
+
+ public function testEditPassword() {
+ $this->model_account_customer->editPassword('customer@localhost', 'password');
+
+ $row = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = 1")->row;
+
+ $this->assertNotEmpty($row['password']);
+ $this->assertNotEmpty($row['salt']);
+ }
+
+ public function testEditNewsletter() {
+ $this->customerLogin('customer@localhost', '', true);
+
+ $this->model_account_customer->editNewsletter(1);
+
+ $row = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = 1")->row;
+
+ $this->assertEquals(1, $row['newsletter']);
+ }
+
+ public function testGetCustomer() {
+ $customer = $this->model_account_customer->getCustomer(1);
+
+ $this->assertNotEmpty($customer);
+ }
+
+ public function testGetCustomerByEmail() {
+ $customer = $this->model_account_customer->getCustomerByEmail('customer@localhost');
+
+ $this->assertNotEmpty($customer);
+ }
+
+ public function testGetCustomerByToken() {
+ $this->db->query("UPDATE " . DB_PREFIX . "customer SET token = 'token'");
+
+ $customer = $this->model_account_customer->getCustomerByToken('token');
+
+ $this->assertNotEmpty($customer);
+ }
+
+ /*
+ public function testGetCustomers() {
+ $data = array(
+ 'filter_name' => '',
+ 'filter_email' => 'customer@localhost',
+ 'filter_customer_group_id' => '1',
+ 'filter_status' => 1,
+ 'filter_approved' => 0,
+ 'filter_ip' => '127.0.0.1',
+ 'filter_date' => '1970-01-01',
+ 'sort' => 'c.email',
+ );
+
+ $customers = $this->model_account_customer->getCustomers($data);
+
+ $this->assertCount(1, $customers);
+ }
+ */
+
+ public function testGetTotalCustomersByEmail() {
+ $count = $this->model_account_customer->getTotalCustomersByEmail('customer@localhost');
+
+ $this->assertEquals(1, $count);
+ }
+
+ public function testGetIps() {
+ $ips = $this->model_account_customer->getIps(1);
+
+ $this->assertCount(1, $ips);
+ }
+
+ public function testIsBanIp() {
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer_ban_ip SET ip = '255.255.255.255'");
+
+ $bannedIp = $this->model_account_customer->isBanIp('255.255.255.255');
+ $this->assertTrue($bannedIp == true);
+
+ $bannedIp = $this->model_account_customer->isBanIp('0.0.0.0');
+ $this->assertFalse($bannedIp == true);
+ }
+
+ // Cannot run this test as the model instantiates Mail class which generates an error
+ // because it can't send a confirmation email. Need to refactor the code, so the Mail
+ // class could be substituted with a mock object.
+ /*
+ public function testAddCustomer() {
+ $customerData = array(
+ 'firstname' => '',
+ 'lastname' => '',
+ 'email' => '',
+ 'telephone' => '',
+ 'fax' => '',
+ 'custom_field' => array(
+ 'account' => array(),
+ ),
+ 'password' => 'password123',
+ 'newsletter' => 0,
+ 'approved' => 1,
+ 'company' => '',
+ 'address_1' => '',
+ 'address_2' => '',
+ 'city' => '',
+ 'postcode' => '',
+ 'country_id' => 0,
+ 'zone_id' => 0,
+ 'custom_field' => array(
+ 'address' => array(),
+ ),
+ );
+
+ $this->request->server['REMOTE_ADDR'] = '127.0.0.1';
+ $this->config->set('config_account_mail', false);
+ $this->config->set('config_mail', array());
+
+ $customerId = $this->model_account_customer->addCustomer($customerData);
+ }
+ */
+
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/DownloadTest.php b/tests/phpunit/opencart/catalog/model/account/DownloadTest.php
new file mode 100644
index 0000000..d3e34c0
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/DownloadTest.php
@@ -0,0 +1,191 @@
+<?php
+
+class CatalogModelAccountDownloadTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('checkout/order');
+ $this->loadModelByRoute('account/custom_field');
+ $this->loadModelByRoute('account/download');
+
+ $this->customerLogout();
+ $this->emptyTables();
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET customer_id = 1, email = 'customer@localhost', `status` = 1, customer_group_id = 1, date_added = '1970-01-01 00:00:00', ip = '127.0.0.1'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET ip = '127.0.0.1', customer_id = 1");
+
+ $this->customerLogin('customer@localhost', '', true);
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->addDummyOrder();
+ }
+
+ $this->db->query("INSERT INTO ". DB_PREFIX . "download SET filename = '', mask = '', date_added = '1970-01-01 00:00:00'");
+ $downloadId = $this->db->getLastId();
+ $this->db->query("INSERT INTO " . DB_PREFIX . "download_description SET download_id = $downloadId, language_id = 1, `name` = ''");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = 1, download_id = $downloadId");
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->emptyTables();
+ $this->customerLogout();
+ }
+
+ private function emptyTables() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ban_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "address");
+
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_custom_field");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_fraud");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_history");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_option");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_product");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring_transaction");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_total");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "download");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "download_description");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download");
+ }
+
+ private function addDummyOrder() {
+ $order = array(
+ 'invoice_prefix' => '',
+ 'store_id' => 0,
+ 'store_url' => '',
+ 'store_name' => '',
+ 'customer_id' => $this->customer->getId(),
+ 'customer_group_id' => 0,
+ 'firstname' => '',
+ 'lastname' => '',
+ 'email' => '',
+ 'telephone' => '',
+ 'fax' => '',
+ 'custom_field' => array(),
+ 'payment_firstname' => '',
+ 'payment_lastname' => '',
+ 'payment_company' => '',
+ 'payment_address_1' => '',
+ 'payment_address_2' => '',
+ 'payment_city' => '',
+ 'payment_postcode' => '',
+ 'payment_zone' => '',
+ 'payment_zone_id' => 0,
+ 'payment_country' => '',
+ 'payment_country_id' => 0,
+ 'payment_address_format' => '',
+ 'payment_custom_field' => array(),
+ 'payment_method' => '',
+ 'payment_code' => '',
+ 'shipping_firstname' => '',
+ 'shipping_lastname' => '',
+ 'shipping_company' => '',
+ 'shipping_address_1' => '',
+ 'shipping_address_2' => '',
+ 'shipping_city' => '',
+ 'shipping_postcode' => '',
+ 'shipping_zone' => '',
+ 'shipping_zone_id' => 0,
+ 'shipping_country' => '',
+ 'shipping_country_id' => 0,
+ 'shipping_address_format' => '',
+ 'shipping_custom_field' => array(),
+ 'shipping_method' => '',
+ 'shipping_code' => '',
+ 'products' => array(
+ array(
+ 'product_id' => 1,
+ 'name' => '',
+ 'model' => '',
+ 'quantity' => 0,
+ 'price' => 0.00,
+ 'total' => 0.00,
+ 'tax' => 0.00,
+ 'reward' => 0.00,
+ 'option' => array(
+ array(
+ 'product_option_id' => 0,
+ 'product_option_value_id' => 0,
+ 'name' => '',
+ 'value' => '',
+ 'type' => '',
+ ),
+ )
+ ),
+ ),
+ 'vouchers' => array(
+ array(
+ 'description' => '',
+ 'code' => '',
+ 'from_name' => '',
+ 'from_email' => '',
+ 'to_name' => '',
+ 'to_email' => '',
+ 'voucher_theme_id' => 0,
+ 'message' => '',
+ 'amount' => 0.00,
+ ),
+ ),
+ 'comment' => '',
+ 'total' => '',
+ 'affiliate_id' => 0,
+ 'commission' => 0,
+ 'marketing_id' => 0,
+ 'tracking' => '',
+ 'language_id' => 0,
+ 'currency_id' => 0,
+ 'currency_code' => '',
+ 'currency_value' => 0,
+ 'ip' => '',
+ 'forwarded_ip' => '',
+ 'user_agent' => '',
+ 'accept_language' => '',
+ 'totals' => array(
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ ),
+ );
+
+ $order_id = $this->model_checkout_order->addOrder($order);
+ $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = " . (int)$this->config->get('config_complete_status_id') . " WHERE order_id = " . (int)$order_id);
+ }
+
+ public function testGetDownload() {
+ $downloadId = $this->db->query("SELECT download_id FROM `". DB_PREFIX . "download` ORDER BY download_id ASC LIMIT 1")->row['download_id'];
+
+ $download = $this->model_account_download->getDownload($downloadId);
+
+ $this->assertNotEmpty($download);
+ }
+
+ public function testGetDownloads() {
+ $downloads = $this->model_account_download->getDownloads();
+
+ $this->assertCount(5, $downloads);
+ }
+
+ public function testGetTotalDownloads() {
+ $downloads = $this->model_account_download->getTotalDownloads();
+
+ $this->assertEquals(5, $downloads);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/account/OrderTest.php b/tests/phpunit/opencart/catalog/model/account/OrderTest.php
new file mode 100644
index 0000000..ef260cc
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/account/OrderTest.php
@@ -0,0 +1,258 @@
+<?php
+
+class CatalogModelAccountOrderTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('account/order');
+ $this->loadModelByRoute('account/custom_field');
+ $this->loadModelByRoute('checkout/order');
+
+ $this->customerLogout();
+ $this->emptyTables();
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET customer_id = 1, email = 'customer@localhost', `status` = 1, customer_group_id = 1, date_added = '1970-01-01 00:00:00', ip = '127.0.0.1'");
+ $this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET ip = '127.0.0.1', customer_id = 1");
+
+ $this->customerLogin('customer@localhost', '', true);
+
+ $this->addDummyOrder();
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->emptyTables();
+ $this->customerLogout();
+ }
+
+ private function emptyTables() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ban_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "address");
+
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_custom_field");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_fraud");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_history");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_option");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_product");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring_transaction");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_total");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher");
+ }
+
+ private function addDummyOrder() {
+ $order = array(
+ 'invoice_prefix' => '',
+ 'store_id' => 0,
+ 'store_url' => '',
+ 'store_name' => '',
+ 'customer_id' => $this->customer->getId(),
+ 'customer_group_id' => 0,
+ 'firstname' => '',
+ 'lastname' => '',
+ 'email' => '',
+ 'telephone' => '',
+ 'fax' => '',
+ 'custom_field' => array(),
+ 'payment_firstname' => '',
+ 'payment_lastname' => '',
+ 'payment_company' => '',
+ 'payment_address_1' => '',
+ 'payment_address_2' => '',
+ 'payment_city' => '',
+ 'payment_postcode' => '',
+ 'payment_zone' => '',
+ 'payment_zone_id' => 0,
+ 'payment_country' => '',
+ 'payment_country_id' => 0,
+ 'payment_address_format' => '',
+ 'payment_custom_field' => array(),
+ 'payment_method' => '',
+ 'payment_code' => '',
+ 'shipping_firstname' => '',
+ 'shipping_lastname' => '',
+ 'shipping_company' => '',
+ 'shipping_address_1' => '',
+ 'shipping_address_2' => '',
+ 'shipping_city' => '',
+ 'shipping_postcode' => '',
+ 'shipping_zone' => '',
+ 'shipping_zone_id' => 0,
+ 'shipping_country' => '',
+ 'shipping_country_id' => 0,
+ 'shipping_address_format' => '',
+ 'shipping_custom_field' => array(),
+ 'shipping_method' => '',
+ 'shipping_code' => '',
+ 'products' => array(
+ array(
+ 'product_id' => 0,
+ 'name' => '',
+ 'model' => '',
+ 'quantity' => 0,
+ 'price' => 0.00,
+ 'total' => 0.00,
+ 'tax' => 0.00,
+ 'reward' => 0.00,
+ 'option' => array(
+ array(
+ 'product_option_id' => 0,
+ 'product_option_value_id' => 0,
+ 'name' => '',
+ 'value' => '',
+ 'type' => '',
+ ),
+ )
+ ),
+ ),
+ 'vouchers' => array(
+ array(
+ 'description' => '',
+ 'code' => '',
+ 'from_name' => '',
+ 'from_email' => '',
+ 'to_name' => '',
+ 'to_email' => '',
+ 'voucher_theme_id' => 0,
+ 'message' => '',
+ 'amount' => 0.00,
+ ),
+ ),
+ 'comment' => '',
+ 'total' => '',
+ 'affiliate_id' => 0,
+ 'commission' => 0,
+ 'marketing_id' => 0,
+ 'tracking' => '',
+ 'language_id' => 0,
+ 'currency_id' => 0,
+ 'currency_code' => '',
+ 'currency_value' => 0,
+ 'ip' => '',
+ 'forwarded_ip' => '',
+ 'user_agent' => '',
+ 'accept_language' => '',
+ 'totals' => array(
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ ),
+ );
+
+ $orderId = $this->model_checkout_order->addOrder($order);
+ $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = 1 WHERE order_id = $orderId");
+ }
+
+ public function testGetOrder() {
+ $result = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order`")->row;
+
+ $order = $this->model_account_order->getOrder($result['order_id']);
+ $this->assertNotEmpty($order);
+
+ $order = $this->model_account_order->getOrder(0);
+ $this->assertFalse($order);
+ }
+
+ public function testGetOrders() {
+ for ($i = 0; $i < 5; $i++) {
+ $this->addDummyOrder();
+ }
+
+ $orders = $this->model_account_order->getOrders();
+ $this->assertCount(6, $orders);
+ }
+
+ public function testGetOrderProducts() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $products = $this->model_account_order->getOrderProducts($orderId);
+ $this->assertCount(1, $products);
+ }
+
+ public function testGetOrderProduct() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $products = $this->model_account_order->getOrderProducts($orderId);
+ $this->assertCount(1, $products);
+
+ $product = $this->model_account_order->getOrderProduct($orderId, $products[0]['order_product_id']);
+ $this->assertNotEmpty($product);
+ }
+
+ public function testGetOrderOptions() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $products = $this->model_account_order->getOrderProducts($orderId);
+ $this->assertCount(1, $products);
+
+ $product = $this->model_account_order->getOrderProduct($orderId, $products[0]['order_product_id']);
+ $this->assertNotEmpty($product);
+
+ $options = $this->model_account_order->getOrderOptions($orderId, $product['order_product_id']);
+ $this->assertNotEmpty($options);
+ }
+
+ public function testGetOrderVouchers() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $vouchers = $this->model_account_order->getOrderVouchers($orderId);
+ $this->assertCount(1, $vouchers);
+ }
+
+ public function testGetOrderTotals() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $totals = $this->model_account_order->getOrderTotals($orderId);
+ $this->assertCount(2, $totals);
+ }
+
+ public function testGetOrderHistories() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->db->query("INSERT INTO `" . DB_PREFIX . "order_history` SET order_id = $orderId, order_status_id = 1, notify = 1, comment = '', date_added = '1970-01-01 00:00:00'");
+ }
+
+ $histories = $this->model_account_order->getOrderHistories($orderId);
+
+ $this->assertCount(5, $histories);
+ }
+
+ public function testGetTotalOrders() {
+ $total = $this->model_account_order->getTotalOrders();
+
+ $this->assertEquals(1, $total);
+ }
+
+ public function testGetTotalOrderProductsByOrderId() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $total = $this->model_account_order->getTotalOrderProductsByOrderId($orderId);
+
+ $this->assertEquals(1, $total);
+ }
+
+ public function testGetTotalOrderVouchersByOrderId() {
+ $orderId = $this->db->query("SELECT order_id FROM `". DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $total = $this->model_account_order->getTotalOrderVouchersByOrderId($orderId);
+
+ $this->assertEquals(1, $total);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/catalog/CategoryTest.php b/tests/phpunit/opencart/catalog/model/catalog/CategoryTest.php
new file mode 100644
index 0000000..f3f7f55
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/catalog/CategoryTest.php
@@ -0,0 +1,27 @@
+<?php
+
+class CatalogModelCataloCategoryTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('catalog/category');
+ }
+
+ public function testGetCategory() {
+ $category = $this->model_catalog_category->getCategory(25);
+ $this->assertEquals($category['category_id'], 25);
+
+ $category = $this->model_catalog_category->getCategory(0);
+ $this->assertEmpty($category);
+ }
+
+ public function testGetCategories() {
+ $categories = $this->model_catalog_category->getCategories(0);
+ $this->assertCount(8, $categories);
+
+ $categories = $this->model_catalog_category->getCategories(20);
+ $this->assertCount(2, $categories);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/catalog/InformationTest.php b/tests/phpunit/opencart/catalog/model/catalog/InformationTest.php
new file mode 100644
index 0000000..740b757
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/catalog/InformationTest.php
@@ -0,0 +1,33 @@
+<?php
+
+class CatalogModelCatalogInformationTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('catalog/information');
+ }
+
+ public function testGetInformation() {
+ $information = $this->model_catalog_information->getInformation(3);
+ $this->assertNotEmpty($information);
+ }
+
+ public function testGetInformations() {
+ $information = $this->model_catalog_information->getInformations();
+
+ $this->assertNotEmpty($information);
+ }
+
+ public function testGetInformationLayoutId() {
+ $information = $this->model_catalog_information->getInformationLayoutId(0);
+ $this->assertEmpty($information);
+
+ $this->db->query("INSERT INTO " . DB_PREFIX . "information_to_layout SET information_id = 3, layout_id = 1");
+ $layoutId = $this->model_catalog_information->getInformationLayoutId(3);
+ $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout");
+ $this->assertEquals(1, $layoutId);
+ }
+
+}
diff --git a/tests/phpunit/opencart/catalog/model/catalog/ManufacturerTest.php b/tests/phpunit/opencart/catalog/model/catalog/ManufacturerTest.php
new file mode 100644
index 0000000..7254c9c
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/catalog/ManufacturerTest.php
@@ -0,0 +1,35 @@
+<?php
+
+class CatalogModelCataloManufacturerTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('catalog/manufacturer');
+ }
+
+ public function testGetManufacturer() {
+ $manufacturer = $this->model_catalog_manufacturer->getManufacturer(5);
+ $this->assertNotEmpty($manufacturer);
+
+ $manufacturer = $this->model_catalog_manufacturer->getManufacturer(0);
+ $this->assertEmpty($manufacturer);
+ }
+
+ public function testGetManufacturers() {
+ $filters = array(
+ 'sort' => 'name',
+ );
+
+ $manufacturers = $this->model_catalog_manufacturer->getManufacturers($filters);
+ $manufacturerIds = array(8, 9, 7, 5, 6, 10);
+ $actualManufacturerIds = array();
+
+ foreach ($manufacturers as $manufacturer) {
+ $actualManufacturerIds[] = $manufacturer['manufacturer_id'];
+ }
+
+ $this->assertEquals($manufacturerIds, $actualManufacturerIds);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/catalog/ProductTest.php b/tests/phpunit/opencart/catalog/model/catalog/ProductTest.php
new file mode 100644
index 0000000..26ea9aa
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/catalog/ProductTest.php
@@ -0,0 +1,76 @@
+<?php
+
+class CatalogModelCatalogProductTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('catalog/product');
+ }
+
+ public function testGetProduct() {
+ $product = array(
+ 'product_id' => 28,
+ 'name' => 'HTC Touch HD',
+ 'model' => 'Product 1',
+ 'quantity' => 939,
+ 'stock_status' => 'In Stock',
+ 'image' => 'catalog/demo/htc_touch_hd_1.jpg',
+ 'manufacturer_id' => 5,
+ 'manufacturer' => 'HTC',
+ 'price' => '100.00',
+ );
+
+ $result = $this->model_catalog_product->getProduct($product['product_id']);
+
+ $this->assertNotFalse($result, 'Could not retrieve product');
+
+ foreach ($product as $key => $value) {
+ $this->assertEquals($product[$key], $result[$key]);
+ }
+ }
+
+ public function testNoProduct() {
+ $result = $this->model_catalog_product->getProduct(0);
+
+ $this->assertFalse($result);
+ }
+
+ public function testAvailableDate() {
+ $product = $this->model_catalog_product->getProduct(28);
+
+ $this->db->query("UPDATE " . DB_PREFIX . "product SET date_available = '9999-12-30' WHERE product_id = 28");
+
+ $result = $this->model_catalog_product->getProduct(28);
+
+ $this->db->query("UPDATE " . DB_PREFIX . "product SET date_available = '" . $product['date_available'] . "' WHERE product_id = 28");
+
+ $this->assertFalse($result);
+ }
+
+ public function testProductViewed() {
+ $product = $this->model_catalog_product->getProduct(28);
+ $this->model_catalog_product->updateViewed($product['product_id']);
+
+ $product2 = $this->model_catalog_product->getProduct(28);
+
+ $this->assertEquals($product['viewed'] + 1, $product2['viewed']);
+ }
+
+ public function testGetProducts() {
+ $filters = array(
+ 'filter_name' => 'a',
+ 'start' => 0,
+ 'limit' => 5,
+ 'sort' => 'p.date_added'
+ );
+
+ $products = $this->model_catalog_product->getProducts($filters);
+
+ $productIds = array(29, 30, 33, 36, 41,);
+
+ $this->assertTrue($productIds === array_keys($products), 'Could not retrieve products');
+ }
+
+}
diff --git a/tests/phpunit/opencart/catalog/model/catalog/ReviewTest.php b/tests/phpunit/opencart/catalog/model/catalog/ReviewTest.php
new file mode 100644
index 0000000..101e7c4
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/catalog/ReviewTest.php
@@ -0,0 +1,74 @@
+<?php
+
+class CatalogModelCatalogReviewTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('catalog/review');
+ $this->db->query("DELETE FROM " . DB_PREFIX . "review");
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->loadModelByRoute('catalog/review');
+ $this->db->query("DELETE FROM " . DB_PREFIX . "review");
+ }
+
+ public function testAddReviews() {
+ $productId = 0;
+ $data = array(
+ 'name' => "Reviewer's name",
+ 'text' => 'Review',
+ 'rating' => 0,
+ );
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->model_catalog_review->addReview($productId, $data);
+ }
+
+ $reviewCount = (int)$this->db->query("SELECT COUNT(*) AS review_num FROM " . DB_PREFIX . "review")->row['review_num'];
+ $this->assertEquals(5, $reviewCount);
+ }
+
+ public function testGetReviews() {
+ $productId = 28;
+ $data = array(
+ 'name' => "Reviewer's name",
+ 'text' => 'Review',
+ 'rating' => 0,
+ );
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->model_catalog_review->addReview($productId, $data);
+ }
+
+ $this->db->query("UPDATE " . DB_PREFIX . "review SET `status` = 1");
+
+ $reviews = $this->model_catalog_review->getReviewsByProductId($productId);
+
+ $this->assertCount(5, $reviews);
+ }
+
+ public function testGetReviewCount() {
+ $productId = 28;
+ $data = array(
+ 'name' => "Reviewer's name",
+ 'text' => 'Review',
+ 'rating' => 0,
+ );
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->model_catalog_review->addReview($productId, $data);
+ }
+
+ $this->db->query("UPDATE " . DB_PREFIX . "review SET `status` = 1");
+
+ $reviewCount = $this->model_catalog_review->getTotalReviewsByProductId($productId);
+
+ $this->assertEquals(5, $reviewCount);
+ }
+}
diff --git a/tests/phpunit/opencart/catalog/model/checkout/OrderTest.php b/tests/phpunit/opencart/catalog/model/checkout/OrderTest.php
new file mode 100644
index 0000000..003a31b
--- /dev/null
+++ b/tests/phpunit/opencart/catalog/model/checkout/OrderTest.php
@@ -0,0 +1,204 @@
+<?php
+
+class CatalogModelCheckoutOrderTest extends OpenCartTest {
+
+ /**
+ * @before
+ */
+ public function setupTest() {
+ $this->loadModelByRoute('checkout/order');
+ $this->loadModelByRoute('account/custom_field');
+
+ $this->emptyTables();
+ }
+
+ /**
+ * @after
+ */
+ public function completeTest() {
+ $this->emptyTables();
+ }
+
+ private function emptyTables() {
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_custom_field");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_fraud");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_history");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_option");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_product");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring_transaction");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_total");
+ $this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher");
+
+ }
+
+ private function getOrderArray() {
+ $order = array(
+ 'invoice_prefix' => '',
+ 'store_id' => 0,
+ 'store_url' => '',
+ 'store_name' => '',
+ 'customer_id' => 0,
+ 'customer_group_id' => 0,
+ 'firstname' => '',
+ 'lastname' => '',
+ 'email' => '',
+ 'telephone' => '',
+ 'fax' => '',
+ 'custom_field' => array(),
+ 'payment_firstname' => '',
+ 'payment_lastname' => '',
+ 'payment_company' => '',
+ 'payment_address_1' => '',
+ 'payment_address_2' => '',
+ 'payment_city' => '',
+ 'payment_postcode' => '',
+ 'payment_zone' => '',
+ 'payment_zone_id' => 0,
+ 'payment_country' => '',
+ 'payment_country_id' => 0,
+ 'payment_address_format' => '',
+ 'payment_custom_field' => array(),
+ 'payment_method' => '',
+ 'payment_code' => '',
+ 'shipping_firstname' => '',
+ 'shipping_lastname' => '',
+ 'shipping_company' => '',
+ 'shipping_address_1' => '',
+ 'shipping_address_2' => '',
+ 'shipping_city' => '',
+ 'shipping_postcode' => '',
+ 'shipping_zone' => '',
+ 'shipping_zone_id' => 0,
+ 'shipping_country' => '',
+ 'shipping_country_id' => 0,
+ 'shipping_address_format' => '',
+ 'shipping_custom_field' => array(),
+ 'shipping_method' => '',
+ 'shipping_code' => '',
+ 'products' => array(
+ array(
+ 'product_id' => 0,
+ 'name' => '',
+ 'model' => '',
+ 'quantity' => 0,
+ 'price' => 0.00,
+ 'total' => 0.00,
+ 'tax' => 0.00,
+ 'reward' => 0.00,
+ 'option' => array(
+ array(
+ 'product_option_id' => 0,
+ 'product_option_value_id' => 0,
+ 'name' => '',
+ 'value' => '',
+ 'type' => '',
+ ),
+ )
+ ),
+ ),
+ 'vouchers' => array(
+ array(
+ 'description' => '',
+ 'code' => '',
+ 'from_name' => '',
+ 'from_email' => '',
+ 'to_name' => '',
+ 'to_email' => '',
+ 'voucher_theme_id' => 0,
+ 'message' => '',
+ 'amount' => 0.00,
+ ),
+ ),
+ 'comment' => '',
+ 'total' => '',
+ 'affiliate_id' => 0,
+ 'commission' => 0,
+ 'marketing_id' => 0,
+ 'tracking' => '',
+ 'language_id' => 0,
+ 'currency_id' => 0,
+ 'currency_code' => '',
+ 'currency_value' => 0,
+ 'ip' => '',
+ 'forwarded_ip' => '',
+ 'user_agent' => '',
+ 'accept_language' => '',
+ 'totals' => array(
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ array(
+ 'code' => '',
+ 'title' => '',
+ 'value' => 0.00,
+ 'sort_order' => 0,
+ ),
+ ),
+ );
+
+ return $order;
+ }
+
+ public function testAddOrder() {
+ $orderData = $this->getOrderArray();
+
+ $orderId = $this->model_checkout_order->addOrder($orderData);
+
+ $this->assertNotNull($orderId);
+
+ $numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order`")->row['total'];
+ $this->assertEquals(1, $numRows);
+
+ $numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_product`")->row['total'];
+ $this->assertEquals(1, $numRows);
+
+ $numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_option`")->row['total'];
+ $this->assertEquals(1, $numRows);
+
+ $numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_voucher`")->row['total'];
+ $this->assertEquals(1, $numRows);
+
+ $numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_total`")->row['total'];
+ $this->assertEquals(2, $numRows);
+ }
+
+ // The following three tests should be completed when custom fields are implemented
+
+ public function testGetOrder() {
+ $this->markTestIncomplete();
+
+ $orderData = $this->getOrderArray();
+
+ $this->model_checkout_order->addOrder($orderData);
+
+ $orderId = $this->db->query("SELECT order_id FROM `" . DB_PREFIX . "order` LIMIT 1")->row['order_id'];
+
+ $order = $this->model_checkout_order->getOrder($orderId);
+
+ $this->assertEquals($orderId, $order['order_id']);
+ }
+
+ public function testConfirm() {
+ $this->markTestIncomplete();
+
+ $orderData = $this->getOrderArray();
+
+ $orderId = $this->model_checkout_order->addOrder($orderData);
+
+ $this->model_checkout_order->confirm($orderId, $this->config->get('config_complete_status_id'));
+ }
+
+ public function testUpdate() {
+ $this->markTestIncomplete();
+
+ $orderData = $this->getOrderArray();
+
+ $orderId = $this->model_checkout_order->addOrder($orderData);
+ $this->model_checkout_order->update($orderId, $this->config->get('config_complete_status_id'));
+ }
+}
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");
+ }
+
+}
diff --git a/tests/phpunit/selenium/catalog/AccountTest.php b/tests/phpunit/selenium/catalog/AccountTest.php
new file mode 100644
index 0000000..10edf84
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/AccountTest.php
@@ -0,0 +1,320 @@
+<?php
+
+class CatalogAccountTest extends OpenCartSeleniumTest {
+
+
+ /**
+ * @before
+ */
+ protected function setupTest() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ /**
+ * @after
+ */
+ protected function completeTest() {
+ $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
+ $db->query("DELETE FROM " . DB_PREFIX . "customer");
+ $db->query("DELETE FROM " . DB_PREFIX . "address");
+ }
+
+ public function testNewsletterSubscription() {
+ $this->doRegistration();
+
+ $this->url("index.php?route=account/newsletter");
+ $this->byCssSelector('input[value="1"]')->click();
+ $this->byCssSelector('input[value="Continue"]')->click();
+ $this->url("index.php?route=account/newsletter");
+ $element = $this->byCssSelector('input[value="1"]');
+ $this->assertEquals('true', $element->attribute('checked'));
+
+ $this->byCssSelector('input[value="0"]')->click();
+ $this->byCssSelector('input[value="Continue"]')->click();
+ $this->url("index.php?route=account/newsletter");
+ $element = $this->byCssSelector('input[value="0"]');
+ $this->assertEquals('true', $element->attribute('checked'));
+ }
+
+ public function testAddAddress() {
+ $this->doRegistration();
+ $this->url("index.php?route=account/address/add");
+
+ $this->clickOnElement('input-firstname');
+ $this->keys('Firstname');
+
+ $this->clickOnElement('input-lastname');
+ $this->keys('Lastname');
+
+ $this->clickOnElement('input-company');
+ $this->keys('Company');
+
+ $this->clickOnElement('input-address-1');
+ $this->keys('Address 1');
+
+ $this->clickOnElement('input-address-2');
+ $this->keys('Address 2');
+
+ $this->clickOnElement('input-city');
+ $this->keys('City');
+
+ $this->clickOnElement('input-postcode');
+ $this->keys('000 000');
+
+ $this->byCssSelector('#input-country option[value="222"]')->click();
+ $this->byCssSelector('#input-zone option[value="3608"]')->click();
+
+ $this->byCssSelector('input[value="Continue"]')->click();
+
+ $this->waitUntil(function() {
+ if (strpos($this->url(), 'account/address') !== False) {
+ return true;
+ }
+ }, 3000);
+
+ $this->byCssSelector('table.table-hover tr:last-child td:last-child .btn-info')->click();
+
+ $this->waitUntil(function() {
+ if (strpos($this->url(), 'account/address/edit') !== False) {
+ return true;
+ }
+ }, 3000);
+
+ $this->byId('input-firstname')->clear();
+ $this->clickOnElement('input-firstname');
+ $this->keys('Firstname2');
+
+ $this->byId('input-lastname')->clear();
+ $this->clickOnElement('input-lastname');
+ $this->keys('Lastname2');
+
+ $this->byId('input-company')->clear();
+ $this->clickOnElement('input-company');
+ $this->keys('Company2');
+
+ $this->byId('input-address-1')->clear();
+ $this->clickOnElement('input-address-1');
+ $this->keys('Address 12');
+
+ $this->byId('input-address-2')->clear();
+ $this->clickOnElement('input-address-2');
+ $this->keys('Address 22');
+
+ $this->byId('input-city')->clear();
+ $this->clickOnElement('input-city');
+ $this->keys('City2');
+
+ $this->byId('input-postcode')->clear();
+ $this->clickOnElement('input-postcode');
+ $this->keys('999 999');
+
+ $this->byCssSelector('#input-country option[value="223"]')->click();
+
+ $this->waitUntil(function() {
+ if ($this->byCssSelector('#input-zone option[value="3624"]')) {
+ return true;
+ }
+ }, 3000);
+
+ $this->byCssSelector('#input-zone option[value="3624"]')->click();
+
+ $this->byCssSelector('input[value="Continue"]')->click();
+
+ $this->waitUntil(function() {
+ if (strpos($this->url(), 'account/address') !== False) {
+ return true;
+ }
+ }, 3000);
+
+ $this->byCssSelector('table.table-hover tr:last-child td:last-child .btn-info')->click();
+
+ $firstname = $this->byId('input-firstname')->value();
+ $this->assertEquals('Firstname2', $firstname);
+
+ $lastname = $this->byId('input-lastname')->value();
+ $this->assertEquals('Lastname2', $lastname);
+
+ $company = $this->byId('input-company')->value();
+ $this->assertEquals('Company2', $company);
+
+ $address1 = $this->byId('input-address-1')->value();
+ $this->assertEquals('Address 12', $address1);
+
+ $address2 = $this->byId('input-address-2')->value();
+ $this->assertEquals('Address 22', $address2);
+
+ $city = $this->byId('input-city')->value();
+ $this->assertEquals('City2', $city);
+
+ $postcode = $this->byId('input-postcode')->value();
+ $this->assertEquals('999 999', $postcode);
+
+ $country = $this->byId('input-country')->value();
+ $this->assertEquals('223', $country);
+
+ $zone = $this->byId('input-zone')->value();
+ $this->assertEquals('3624', $zone);
+ }
+
+ public function testChangePassword() {
+ $this->doRegistration();
+
+ $this->url("index.php?route=account/password");
+
+ $this->clickOnElement('input-password');
+ $this->keys('new-password');
+
+ $this->clickOnElement('input-confirm');
+ $this->keys('new-password');
+
+ $this->byCssSelector('input[value="Continue"]')->click();
+
+ $this->url('index.php?route=account/logout');
+ $this->url('index.php?route=account/login');
+
+ $this->clickOnElement('input-email');
+ $this->keys('john.smith@example.com');
+
+ $this->clickOnElement('input-password');
+ $this->keys('new-password');
+
+ $this->byCssSelector('input[value="Login"]')->click();
+
+ $this->waitUntil(function(){
+ if (strpos($this->url(), 'account/account') !== False) {
+ return true;
+ }
+ }, 3000);
+ }
+
+ public function testInformationEditing() {
+ $this->doRegistration();
+
+ $this->url("index.php?route=account/edit");
+
+ $this->byId('input-firstname')->clear();
+ $this->clickOnElement('input-firstname');
+ $this->keys('John-New');
+
+ $this->byId('input-lastname')->clear();
+ $this->clickOnElement('input-lastname');
+ $this->keys('Smith-New');
+
+ $this->byId('input-email')->clear();
+ $this->clickOnElement('input-email');
+ $this->keys('john.smith.new@example.com');
+
+ $this->byId('input-telephone')->clear();
+ $this->clickOnElement('input-telephone');
+ $this->keys('000000000');
+
+ $this->byCssSelector('input[value="Continue"]')->click();
+
+ $this->url("index.php?route=account/edit");
+
+ $firstname = $this->byId('input-firstname')->value();
+ $this->assertEquals('John-New', $firstname);
+
+ $lastname = $this->byId('input-lastname')->value();
+ $this->assertEquals('Smith-New', $lastname);
+
+ $email = $this->byId('input-email')->value();
+ $this->assertEquals('john.smith.new@example.com', $email);
+
+ $telephone = $this->byId('input-telephone')->value();
+ $this->assertEquals('000000000', $telephone);
+ }
+
+ public function testLogin() {
+ $this->doRegistration();
+ $this->url('index.php?route=account/logout');
+ $this->url('index.php?route=account/login');
+
+ $this->clickOnElement('input-email');
+ $this->keys('john.smith@example.com');
+
+ $this->clickOnElement('input-password');
+ $this->keys('password123456');
+
+ $this->byCssSelector('input[value="Login"]')->click();
+
+ $this->waitUntil(function(){
+ if (strpos($this->url(), 'account/account') !== False) {
+ return true;
+ }
+ }, 3000);
+ }
+
+ public function testFailedLogin() {
+ $this->doRegistration();
+ $this->url('index.php?route=account/logout');
+ $this->url('index.php?route=account/login');
+
+ $this->clickOnElement('input-email');
+ $this->keys('john.smith@example.com');
+
+ $this->clickOnElement('input-password');
+ $this->keys('incorrect password');
+
+ $this->byCssSelector('input[value="Login"]')->click();
+
+ $this->waitUntil(function(){
+ if (strpos($this->url(), 'account/login') !== False) {
+ return true;
+ }
+ }, 3000);
+
+ $this->byCssSelector('.alert-danger');
+ }
+
+ private function doRegistration() {
+ $this->url('index.php?route=account/register');
+
+ $this->clickOnElement('input-firstname');
+ $this->keys('John');
+
+ $this->clickOnElement('input-lastname');
+ $this->keys('Smith');
+
+ $this->clickOnElement('input-email');
+ $this->keys('john.smith@example.com');
+
+ $this->clickOnElement('input-telephone');
+ $this->keys('0123456789');
+
+ $this->clickOnElement('input-address-1');
+ $this->keys('Address 1');
+
+ $this->clickOnElement('input-address-2');
+ $this->keys('Address 2');
+
+ $this->clickOnElement('input-city');
+ $this->keys('City');
+
+ $this->clickOnElement('input-postcode');
+ $this->keys('000 000');
+
+ $countryElement = $this->byCssSelector('#input-country option[value="222"]');
+ $countryElement->click();
+
+ $countyElement = $this->byCssSelector('#input-zone option[value="3608"]');
+ $countyElement->click();
+
+ $this->clickOnElement('input-password');
+ $this->keys('password123456');
+
+ $this->clickOnElement('input-confirm');
+ $this->keys('password123456');
+
+ $this->byCssSelector('input[name="agree"]')->click();
+
+ $this->byCssSelector('input[value="Continue"]')->click();
+
+ $this->waitUntil(function(){
+ if (strpos($this->url(), 'account/success') !== False) {
+ return true;
+ }
+ }, 3000);
+ }
+}
diff --git a/tests/phpunit/selenium/catalog/CategoryTest.php b/tests/phpunit/selenium/catalog/CategoryTest.php
new file mode 100644
index 0000000..878ecc2
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/CategoryTest.php
@@ -0,0 +1,39 @@
+<?php
+
+class CatalogCategoryTest extends OpenCartSeleniumTest {
+
+
+ /**
+ * @before
+ */
+ protected function setupTest() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ public function testAddToCartButton() {
+ $this->url('http://opencart.welfordlocal.co.uk/index.php?route=product/category&path=20');
+
+ $addToCartButton = $this->byCssSelector('button[onclick="cart.add(\'28\');"]');
+ $addToCartButton->click();
+
+ $this->url('index.php?route=checkout/cart');
+ $element = $this->byCssSelector('#accordion + br + .row .table-bordered tr:last-child td:last-child');
+ $this->assertEquals('$119.50', $element->text());
+ }
+
+
+ public function testRedirect() {
+ $this->url('http://opencart.welfordlocal.co.uk/index.php?route=product/category&path=20');
+
+ $addToCartButton = $this->byCssSelector('button[onclick="cart.add(\'42\');"]');
+ $addToCartButton->click();
+
+ $this->waitUntil(function(){
+ if (strpos($this->url(), 'product/product') !== False) {
+ return true;
+ }
+ }, 3000);
+ }
+
+}
diff --git a/tests/phpunit/selenium/catalog/CheckoutTest.php b/tests/phpunit/selenium/catalog/CheckoutTest.php
new file mode 100644
index 0000000..8d5583d
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/CheckoutTest.php
@@ -0,0 +1,64 @@
+<?php
+
+class CatalogCheckoutTest extends OpenCartSeleniumTest {
+
+
+ /**
+ * @before
+ */
+ protected function setupTest() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ public function testUpdateQuantity() {
+ $this->addProductsToCart();
+
+ $element = $this->byCssSelector('.table-bordered tbody tr:last-child input');
+ $this->assertEquals('3', $element->value());
+
+ $element = $this->byCssSelector('.table-bordered tbody tr:first-child input');
+ $this->assertEquals('1', $element->value());
+
+ $element->clear();
+ $element->click();
+ $this->keys('2');
+
+ $this->byCssSelector('.table-bordered tbody tr:first-child button.btn-primary')->click();
+
+ sleep(3);
+
+ $element = $this->byCssSelector('.table-bordered tbody tr:first-child input');
+ $this->assertEquals('2', $element->value());
+
+ $element = $this->byCssSelector('.table-bordered tbody tr:last-child input');
+ $this->assertEquals('3', $element->value());
+ }
+
+ public function testRemoveProduct() {
+ $this->addProductsToCart();
+
+ $element = $this->byCssSelector('form .table-bordered tbody tr:first-child td:nth-child(2)');
+ $this->assertStringStartsWith('MacBook', $element->text());
+
+ $this->byCssSelector('.table-bordered tbody tr:first-child button.btn-danger')->click();
+
+ sleep(3);
+
+ $element = $this->byCssSelector('form .table-bordered tbody tr:first-child td:nth-child(2)');
+ $this->assertStringStartsWith('Sony VAIO', $element->text());
+ }
+
+ private function addProductsToCart() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $this->byId('button-cart')->click();
+
+ $this->url('index.php?route=product/product&product_id=46');
+ $this->byId('input-quantity')->clear();
+ $this->clickOnElement('input-quantity');
+ $this->keys('3');
+ $this->byId('button-cart')->click();
+
+ $this->url('index.php?route=checkout/cart');
+ }
+}
diff --git a/tests/phpunit/selenium/catalog/PayPalExpressTest.php b/tests/phpunit/selenium/catalog/PayPalExpressTest.php
new file mode 100644
index 0000000..8fcc9c5
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/PayPalExpressTest.php
@@ -0,0 +1,173 @@
+<?php
+
+class CatalogPayPalExpressTest extends OpenCartSeleniumTest {
+
+ private $moduleInstalled = false;
+
+ /**
+ * @before
+ */
+ protected function before() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ public function setUpPage() {
+ if (!$this->moduleInstalled) {
+ $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "paypal_order");
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "paypal_order_transaction");
+ $db->query("DELETE l, lr FROM " . DB_PREFIX . "layout l, " . DB_PREFIX . "layout_route lr WHERE l.layout_id = lr.layout_id AND l.`name` = 'Cart'");
+
+ $this->url("admin/");
+
+ $this->byCssSelector('input[name="username"]')->click();
+ $this->keys(ADMIN_USERNAME);
+
+ $this->byCssSelector('input[name="password"]')->click();
+ $this->keys(ADMIN_PASSWORD);
+
+ $this->byCssSelector('button[type="submit"]')->click();
+
+ $this->moduleInstalled = true;
+
+ $this->waitToLoad('Dashboard');
+
+ // Installing the payment module
+ $this->clickOnElement('button-menu');
+
+ $this->waitToAppearAndClick('#extension a');
+ $this->waitToAppearAndClick('#extension li:nth-child(5) a');
+
+ $this->waitToLoad('Payment');
+
+ $i = 1;
+
+ for ( ; ; $i++) {
+ $element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");
+
+ if ($element->text() == 'PayPal Express Checkout') {
+ break;
+ }
+ }
+
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");
+
+ $this->waitToLoad('PayPal Express Checkout');
+
+ $this->clickOnElement('entry-username');
+ $this->keys(PP_EXPRESS_API_USERNAME);
+
+ $this->clickOnElement('entry-password');
+ $this->keys(PP_EXPRESS_API_PASSWORD);
+
+ $this->clickOnElement('entry-signature');
+ $this->keys(PP_EXPRESS_API_SIGNATURE);
+
+ $this->byCssSelector('a[href="#tab-general"]')->click();
+
+ $this->waitToAppearAndClick('#input-live-demo option[value="1"]');
+
+ for ($i = 1; ; $i++) {
+ $element = $this->byCssSelector('#input-currency option:nth-child(' . $i . ')');
+
+ if ($element->text() == 'USD') {
+ $element->click();
+ break;
+ }
+ }
+
+ $this->clickOnElement('input-total');
+ $this->keys('0.00');
+
+ $this->byCssSelector('#input-status option[value="1"]')->click();
+
+ $this->byCssSelector('.pull-right button.btn')->click();
+
+ // Adding the Cart Layout
+ $this->waitToAppearAndClick('#system a');
+ $this->waitToAppearAndClick('#system li:nth-child(2) a');
+ $this->waitToAppearAndClick('#system li:nth-child(2) li:first-child a');
+
+ $this->waitToLoad('Layouts');
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ $this->waitToAppearAndClick('#input-name');
+ $this->keys('Cart');
+
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ $this->byCssSelector('input[name="layout_route[0][route]"]')->click();
+ $this->keys('checkout/cart');
+
+ $this->byCssSelector('.fa-check-circle')->click();
+
+ // Installing the payment button
+ $this->waitToAppearAndClick('#extension a');
+ $this->waitToAppearAndClick('#extension li:nth-child(3) a');
+
+ $i = 1;
+
+ for ( ; ; $i++) {
+ $element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");
+
+ if ($element->text() == 'PayPal Express Checkout button') {
+ break;
+ }
+ }
+
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");
+
+ $this->waitToLoad('PayPal Express Checkout button');
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ for ($i = 1; ; $i++) {
+ $element = $this->byCssSelector("select[name=\"pp_button_module[0][layout_id]\"] option:nth-child($i)");
+
+ if ($element->text() == 'Cart') {
+ $element->click();
+ break;
+ }
+ }
+
+ $this->byCssSelector('button[title="Save"]')->click();
+ }
+ }
+
+ public function testOneProduct() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $this->clickOnElement('button-cart');
+
+ $this->url('index.php?route=checkout/cart');
+ $this->waitToLoad('Shopping Cart');
+
+ $this->byCssSelector('.pp-express-button')->click();
+
+ $this->waitToLoad("Pay with a PayPal", 30000);
+
+ $this->clickOnElement('login_email');
+ $this->keys(PP_EXPRESS_USERNAME);
+
+ $this->clickOnElement('login_password');
+ $this->keys(PP_EXPRESS_PASSWORD);
+
+ $this->clickOnElement('submitLogin');
+
+ $this->waitToLoad("Review your information", 30000);
+
+ $this->clickOnElement('continue_abovefold');
+
+ $this->waitToLoad("Confirm order", 30000);
+
+ $this->byCssSelector('.pull-right .btn-primary')->click();
+
+ $this->waitToLoad("Your order has been placed!");
+
+ $element = $this->byCssSelector('#content h1');
+
+ $this->assertEquals('Your order has been placed!', $element->text());
+ }
+
+}
diff --git a/tests/phpunit/selenium/catalog/ProductTest.php b/tests/phpunit/selenium/catalog/ProductTest.php
new file mode 100644
index 0000000..5d70b4a
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/ProductTest.php
@@ -0,0 +1,79 @@
+<?php
+
+class CatalogProductTest extends OpenCartSeleniumTest {
+
+
+ /**
+ * @before
+ */
+ protected function setupTest() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ public function testSearch() {
+ $this->url('index.php?route=common/home');
+ $this->byCssSelector('input[name="search"]')->click();
+ $this->keys('Apple');
+
+ $this->byCssSelector('i.fa-search')->click();
+
+ $this->waitUntil(function() {
+ if (strpos($this->url(), 'product/search') !== False) {
+ return true;
+ }
+ }, 3000);
+
+ $element = $this->byCssSelector('div.caption a');
+ $this->assertTrue(strpos($element->attribute('href'), 'product_id=42') !== False);
+ }
+
+ public function testAddToCartButton() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $this->clickOnElement('button-cart');
+
+ $this->url('index.php?route=checkout/cart');
+ $element = $this->byCssSelector('#accordion + br + .row .table-bordered tr:last-child td:last-child');
+ $this->assertEquals('$589.50', $element->text());
+ }
+
+ public function testQuantityField() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $inputElement = $this->byId('input-quantity');
+ $inputElement->clear();
+
+ $this->clickOnElement('input-quantity');
+ $this->keys('3');
+
+ $this->clickOnElement('button-cart');
+
+ $this->url('index.php?route=checkout/cart');
+ $element = $this->byCssSelector('#accordion + br + .row .table-bordered tr:last-child td:last-child');
+ $this->assertEquals('$1,768.50', $element->text());
+ }
+
+ public function testWishListButton() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $element = $this->byCssSelector('i.fa-heart:last-child');
+ $element->click();
+
+ $this->waitUntil(function() {
+ if ($this->byCssSelector('.alert-success')) {
+ return true;
+ }
+ }, 2000);
+ }
+
+ public function testCompareButton() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $element = $this->byCssSelector('i.fa-exchange');
+ $element->click();
+
+ $this->waitUntil(function() {
+ if ($this->byCssSelector('.alert-success')) {
+ return true;
+ }
+ }, 2000);
+ }
+
+}
diff --git a/tests/phpunit/selenium/catalog/SagePayDirectTest.php b/tests/phpunit/selenium/catalog/SagePayDirectTest.php
new file mode 100644
index 0000000..8e65fe6
--- /dev/null
+++ b/tests/phpunit/selenium/catalog/SagePayDirectTest.php
@@ -0,0 +1,153 @@
+<?php
+
+class CatalogSagePayExpressTest extends OpenCartSeleniumTest {
+
+ private $moduleInstalled = false;
+
+ /**
+ * @before
+ */
+ protected function before() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ public function setUpPage() {
+ if (!$this->moduleInstalled) {
+ $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order");
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order_transaction");
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_order_recurring");
+ $db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "sagepay_direct_card");
+
+ $this->url("admin/");
+
+ $this->byCssSelector('input[name="username"]')->click();
+ $this->keys(ADMIN_USERNAME);
+
+ $this->byCssSelector('input[name="password"]')->click();
+ $this->keys(ADMIN_PASSWORD);
+
+ $this->byCssSelector('button[type="submit"]')->click();
+
+ $this->moduleInstalled = true;
+
+ $this->waitToLoad('Dashboard');
+
+ // Installing the payment module
+ $this->clickOnElement('button-menu');
+
+ $this->waitToAppearAndClick('#extension a');
+ $this->waitToAppearAndClick('#extension li:nth-child(5) a');
+
+ $this->waitToLoad('Payment');
+
+ $i = 1;
+
+ for ( ; ; $i++) {
+ $element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");
+
+ if ($element->text() == 'SagePay Direct') {
+ break;
+ }
+ }
+
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");
+
+ $this->waitToLoad('SagePay Direct');
+
+ $this->clickOnElement('sagepay_direct_vendor');
+ $this->keys(SAGEPAY_DIRECT_VENDOR);
+
+ $this->byCssSelector('#input-test option[value="test"]')->click();
+
+ $this->clickOnElement('sagepay_direct_total');
+ $this->keys('0.00');
+
+ // Adding the Cart Layout
+ $this->waitToAppearAndClick('#system a');
+ $this->waitToAppearAndClick('#system li:nth-child(2) a');
+ $this->waitToAppearAndClick('#system li:nth-child(2) li:first-child a');
+
+ $this->waitToLoad('Layouts');
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ $this->waitToAppearAndClick('#input-name');
+ $this->keys('Cart');
+
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ $this->byCssSelector('input[name="layout_route[0][route]"]')->click();
+ $this->keys('checkout/cart');
+
+ $this->byCssSelector('.fa-check-circle')->click();
+
+ // Installing the payment button
+ $this->waitToAppearAndClick('#extension a');
+ $this->waitToAppearAndClick('#extension li:nth-child(3) a');
+
+ $i = 1;
+
+ for ( ; ; $i++) {
+ $element = $this->byCssSelector(".table-bordered tbody tr:nth-child($i) td:first-child");
+
+ if ($element->text() == 'PayPal Express Checkout button') {
+ break;
+ }
+ }
+
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-success");
+ $this->waitToAppearAndClick(".table-bordered tbody tr:nth-child($i) td:last-child a.btn-primary");
+
+ $this->waitToLoad('PayPal Express Checkout button');
+ $this->byCssSelector('.fa-plus-circle')->click();
+
+ for ($i = 1; ; $i++) {
+ $element = $this->byCssSelector("select[name=\"pp_button_module[0][layout_id]\"] option:nth-child($i)");
+
+ if ($element->text() == 'Cart') {
+ $element->click();
+ break;
+ }
+ }
+
+ $this->byCssSelector('button[title="Save"]')->click();
+ }
+ }
+
+ public function testOneProduct() {
+ $this->url('index.php?route=product/product&product_id=43');
+ $this->clickOnElement('button-cart');
+
+ $this->url('index.php?route=checkout/cart');
+ $this->waitToLoad('Shopping Cart');
+
+ $this->byCssSelector('.pp-express-button')->click();
+
+ $this->waitToLoad("Pay with a PayPal", 30000);
+
+ $this->clickOnElement('login_email');
+ $this->keys(PP_EXPRESS_USERNAME);
+
+ $this->clickOnElement('login_password');
+ $this->keys(PP_EXPRESS_PASSWORD);
+
+ $this->clickOnElement('submitLogin');
+
+ $this->waitToLoad("Review your information", 30000);
+
+ $this->clickOnElement('continue_abovefold');
+
+ $this->waitToLoad("Confirm order", 30000);
+
+ $this->byCssSelector('.pull-right .btn-primary')->click();
+
+ $this->waitToLoad("Your order has been placed!");
+
+ $element = $this->byCssSelector('#content h1');
+
+ $this->assertEquals('Your order has been placed!', $element->text());
+ }
+
+}
diff --git a/tests/phpunit/selenium/openbay/SetupTest.php b/tests/phpunit/selenium/openbay/SetupTest.php
new file mode 100644
index 0000000..831a891
--- /dev/null
+++ b/tests/phpunit/selenium/openbay/SetupTest.php
@@ -0,0 +1,91 @@
+<?php
+class OpenbaySetupTest extends OpenCartSeleniumTest {
+ private $moduleInstalled = false;
+
+ /**
+ * @before
+ */
+ protected function before() {
+ $this->setBrowser('firefox');
+ $this->setBrowserUrl(HTTP_SERVER);
+ }
+
+ /**
+ * @after
+ */
+ protected function completeTest() {
+
+ }
+
+ public function testSetup() {
+ if ($this->moduleInstalled === false) {
+ $this->url("admin/");
+
+ $this->byCssSelector('input[name="username"]')->click();
+ $this->keys(ADMIN_USERNAME);
+
+ $this->byCssSelector('input[name="password"]')->click();
+ $this->keys(ADMIN_PASSWORD);
+
+ $this->byCssSelector('button[type="submit"]')->click();
+
+ $this->moduleInstalled = true;
+
+ $this->waitToLoad('Dashboard');
+
+ // Installing the payment module
+ $this->clickOnElement('button-menu');
+
+ $this->waitToAppearAndClick('#extension a');
+ $this->waitToAppearAndClick('#extension li:nth-child(3) a');
+
+ $this->waitToLoad('Modules');
+
+ $i = 1;
+
+ for ( ; ; $i++) {
+ $element = $this->byCssSelector(".table-striped tbody tr:nth-child($i) td:first-child");
+
+ if ($element->text() == 'OpenBay Pro') {
+ break;
+ }
+ }
+
+ $this->waitToAppearAndClick(".table-striped tbody tr:nth-child($i) td:last-child a.btn-success");
+
+ $this->waitToLoad('Modules', 50000);
+
+ // Go to the OpenBay Pro dashboard
+ $this->waitToAppearAndClick('#extension li:nth-child(8) a');
+ $this->waitToAppearAndClick('#extension li:nth-child(8) li:first-child a');
+
+ $this->waitToLoad('OpenBay Pro', 50000);
+
+ $this->byCssSelector('#button-install-ebay')->click();
+
+ $this->waitToLoad('OpenBay Pro', 50000);
+
+ $this->byCssSelector('#button-edit-ebay')->click();
+
+ $this->waitToLoad('Dashboard', 50000);
+
+ $this->byCssSelector('#settings-link')->click();
+
+ $this->waitToLoad('Marketplace settings', 50000);
+
+ $this->byCssSelector('#ebay-status option[value="1"]')->click();
+
+ $this->clickOnElement('ebay-token');
+ $this->keys(OPENBAY_EBAY_TOKEN);
+
+ $this->clickOnElement('ebay-secret');
+ $this->keys(OPENBAY_EBAY_SECRET);
+
+ $this->byCssSelector('button[type="submit"]')->click();
+ }
+ }
+
+ public function installEbay() {
+
+ }
+}