Skip to content

Commit

Permalink
Merge pull request #247 from formapro-forks/token-factory-must-accept…
Browse files Browse the repository at this point in the history
…-identificator

[security] token factory should accept identificator.
  • Loading branch information
makasim committed Nov 11, 2014
2 parents ab1bbef + 38a1bc1 commit 75c0b04
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Security/AbstractGenericTokenFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Payum\Core\Security;

use Payum\Core\Model\Identificator;
use Payum\Core\Registry\StorageRegistryInterface;
use Payum\Core\Storage\StorageInterface;

Expand Down Expand Up @@ -58,10 +59,10 @@ public function createToken($paymentName, $model, $targetPath, array $targetPara

$token->setPaymentName($paymentName);

if (null !== $model) {
$token->setDetails(
$this->storageRegistry->getStorage($model)->getIdentificator($model)
);
if ($model instanceof Identificator) {
$token->setDetails($model);
} else if (null !== $model) {
$token->setDetails($this->storageRegistry->getStorage($model)->getIdentificator($model));
}

$targetParameters = array_replace($targetParameters, array('payum_token' => $token->getHash()));
Expand Down
50 changes: 50 additions & 0 deletions Tests/Security/GenericTokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,56 @@ public function shouldCreateCustomToken()
$this->assertEquals('http://example.com/theAfterPath?afterPathKey=afterPathVal', $token->getAfterUrl());
}

/**
* @test
*/
public function shouldCreateCustomTokenWithIdentificatorAsModel()
{
$token = new Token;

$tokenStorageMock = $this->createStorageMock();
$tokenStorageMock
->expects($this->once())
->method('createModel')
->will($this->returnValue($token))
;
$tokenStorageMock
->expects($this->once())
->method('updateModel')
->with($this->identicalTo($token))
;

$paymentName = 'thePaymentName';
$identificator = new Identificator('anId', 'stdClass');

$storageRegistryMock = $this->createStorageRegistryMock();
$storageRegistryMock
->expects($this->never())
->method('getStorage')
;

$factory = new GenericTokenFactory(
$tokenStorageMock,
$storageRegistryMock,
'http://example.com',
'capture.php',
'notify.php',
'authorize.php'
);

$actualToken = $factory->createToken(
$paymentName,
$identificator,
'theTargetPath',
array('targetPathKey' => 'targetPathVal'),
'theAfterPath',
array('afterPathKey' => 'afterPathVal')
);

$this->assertSame($token, $actualToken);
$this->assertSame($identificator, $token->getDetails());
}

/**
* @test
*/
Expand Down

0 comments on commit 75c0b04

Please sign in to comment.