From 38a1bc1737753978513cbcf6ee3276a099253fe8 Mon Sep 17 00:00:00 2001 From: Kotlyar Maksim Date: Tue, 11 Nov 2014 13:53:39 +0000 Subject: [PATCH] [security] token factory should accept identificator. --- Security/AbstractGenericTokenFactory.php | 9 ++-- Tests/Security/GenericTokenFactoryTest.php | 50 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Security/AbstractGenericTokenFactory.php b/Security/AbstractGenericTokenFactory.php index bb29dc5..efe05b6 100644 --- a/Security/AbstractGenericTokenFactory.php +++ b/Security/AbstractGenericTokenFactory.php @@ -1,6 +1,7 @@ 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())); diff --git a/Tests/Security/GenericTokenFactoryTest.php b/Tests/Security/GenericTokenFactoryTest.php index 2fe925b..58aa533 100644 --- a/Tests/Security/GenericTokenFactoryTest.php +++ b/Tests/Security/GenericTokenFactoryTest.php @@ -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 */