diff options
Diffstat (limited to 'tests/phpunit/opencart')
17 files changed, 1506 insertions, 0 deletions
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&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&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"); + } + +} |