-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Taco van Sambeek
committed
Aug 15, 2019
1 parent
e057d8d
commit a0d8d7d
Showing
5 changed files
with
251 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,4 @@ php.ini | |
/composer.lock | ||
/composer.phar | ||
/vendor | ||
/*.zip | ||
/upload/tests/ | ||
/*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
date_default_timezone_set('CET'); | ||
|
||
define("DIR_APPLICATION", realpath(dirname(__FILE__) . "/..")); | ||
define("DIR_SYSTEM", DIR_APPLICATION . "/system"); | ||
define("DIR_TEMPLATE", DIR_APPLICATION . "/catalog/view/theme"); | ||
define("VERSION", '9.0.0'); | ||
|
||
|
||
date_default_timezone_set("Europe/Amsterdam"); | ||
|
||
spl_autoload_register(function($className) | ||
{ | ||
$project_dir = dirname(dirname(__FILE__)); | ||
|
||
$map = array( | ||
"MollieHelper" => "$project_dir/catalog/controller/payment/mollie/helper.php", | ||
"ControllerPaymentMollieBase" => "$project_dir/catalog/controller/payment/mollie/base.php", | ||
"ModelPaymentMollieBase" => "$project_dir/catalog/model/payment/mollie/base.php", | ||
); | ||
|
||
if (isset($map[$className])) | ||
{ | ||
include $map[$className]; | ||
return; | ||
} | ||
|
||
class_alias("stub", $className); | ||
}); | ||
|
||
class stub extends ArrayObject implements ArrayAccess { | ||
public function __isset($name) | ||
{ | ||
return $this->getIterator()->__isset($name); | ||
} | ||
public function __unset($name) | ||
{ | ||
return $this->getIterator()->__unset($name); | ||
} | ||
public function offsetSet ($key, $value) | ||
{ | ||
return $this->getIterator()->offsetSet($key, $value); | ||
} | ||
public function offsetGet ($key) | ||
{ | ||
return $this->getIterator()->offsetGet($key); | ||
} | ||
} | ||
|
||
define("DB_PREFIX", "prefix_"); | ||
|
||
class Mollie_OpenCart_TestCase extends PHPUnit_Framework_TestCase | ||
{ | ||
const CONFIG_PARTNER_ID = 1001; | ||
const CONFIG_PROFILE_KEY = "decafbad"; | ||
const CONFIG_TESTMODE = TRUE; | ||
const CONFIG_DESCRIPTION = "Uw order %"; | ||
const CONFIG_DESCRIPTION_FINAL = "Uw order 1337"; | ||
const CONFIG_SORT_ORDER = 995; | ||
|
||
const URL_PAYMENT = "https://opencart.local/url/payment"; | ||
|
||
const BANK_URL = "https://bankieren.mijnbank.example"; | ||
|
||
const TRANSACTION_ID = "1bba1d8fdbd8103b46151634bdbe0a60"; | ||
|
||
const ORDER_STATUS_SUCCESS_ID = 1; | ||
const ORDER_STATUS_FAILED_ID = 2; | ||
const ORDER_STATUS_PROCESSING_ID = 3; | ||
const ORDER_STATUS_CANCELED_ID = 4; | ||
const ORDER_STATUS_EXPIRED_ID = 5; | ||
|
||
const ORDER_ID = 1337; | ||
|
||
const BANK_ID = "0999"; | ||
|
||
protected static $banks = array( | ||
'1234' => 'Test bank 1', | ||
'0678' => 'Test bank 2' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<phpunit bootstrap="bootstrap.php" backupStaticAttributes="false" colors="true"> | ||
<testsuites> | ||
<testsuite name="Mollie OpenCart"> | ||
<directory>.</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<log type="junit" target="../build/logs/junit-unittests.xml" logIncompleteSkipped="false"/> | ||
<log type="coverage-html" target="../build/coverage" charset="UTF-8" | ||
yui="true" highlight="true" | ||
lowUpperBound="35" highLowerBound="70"/> | ||
<log type="coverage-clover" target="../build/clover/clover-unittests.xml"/> | ||
</logging> | ||
<filter> | ||
<blacklist> | ||
<directory>/usr/share/php</directory> | ||
<directory>.</directory> | ||
<directory>../admin/language</directory> | ||
<directory>../catalog/language</directory> | ||
<directory>../catalog/controller/payment/mollie-api-client</directory> | ||
</blacklist> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory>../admin</directory> | ||
<directory>../catalog</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
89 changes: 89 additions & 0 deletions
89
tests/unittests/catalog/model/ModelPaymentMollieIdealTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
class ModelPaymentMollieIdealTest extends Mollie_OpenCart_TestCase | ||
{ | ||
/** | ||
* @var ModelPaymentMollieIdeal | ||
*/ | ||
protected $model; | ||
|
||
protected $client; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->model = $this->getMock("ModelPaymentMollieBase", array("getAPIClient", "getIssuers", "getCurrentDate")); | ||
$this->model->db = $this->getMock("stub", array("query", "escape", "countAffected")); | ||
|
||
// Mock API client. | ||
$this->client = $this->getMock("stub"); | ||
$this->client_methods = $this->getMock("stub", array("all", "get")); | ||
$this->client->methods = $this->client_methods; | ||
|
||
$this->model | ||
->method("getAPIClient") | ||
->willReturn($this->client); | ||
|
||
// Mock model methods. | ||
$this->model | ||
->method("getCurrentDate") | ||
->will($this->returnValue('2013-05-05 12:12:12')); | ||
|
||
$this->model->db | ||
->method("escape") | ||
->will($this->returnCallback(function ($arg0) | ||
{ | ||
return addslashes($arg0); | ||
})); | ||
|
||
$this->model->load = $this->getMock("stdClass", array("model", "language")); | ||
|
||
$this->model->language = $this->getMock("stub", array("get")); | ||
$this->model->language->expects($this->any()) | ||
->method("get") | ||
->will($this->returnArgument(0)); | ||
|
||
$this->model->config = $this->getMock("stdClass", array("get")); | ||
$this->model->config->expects($this->any()) | ||
->method("get") | ||
->will($this->returnValueMap(array( | ||
array("mollie_ideal_sort_order", self::CONFIG_SORT_ORDER), | ||
))); | ||
|
||
$this->model->url = $this->getMock("stub", array("link")); | ||
} | ||
|
||
public function testSetPaymentReturnsFalseIfArgumentsOmitted() | ||
{ | ||
$this->assertFalse($this->model->setPayment(NULL, NULL)); | ||
} | ||
|
||
public function testSetPaymentNothingAffected() | ||
{ | ||
$this->model->db->expects($this->once()) | ||
->method("query") | ||
->with("REPLACE INTO `prefix_mollie_payments` (`order_id` ,`mollie_order_id`, `method`) | ||
VALUES ('1337', '1bba1d8fdbd8103b46151634bdbe0a60', 'idl')"); | ||
|
||
$this->model->db->expects($this->once()) | ||
->method("countAffected") | ||
->will($this->returnValue(0)); | ||
|
||
$this->assertFalse($this->model->setPayment(self::ORDER_ID, self::TRANSACTION_ID)); | ||
} | ||
|
||
public function testSetPaymentPaymentSet() | ||
{ | ||
$this->model->db->expects($this->once()) | ||
->method("query") | ||
->with("REPLACE INTO `prefix_mollie_payments` (`order_id` ,`mollie_order_id`, `method`) | ||
VALUES ('1337', '1bba1d8fdbd8103b46151634bdbe0a60', 'idl')"); | ||
|
||
$this->model->db->expects($this->once()) | ||
->method("countAffected") | ||
->will($this->returnValue(1)); | ||
|
||
$this->assertTrue($this->model->setPayment(self::ORDER_ID, self::TRANSACTION_ID)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
class TranslationTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private static $LANGUAGES = array("dutch", "english", "french", "nl-nl", "en-gb", "fr-fr"); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $keys = array(); | ||
|
||
/** | ||
* @param $orig_path | ||
* | ||
* @dataProvider dpTranslationPaths | ||
*/ | ||
public function testTranslationFilesHaveIdenticalKeys($orig_path) | ||
{ | ||
$path = $orig_path . DIRECTORY_SEPARATOR . "language"; | ||
|
||
$keys = array(); | ||
|
||
foreach (self::$LANGUAGES as $language) | ||
{ | ||
$lang_path = $path . | ||
DIRECTORY_SEPARATOR . $language . | ||
DIRECTORY_SEPARATOR . "payment" . | ||
DIRECTORY_SEPARATOR . "mollie.php"; | ||
$_ = array(); | ||
|
||
include $lang_path; | ||
|
||
$keys[$language] = array_keys($_); | ||
} | ||
|
||
self::$keys[$orig_path] = $keys; | ||
|
||
$diff = call_user_func_array("array_diff", $keys); | ||
$this->assertCount(0, $diff); | ||
} | ||
|
||
public function dpTranslationPaths() | ||
{ | ||
return array( | ||
array(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "admin"), | ||
array(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "catalog"), | ||
); | ||
} | ||
} |