-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from yii-cms/tests
basic tests
- Loading branch information
Showing
10 changed files
with
355 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# phpstorm project files | ||
.idea | ||
|
||
# netbeans project files | ||
nbproject | ||
|
||
# zend studio for eclipse project files | ||
.buildpath | ||
.project | ||
.settings | ||
|
||
# windows thumbnail cache | ||
Thumbs.db | ||
|
||
# composer vendor dir | ||
/vendor | ||
|
||
/composer.lock | ||
|
||
# composer itself is not needed | ||
composer.phar | ||
|
||
# Mac DS_Store Files | ||
.DS_Store | ||
|
||
# phpunit itself is not needed | ||
phpunit.phar | ||
# local phpunit config | ||
/phpunit.xml | ||
|
||
# local tests configuration | ||
/tests/data/config.local.php | ||
|
||
# runtime cache | ||
/tests/runtime |
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,31 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
sudo: true | ||
|
||
# cache vendor dirs | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
install: | ||
- travis_retry composer self-update && composer --version | ||
- export PATH="$HOME/.composer/vendor/bin:$PATH" | ||
- travis_retry composer install --prefer-dist --no-interaction | ||
|
||
script: | ||
- phpunit --verbose $PHPUNIT_FLAGS | ||
|
||
after_script: | ||
- | | ||
if [ $TRAVIS_PHP_VERSION = '5.6' ]; then | ||
cd ../../.. | ||
travis_retry wget https://scrutinizer-ci.com/ocular.phar | ||
php ocular.phar code-coverage:upload --format=php-clover coverage.clover | ||
fi |
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
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
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
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Yii2 Robokassa Test Suite"> | ||
<directory>./tests/unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">.</directory> | ||
<exclude> | ||
<directory suffix=".php">vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,17 @@ | ||
<?php | ||
|
||
error_reporting(E_ALL); | ||
|
||
define('YII_ENABLE_ERROR_HANDLER', false); | ||
define('YII_DEBUG', true); | ||
|
||
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; | ||
$_SERVER['SCRIPT_FILENAME'] = __FILE__; | ||
|
||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); | ||
|
||
Yii::setAlias('@robokassa/tests/unit', __DIR__ . '/unit'); | ||
Yii::setAlias('@robokassa', dirname(__DIR__)); | ||
|
||
require_once(__DIR__ . '/compatibility.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,51 @@ | ||
<?php | ||
|
||
/* | ||
* Ensures compatibility with PHPUnit < 6.x | ||
*/ | ||
namespace PHPUnit\Framework\Constraint { | ||
if (!class_exists('PHPUnit\Framework\Constraint\Constraint') && class_exists('PHPUnit_Framework_Constraint')) { | ||
abstract class Constraint extends \PHPUnit_Framework_Constraint {} | ||
} | ||
} | ||
|
||
namespace PHPUnit\Framework { | ||
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) { | ||
abstract class TestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @param string $exception | ||
*/ | ||
public function expectException($exception) | ||
{ | ||
$this->setExpectedException($exception); | ||
} | ||
|
||
/** | ||
* @param string $message | ||
*/ | ||
public function expectExceptionMessage($message) | ||
{ | ||
$parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); | ||
if (in_array('expectExceptionMessage', $parentClassMethods)) { | ||
parent::expectExceptionMessage($message); | ||
return; | ||
} | ||
$this->setExpectedException($this->getExpectedException(), $message); | ||
} | ||
|
||
/** | ||
* @param string $messageRegExp | ||
*/ | ||
public function expectExceptionMessageRegExp($messageRegExp) | ||
{ | ||
$parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase'); | ||
if (in_array('expectExceptionMessageRegExp', $parentClassMethods)) { | ||
parent::expectExceptionMessageRegExp($messageRegExp); | ||
return; | ||
} | ||
$this->setExpectedExceptionRegExp($this->getExpectedException(), $messageRegExp); | ||
} | ||
} | ||
} | ||
} |
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,94 @@ | ||
<?php | ||
namespace robokassa\tests\unit; | ||
|
||
use robokassa\Merchant; | ||
|
||
class MerchantTest extends TestCase | ||
{ | ||
public function testRedirectUrl() | ||
{ | ||
$merchant = new Merchant([ | ||
'sMerchantLogin' => 'demo', | ||
'sMerchantPass1' => 'password_1', | ||
'hashAlgo' => 'md5', | ||
'isTest' => true, | ||
]); | ||
|
||
$returnUrl = $merchant->payment(100, 1, 'Description', null, null, 'en', [], true); | ||
|
||
$this->assertEquals("https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin=demo&OutSum=100&InvId=1&Desc=Description&SignatureValue=8a50b8d86ed28921edfc371cff6e156f&Culture=en&IsTest=1", $returnUrl); | ||
|
||
// disable test | ||
$merchant->isTest = false; | ||
|
||
$returnUrl = $merchant->payment(100, 1, 'Description', null, null, 'en', [], true); | ||
|
||
$this->assertEquals("https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin=demo&OutSum=100&InvId=1&Desc=Description&SignatureValue=8a50b8d86ed28921edfc371cff6e156f&Culture=en", $returnUrl); | ||
} | ||
|
||
public function testSignature() | ||
{ | ||
$merchant = new Merchant([ | ||
'sMerchantLogin' => 'demo', | ||
'sMerchantPass1' => 'password_1', | ||
'hashAlgo' => 'md5', | ||
'isTest' => true, | ||
]); | ||
|
||
$signature = md5('100:1:pass1'); // '1e8f0be69238c13020beba0206951535' | ||
|
||
$check = $merchant->checkSignature($signature, 100, 1, 'pass1'); | ||
|
||
$this->assertInternalType('boolean', $check); | ||
|
||
$this->assertTrue($check); | ||
} | ||
|
||
public function testSignatureUserParams() | ||
{ | ||
$merchant = new Merchant([ | ||
'sMerchantLogin' => 'demo', | ||
'sMerchantPass1' => 'password_1', | ||
'hashAlgo' => 'md5', | ||
'isTest' => true, | ||
]); | ||
|
||
$signature = md5('100:1:pass1:shp_id=1:shp_login=user1'); // 'd2b1beae30b0c2586eb4b4a7ce23aedd' | ||
|
||
$this->assertTrue($merchant->checkSignature($signature, 100, 1, 'pass1', [ | ||
'shp_id' => 1, | ||
'shp_login' => 'user1', | ||
])); | ||
} | ||
|
||
public function testSignatureInvalidSortUserParams() | ||
{ | ||
$merchant = new Merchant([ | ||
'sMerchantLogin' => 'demo', | ||
'sMerchantPass1' => 'password_1', | ||
'hashAlgo' => 'md5', | ||
'isTest' => true, | ||
]); | ||
|
||
$signatureInvalidSort = md5('100:1:pass1:shp_login=user1:shp_id=1'); | ||
|
||
$this->assertFalse($merchant->checkSignature($signatureInvalidSort, 100, 1, 'pass1', [ | ||
'shp_id' => 1, | ||
'shp_login' => 'user1', | ||
])); | ||
} | ||
|
||
public function testSignatureAlgo() | ||
{ | ||
$merchant = new Merchant([ | ||
'sMerchantLogin' => 'demo', | ||
'sMerchantPass1' => 'password_1', | ||
'hashAlgo' => 'sha256', // <=== 'sha256' | ||
'isTest' => true, | ||
]); | ||
|
||
$signature = hash('sha256', '100:1:pass1'); | ||
|
||
$this->assertTrue($merchant->checkSignature($signature, 100, 1, 'pass1')); | ||
} | ||
} |
Oops, something went wrong.