Skip to content

Commit

Permalink
Merge pull request #61 from lrqdo/check_alias_max_length
Browse files Browse the repository at this point in the history
Make sure Ecommerce Alias is not too long
  • Loading branch information
jelte committed May 6, 2016
2 parents a314e13 + 058be40 commit 79acf5d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "marlon-be/marlon-ogone",
"autoload": {
"psr-0": { "Ogone": "lib/" }
"psr-4": {
"Ogone\\": "lib/Ogone/",
"Ogone\\Tests\\": "tests/Ogone/Tests/"
}
},
"require": {
"php": ">=5.3"
Expand Down
4 changes: 4 additions & 0 deletions lib/Ogone/Ecommerce/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Alias

public function __construct($alias, $aliasOperation = self::OPERATION_BY_MERCHANT, $aliasUsage = null)
{
if (strlen($alias) > 50) {
throw new InvalidArgumentException("Alias is too long");
}

if (preg_match('/[^a-zA-Z0-9_-]/', $alias)) {
throw new InvalidArgumentException("Alias cannot contain special characters");
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Ogone/Tests/Ecommerce/AliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function AliasCanHaveOperationByPsp()
$this->assertEquals(Alias::OPERATION_BY_PSP, $alias->getAliasOperation());
}

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function AliasIsMax50Characters()
{
new Alias(str_repeat('X', 51));
}

/**
* @test
* @expectedException \InvalidArgumentException
Expand Down
3 changes: 0 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
use Ogone\DirectLink\DirectLinkPaymentRequest;
use Ogone\DirectLink\DirectLinkQueryRequest;

require_once 'PHPUnit/Framework/TestCase.php';
require_once __DIR__.'/Ogone/Tests/ShaComposer/FakeShaComposer.php';

abstract class TestCase extends PHPUnit_Framework_TestCase
{
/** @return EcommercePaymentRequest*/
Expand Down

0 comments on commit 79acf5d

Please sign in to comment.