diff options
author | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
commit | 2eed7b082f83630301e51f57ca8394de228a8605 (patch) | |
tree | 1d19962d22d30f99317d9276e4bae7744fc93fc2 /tests | |
download | librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip |
first commit
Diffstat (limited to 'tests')
36 files changed, 3138 insertions, 0 deletions
diff --git a/tests/phpcs/OpenCart/IDE/README.md b/tests/phpcs/OpenCart/IDE/README.md new file mode 100644 index 0000000..6bdc746 --- /dev/null +++ b/tests/phpcs/OpenCart/IDE/README.md @@ -0,0 +1,11 @@ +## IDE auto formatters + +* PHPStorm +Copy the file ```opencart_phpstorm.xml``` to: + - Mac ```~/Library/Preferences/<PRODUCT><VERSION>/codestyles/OpenCart.xml``` + - Windows ```<User home>\.<PRODUCT><VERSION>\config\codestyles\OpenCart.xml``` + - Linux ```~/.<PRODUCT><VERSION>/config/codestyles/OpenCart.xml``` + +### References +* PHPStorm https://www.jetbrains.com/phpstorm/webhelp/code-style-xml.html +* PHPStorm https://www.jetbrains.com/help/phpstorm/2016.1/directories-used-by-phpstorm-to-store-settings-caches-plugins-and-logs.html diff --git a/tests/phpcs/OpenCart/IDE/opencart_phpstorm.xml b/tests/phpcs/OpenCart/IDE/opencart_phpstorm.xml new file mode 100644 index 0000000..d1ab9b9 --- /dev/null +++ b/tests/phpcs/OpenCart/IDE/opencart_phpstorm.xml @@ -0,0 +1,22 @@ +<code_scheme name="OpenCart"> + <PHPCodeStyleSettings> + <option name="ALIGN_KEY_VALUE_PAIRS" value="true" /> + <option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" /> + <option name="ALIGN_PHPDOC_COMMENTS" value="true" /> + <option name="PHPDOC_BLANK_LINES_AROUND_PARAMETERS" value="true" /> + <option name="UPPER_CASE_BOOLEAN_CONST" value="true" /> + <option name="UPPER_CASE_NULL_CONST" value="true" /> + <option name="BLANK_LINE_BEFORE_RETURN_STATEMENT" value="true" /> + <option name="ALIGN_CLASS_CONSTANTS" value="true" /> + </PHPCodeStyleSettings> + <codeStyleSettings language="PHP"> + <option name="CLASS_BRACE_STYLE" value="1" /> + <option name="METHOD_BRACE_STYLE" value="1" /> + <option name="SPECIAL_ELSE_IF_TREATMENT" value="true" /> + <option name="IF_BRACE_FORCE" value="3" /> + <indentOptions> + <option name="USE_TAB_CHARACTER" value="true" /> + <option name="SMART_TABS" value="true" /> + </indentOptions> + </codeStyleSettings> +</code_scheme>
\ No newline at end of file diff --git a/tests/phpcs/OpenCart/Sniffs/Spacing/ConcatenationSniff.php b/tests/phpcs/OpenCart/Sniffs/Spacing/ConcatenationSniff.php new file mode 100644 index 0000000..432c921 --- /dev/null +++ b/tests/phpcs/OpenCart/Sniffs/Spacing/ConcatenationSniff.php @@ -0,0 +1,34 @@ +<?php +/** + * Makes sure there are the needed spaces between the concatenation operator (.) and + * the strings being concatenated. + * + * @category PHP + * @package PHP_CodeSniffer + * @author Peter Philipp <peter.philipp@cando-image.com> + * @link http://pear.php.net/package/PHP_CodeSniffer + * @Licence http://www.gnu.org/licenses/gpl-2.0.html + */ +class OpenCart_Sniffs_Spacing_ConcatenationSniff implements PHP_CodeSniffer_Sniff { + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() { + return array(T_STRING_CONCAT); + + }//end register() + + + /** + * Processes this test, when one of its tokens is encountered. + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + $tokens = $phpcsFile->getTokens(); + if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE || $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { + $message = 'PHP concat operator must be surrounded by spaces'; + $phpcsFile->addError($message, $stackPtr, 'Missing'); + } + } +}//end class
\ No newline at end of file diff --git a/tests/phpcs/OpenCart/Sniffs/Spacing/OpenBracketSpacingSniff.php b/tests/phpcs/OpenCart/Sniffs/Spacing/OpenBracketSpacingSniff.php new file mode 100644 index 0000000..924b873 --- /dev/null +++ b/tests/phpcs/OpenCart/Sniffs/Spacing/OpenBracketSpacingSniff.php @@ -0,0 +1,69 @@ +<?php +/** + * Checks that there is no white space after an opening bracket, for "(" and "{". + * Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff. + * + * @category PHP + * @package PHP_CodeSniffer + * @link http://pear.php.net/package/PHP_CodeSniffer + * @Licence http://www.gnu.org/licenses/gpl-2.0.html + */ +class OpenCart_Sniffs_Spacing_OpenBracketSpacingSniff implements PHP_CodeSniffer_Sniff { + /** + * A list of tokenizers this sniff supports. + * + * @var array + */ + public $supportedTokenizers = array( + 'PHP', + 'JS', + ); + + + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() { + return array( + T_OPEN_CURLY_BRACKET, + T_OPEN_PARENTHESIS, + ); + + }//end register() + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * + * @return void + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + $tokens = $phpcsFile->getTokens(); + + // Ignore curly brackets in javascript files. + if ($tokens[$stackPtr]['code'] === T_OPEN_CURLY_BRACKET + && $phpcsFile->tokenizerType === 'JS' + ) { + return; + } + + if (isset($tokens[($stackPtr + 1)]) === true + && $tokens[($stackPtr + 1)]['code'] === T_WHITESPACE + && strpos($tokens[($stackPtr + 1)]['content'], $phpcsFile->eolChar) === false + ) { + $error = 'There should be no white space after an opening "%s"'; + $phpcsFile->addError( + $error, + ($stackPtr + 1), + 'OpeningWhitespace', + array($tokens[$stackPtr]['content']) + ); + } + + }//end process() +}//end class
\ No newline at end of file diff --git a/tests/phpcs/OpenCart/Sniffs/Variables/ValidVariableNameSniff.php b/tests/phpcs/OpenCart/Sniffs/Variables/ValidVariableNameSniff.php new file mode 100644 index 0000000..0e5be78 --- /dev/null +++ b/tests/phpcs/OpenCart/Sniffs/Variables/ValidVariableNameSniff.php @@ -0,0 +1,209 @@ +<?php +/** + * Validates variable names. + * + * @category PHP + * @package PHP_CodeSniffer + * @author Greg Sherwood <gsherwood@squiz.net> + * @author Marc McIntyre <mmcintyre@squiz.net> + * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600) + * @license http://opensource.org/licenses/BSD-3-Clause + * @link http://pear.php.net/package/PHP_CodeSniffer + */ + +if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { + throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); +} + +/** + * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. + * + * Checks the naming of variables and member variables. + * + * @category PHP + * @package PHP_CodeSniffer + * @author Greg Sherwood <gsherwood@squiz.net> + * @author Marc McIntyre <mmcintyre@squiz.net> + * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600) + * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence + * @version Release: 1.3.3 + * @link http://pear.php.net/package/PHP_CodeSniffer + */ +class OpenCart_Sniffs_Variables_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff { + + /** + * Tokens to ignore so that we can find a DOUBLE_COLON. + * + * @var array + */ + private $_ignore = array( + T_WHITESPACE, + T_COMMENT, + ); + + /** + * Regex to match valid underscore names for variables + * + * @var string + */ + private static $underscore_var = '/^(_|[a-z](?:_?[a-z0-9]+)*)$/'; + + /** + * Complementary regex to just exclude camel casing + * @var string + */ + private static $camelcase = '/[a-z][A-Z]/'; + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. + * + * @return void + */ + protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + $tokens = $phpcsFile->getTokens(); + $varName = ltrim($tokens[$stackPtr]['content'], '$'); + + $phpReservedVars = array( + '_SERVER', + '_GET', + '_POST', + '_REQUEST', + '_SESSION', + '_ENV', + '_COOKIE', + '_FILES', + 'GLOBALS', + ); + + // If it's a php reserved var, then its ok. + if (in_array($varName, $phpReservedVars) === true) { + return; + } + + if ($tokens[$stackPtr - 1]['code'] === T_PAAMAYIM_NEKUDOTAYIM) { + // static vars just ensure no camelcase (caps allowed) + if (preg_match(self::$camelcase, $varName)) { + $error = 'Variable "%s" is not in valid underscore format'; + $phpcsFile->addError($error, $stackPtr, 'NotUnderscore', array($varName)); + } + return; + } + + $objOperator = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true); + if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) { + // Check to see if we are using a variable from an object. + $var = $phpcsFile->findNext(array(T_WHITESPACE), ($objOperator + 1), null, true); + if ($tokens[$var]['code'] === T_STRING) { + $bracket = $objOperator = $phpcsFile->findNext(array(T_WHITESPACE), ($var + 1), null, true); + if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { + $objVarName = $tokens[$var]['content']; + + if (preg_match(self::$underscore_var, $objVarName) === 0) { + $phpcsFile->addError( + 'Variable "%s" is not in valid underscore format', + $var, + 'NotUnderscore', + array($objVarName) + ); + } + }//end if + }//end if + }//end if + + if (preg_match(self::$underscore_var, $varName) === 0) { + $error = 'Variable "%s" is not in valid underscore format'; + $phpcsFile->addError($error, $stackPtr, 'NotUnderscore', array($varName)); + } + }//end processVariable() + + /** + * Processes class member variables. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. + * + * @return void + */ + protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + $tokens = $phpcsFile->getTokens(); + + $varName = ltrim($tokens[$stackPtr]['content'], '$'); + $memberProps = $phpcsFile->getMemberProperties($stackPtr); + if (empty($memberProps) === true) { + // Couldn't get any info about this variable, which + // generally means it is invalid or possibly has a parse + // error. Any errors will be reported by the core, so + // we can ignore it. + return; + } + + $errorData = array($varName); + + if ( + ($memberProps['is_static'] && preg_match(self::$camelcase, $varName)) + || (!$memberProps['is_static'] && preg_match(self::$underscore_var, $varName) === 0) + ) { + $error = 'Variable "%s" is not in valid underscore format'; + $phpcsFile->addError($error, $stackPtr, 'MemberNotUnderscore', $errorData); + } + + }//end processMemberVar() + + + /** + * Processes the variable found within a double quoted string. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the double quoted + * string. + * + * @return void + */ + protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + $tokens = $phpcsFile->getTokens(); + + $phpReservedVars = array( + '_SERVER', + '_GET', + '_POST', + '_REQUEST', + '_SESSION', + '_ENV', + '_COOKIE', + '_FILES', + 'GLOBALS', + ); + if (preg_match_all('|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) { + foreach ($matches[1] as $varName) { + // If it's a php reserved var, then its ok. + if (in_array($varName, $phpReservedVars) === true) { + continue; + } + + // There is no way for us to know if the var is public or private, + // so we have to ignore a leading underscore if there is one and just + // check the main part of the variable name. + $originalVarName = $varName; + if (substr($varName, 0, 1) === '_') { + if ($phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE)) === true) { + $varName = substr($varName, 1); + } + } + + if (preg_match(self::$underscore_var, $varName) === 0) { + $varName = $matches[0]; + $error = 'Variable "%s" is not in valid underscore format'; + $data = array($originalVarName); + $phpcsFile->addError($error, $stackPtr, 'StringNotUnderscore', $data); + + } + } + }//end if + + }//end processVariableInString() +}//end class
\ No newline at end of file diff --git a/tests/phpcs/OpenCart/ruleset.xml b/tests/phpcs/OpenCart/ruleset.xml new file mode 100644 index 0000000..7823ffb --- /dev/null +++ b/tests/phpcs/OpenCart/ruleset.xml @@ -0,0 +1,102 @@ +<?xml version="1.0"?> +<ruleset name="OpenCart"> + <description>The Code Sniffer rule set for OpenCart</description> + + <exclude-pattern>*/system/vendor/*</exclude-pattern> + + <rule ref="Squiz.ControlStructures.InlineIfDeclaration" /> + + <!-- Closing PHP tags are not allowed --> + <rule ref="Zend.Files.ClosingTag"> + <severity>5</severity> + <type>error</type> + </rule> + + <!-- Test the spacing of inline control statements --> + <rule ref="Squiz.ControlStructures.InlineIfDeclaration" /> + + <!-- Check for whitespace after lines of code and checks for spaces/indents on empty lines --> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"> + <severity>1</severity> + <type>warning</type> + </rule> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" /> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" /> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" /> + + <!-- Check to ensure no PHP deprecated functions have been used --> + <rule ref="Generic.PHP.DeprecatedFunctions"> + <severity>5</severity> + <type>error</type> + </rule> + + <!-- PHP opening tag must be full <?php, no shorthand or ASP tags --> + <rule ref="Generic.PHP.DisallowShortOpenTag"> + <severity>5</severity> + <type>error</type> + </rule> + + <!-- In PHP files make sure there is no character before the opening tag --> + <rule ref="Generic.PHP.CharacterBeforePHPOpeningTag"/> + + <!-- true, false, null etc should all be lowercase only --> + <rule ref="Generic.PHP.LowerCaseConstant" /> + + <!-- Type casting should be immediately followed by the variable, no space --> + <rule ref="Generic.Formatting.NoSpaceAfterCast" /> + + <!-- Pass by reference is now only supported in the method/function params --> + <rule ref="Generic.Functions.CallTimePassByReference" /> + + <!-- keep the spacing between function/method params space after comma --> + <rule ref="Generic.Functions.FunctionCallArgumentSpacing" /> + + <!-- method names should always be camel case --> + <rule ref="Generic.NamingConventions.CamelCapsFunctionName"/> + + <!-- constants should always be uppercase --> + <rule ref="Generic.NamingConventions.UpperCaseConstantName"/> + + <!-- Detect BOMs to avoid curruptions --> + <rule ref="Generic.Files.ByteOrderMark"/> + + <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"> + <exclude-pattern>*.tpl</exclude-pattern> + <exclude-pattern>*.css</exclude-pattern> + <exclude-pattern>*.html</exclude-pattern> + <exclude-pattern>*.ini</exclude-pattern> + <exclude-pattern>*.txt</exclude-pattern> + <severity>1</severity> + <type>warning</type> + </rule> + + <!-- To do comments should be reported and completed --> + <rule ref="Generic.Commenting.Todo.CommentFound"> + <message>Please review this TODO comment: %s</message> + <severity>3</severity> + <type>warning</type> + </rule> + + <!-- Fix me comments should be reported and fixed --> + <rule ref="Generic.Commenting.Todo.Fixme"> + <message>Please review this FIXME comment: %s</message> + <severity>5</severity> + <type>warning</type> + </rule> + + <!-- Check that line endings are only \n --> + <rule ref="Generic.Files.LineEndings"> + <properties> + <property name="eolChar" value="\n"/> + </properties> + </rule> + + <!-- <rule ref="Squiz.ControlStructures.ControlSignature" /> --> + <!-- <rule ref="Generic.ControlStructures.InlineControlStructure"></rule> --> + + <!-- exclude the actual tests directory from being tested! --> + <exclude-pattern>*/tests/*</exclude-pattern> +</ruleset> + +<!-- @todo - A Sniff test needs to be added to ensure short echo tags are not used --> +<!-- @todo - A Sniff test to allow helper functions (normal functions) to be snake case -->
\ No newline at end of file diff --git a/tests/phpmd/phpmd.xml b/tests/phpmd/phpmd.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/phpmd/phpmd.xml 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&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"); + } + +} 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() { + + } +} diff --git a/tests/readme.md b/tests/readme.md new file mode 100644 index 0000000..22a4d8f --- /dev/null +++ b/tests/readme.md @@ -0,0 +1,45 @@ +## Important things to note about testing +* Tests should only be run on a test system, never a live one. +* They have been created to help developers test and improve not only OpenCart but also modules too. + +## Requirements: +* [GIT](http://git-scm.com/) +* [Composer](https://getcomposer.org/download/) +* A bit of command line knowledge +* Selenium (optional) + +## Instructions +* Install Git (most developers will already have this!) +* Install composer +* Git clone OpenCart (you cannot download the ZIP as this will not include the tests). +* Install OpenCart as normal +* Go to your command line (Windows > Run > Cmd), Shell, or Git Bash +* Change directory to /tests/phpunit/ folder +* Type in the command line: composer update (this will create you a vendor folder and download all dependencies) +* Composer will now pull in all of the required externals/dependencies +* run: vendor\bin\phpunit --bootstrap bootstrap.php opencart\admin to run tests in admin folder +* run: vendor\bin\phpunit --bootstrap bootstrap.php opencart\catalog to run tests in catalog folder +* run: vendor\bin\phpunit --bootstrap bootstrap.php opencart\system to run tests in system folder + +## Selenium instructions + +Running Acceptance (Functional) Tests with Selenium requires a standalone selenium server on your machine. +The server can be downloaded from [here](http://code.google.com/p/selenium/downloads/list). Before starting your Selenium Tests +you have to run the standalone server: `java -jar selenium-server-standalone-2.32.0.jar`. Writing Selenium Tests requires you to extend the OpenCartSeleniumTest class. + +* run: vendor\bin\phpunit --bootstrap bootstrap.php selenium\catalog to run tests in system folder + +## Please READ! +The tests are still under development, there is hundreds of them to do. + +The tests will drop and recreate tables in database specified in config.php and admin/config.php + +## Jenkins Users +You will also see a build.xml file inside the project root which you can use to configure a Jenkins build. + +## We need you +If you understand testing, then you know how important it is to any project. If you have a suggestion then we would really like to hear it! + +Forum thread: http://forum.opencart.com/viewtopic.php?f=177&t=124532 + +Please help by contributing to writing unit tests and submitting a pull request!
\ No newline at end of file diff --git a/tests/setup/config.php b/tests/setup/config.php new file mode 100644 index 0000000..b148f42 --- /dev/null +++ b/tests/setup/config.php @@ -0,0 +1,41 @@ +<?php +define('VERSION', '2.3.0.3_rc'); +define('ADMIN_USERNAME', ''); +define('ADMIN_PASSWORD', ''); + +/* + * Use the $settings array to change store settings. The key must match the store ID. + */ +$settings = array( + 0 => array( + 'config_maintenance' => 1, + ) +); + +/* + * Use the $module_settings array to install payment, shipping or feed modules + */ +$module_settings = array( + 'payment' => array( + 'cheque' => array( + 'cheque_status' => 1, + 'cheque_payable' => 'OpenCart test store', + 'cheque_order_status_id' => 1, + ), + 'free_checkout' => array( + 'free_checkout_status' => 1, + 'free_checkout_order_status_id' => 1, + ), + ), + 'shipping' => array( + 'item' => array( + 'item_status' => 1, + 'item_cost' => 1.25, + ), + ), + 'feed' => array( + 'google_sitemap' => array( + 'google_sitemap_status' => 1 + ) + ), +); diff --git a/tests/setup/install.php b/tests/setup/install.php new file mode 100644 index 0000000..c797739 --- /dev/null +++ b/tests/setup/install.php @@ -0,0 +1,136 @@ +<?php +/** + * Demo install file allows for config and module settings to be set-up using a single setup file. + * + * Designed to be used with build automation services like Jenkins to save time with demo installation sites, no need + * for admin to login to the store and update settings or installing modules manually for each test build. + * + * @todo support for modules & order totals + * @todo create front end demo user account from config (or re-use current selenium test account) + */ + +// Version +define('CONFIG_ADMIN', __DIR__ . '/../../upload/admin/config.php'); +require('./config.php'); + +require(CONFIG_ADMIN); +require(DIR_SYSTEM . 'library/db.php'); +require(DIR_SYSTEM . 'library/db/' . DB_DRIVER . '.php'); + +$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT); + +/** + * Store settings configuration + */ +foreach ($settings as $store_id => $store_settings) { + $query = $db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "'"); + + $old_store_config = array(); + + foreach ($query->rows as $result) { + if ($result['serialized'] == 1) { + $old_store_config[$result['key']] = json_decode($result['value']); + } else { + $old_store_config[$result['key']] = $result['value']; + + } + } + + $new_store_config = array_merge($old_store_config, $store_settings); + + editSetting('config', $new_store_config, $store_id); +} + +// Startup +require_once(DIR_SYSTEM . 'startup.php'); + +// Registry +$registry = new Registry(); + +// Loader +$loader = new Loader($registry); +$registry->set('load', $loader); + +// Request +$request = new Request(); +$registry->set('request', $request); + +// Cache +$cache = new Cache('file'); +$registry->set('cache', $cache); + +// Session +$session = new Session(); +$registry->set('session', $session); + +// Config +$config = new Config(); +$registry->set('config', $config); + +// Database +$registry->set('db', $db); + +// User +$user = new Cart\User($registry); +$user->login(ADMIN_USERNAME, ADMIN_PASSWORD); + +$registry->set('user', $user); + +foreach ($module_settings as $module_settings_type => $module_settings_data) { + $installed_extensions = getInstalledExtension($module_settings_type); + + foreach ($installed_extensions as $remove_extension) { + $loader->controller($module_settings_type . '/' . $remove_extension . '/uninstall'); + deleteSetting($store_id, $remove_extension); + } + + $db->query("DELETE FROM " . DB_PREFIX . "extension WHERE `type` = '" . $db->escape($module_settings_type) . "' AND `code` = '" . $db->escape($remove_extension) . "'"); + + foreach ($module_settings_data as $module_key => $module_data) { + $db->query("INSERT INTO " . DB_PREFIX . "extension SET `type` = '" . $db->escape($module_settings_type) . "', `code` = '" . $db->escape($module_key) . "'"); + + $loader->model('user/user_group'); + + $loader->controller($module_settings_type . '/' . $module_key . '/install'); + + editSetting($module_key, $module_data); + } +} + +echo "Setting update completed\r\n"; + +function deleteSetting($store_id, $code) { + global $db; + + $db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $db->escape($code) . "'"); +} + +function editSetting($code, $data, $store_id = 0) { + global $db; + + $db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $db->escape($code) . "'"); + + foreach ($data as $key => $value) { + if (substr($key, 0, strlen($code)) == $code) { + if (!is_array($value)) { + $db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $db->escape($code) . "', `key` = '" . $db->escape($key) . "', `value` = '" . $db->escape($value) . "'"); + } else { + $db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $db->escape($code) . "', `key` = '" . $db->escape($key) . "', `value` = '" . $db->escape(json_encode($value)) . "', serialized = '1'"); + } + } + } +} + +function getInstalledExtension($type) { + global $db; + + $extension_data = array(); + + $query = $db->query("SELECT * FROM " . DB_PREFIX . "extension WHERE `type` = '" . $db->escape($type) . "' ORDER BY code"); + + foreach ($query->rows as $result) { + $extension_data[] = $result['code']; + } + + return $extension_data; +}
\ No newline at end of file |