Skip to content

Commit

Permalink
Make sure Ecommerce Alias is not too long
Browse files Browse the repository at this point in the history
There is a check already for DirectLink Alias, but it was missing for
Ecommerce Alias.
  • Loading branch information
nclavaud committed Mar 25, 2016
1 parent a314e13 commit 60c71fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 60c71fb

Please sign in to comment.