-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #664 from magento-api/API-Sprint-58-Bugs-and-Tests
[API] Sprint 58 Bug Fixes and Test Coverage
- Loading branch information
Showing
23 changed files
with
1,436 additions
and
299 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
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
130 changes: 130 additions & 0 deletions
130
app/code/Magento/EncryptionKey/Test/Unit/Controller/Adminhtml/Crypt/Key/SaveTest.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,130 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\EncryptionKey\Test\Unit\Controller\Adminhtml\Crypt\Key; | ||
|
||
/** | ||
* Test class for Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key\Save | ||
*/ | ||
class SaveTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \Magento\Framework\Encryption\EncryptorInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $encryptMock; | ||
/** @var \Magento\EncryptionKey\Model\Resource\Key\Change|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $changeMock; | ||
/** @var \Magento\Framework\App\CacheInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $cacheMock; | ||
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $requestMock; | ||
/** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $managerMock; | ||
/** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $responseMock; | ||
/** @var \Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key\Save */ | ||
protected $model; | ||
|
||
public function setUp() | ||
{ | ||
$this->encryptMock = $this->getMockBuilder('Magento\Framework\Encryption\EncryptorInterface') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->changeMock = $this->getMockBuilder('Magento\EncryptionKey\Model\Resource\Key\Change') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') | ||
->disableOriginalConstructor() | ||
->setMethods(['getPost']) | ||
->getMockForAbstractClass(); | ||
$this->managerMock = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') | ||
->disableOriginalConstructor() | ||
->setMethods(['setRedirect']) | ||
->getMockForAbstractClass(); | ||
|
||
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
|
||
$this->model = $helper->getObject( | ||
'Magento\EncryptionKey\Controller\Adminhtml\Crypt\Key\Save', | ||
[ | ||
'encryptor' => $this->encryptMock, | ||
'change' => $this->changeMock, | ||
'cache' => $this->cacheMock, | ||
'request' => $this->requestMock, | ||
'messageManager' => $this->managerMock, | ||
'response' => $this->responseMock, | ||
] | ||
); | ||
} | ||
|
||
public function testExecuteNonRandomAndWithCryptKey() | ||
{ | ||
$expectedMessage = 'The encryption key has been changed.'; | ||
$key = 1; | ||
$newKey = 'RSASHA9000VERYSECURESUPERMANKEY'; | ||
$this->requestMock | ||
->expects($this->at(0)) | ||
->method('getPost') | ||
->with($this->equalTo('generate_random')) | ||
->willReturn(0); | ||
$this->requestMock | ||
->expects($this->at(1)) | ||
->method('getPost') | ||
->with($this->equalTo('crypt_key')) | ||
->willReturn($key); | ||
$this->encryptMock->expects($this->once())->method('validateKey'); | ||
$this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey); | ||
$this->managerMock->expects($this->once())->method('addSuccessMessage')->with($expectedMessage); | ||
$this->cacheMock->expects($this->once())->method('clean'); | ||
$this->responseMock->expects($this->once())->method('setRedirect'); | ||
|
||
$this->model->execute(); | ||
} | ||
|
||
public function testExecuteNonRandomAndWithoutCryptKey() | ||
{ | ||
$key = null; | ||
$this->requestMock | ||
->expects($this->at(0)) | ||
->method('getPost') | ||
->with($this->equalTo('generate_random')) | ||
->willReturn(0); | ||
$this->requestMock | ||
->expects($this->at(1)) | ||
->method('getPost') | ||
->with($this->equalTo('crypt_key')) | ||
->willReturn($key); | ||
$this->managerMock->expects($this->once())->method('addErrorMessage'); | ||
|
||
$this->model->execute(); | ||
} | ||
|
||
public function testExecuteRandom() | ||
{ | ||
$newKey = 'RSASHA9000VERYSECURESUPERMANKEY'; | ||
$this->requestMock | ||
->expects($this->at(0)) | ||
->method('getPost') | ||
->with($this->equalTo('generate_random')) | ||
->willReturn(1); | ||
$this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey); | ||
$this->managerMock->expects($this->once())->method('addSuccessMessage'); | ||
$this->managerMock->expects($this->once())->method('addNoticeMessage'); | ||
$this->cacheMock->expects($this->once())->method('clean'); | ||
$this->responseMock->expects($this->once())->method('setRedirect'); | ||
|
||
$this->model->execute(); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
app/code/Magento/EncryptionKey/Test/Unit/Model/Resource/Key/ChangeTest.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,130 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\EncryptionKey\Test\Unit\Model\Resource\Key; | ||
|
||
/** | ||
* Test Class For Magento\EncryptionKey\Model\Resource\Key\Change | ||
*/ | ||
class ChangeTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \Magento\Framework\Encryption\EncryptorInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $encryptMock; | ||
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $filesystemMock; | ||
/** @var \Magento\Config\Model\Config\Structure|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $structureMock; | ||
/** @var \Magento\Framework\App\DeploymentConfig\Writer|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $writerMock; | ||
/** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $adapterMock; | ||
/** @var \Magento\Framework\App\Resource|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $resourceMock; | ||
/** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $selectMock; | ||
/** @var \Magento\Framework\Model\Resource\Db\TransactionManagerInterface */ | ||
protected $tansactionMock; | ||
/** @var \Magento\Framework\Model\Resource\Db\ObjectRelationProcessor|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $objRelationMock; | ||
/** @var \Magento\EncryptionKey\Model\Resource\Key\Change */ | ||
protected $model; | ||
|
||
public function setUp() | ||
{ | ||
$this->encryptMock = $this->getMockBuilder('Magento\Framework\Encryption\EncryptorInterface') | ||
->disableOriginalConstructor() | ||
->setMethods(['setNewKey', 'exportKeys']) | ||
->getMockForAbstractClass(); | ||
$this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->structureMock = $this->getMockBuilder('Magento\Config\Model\Config\Structure') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->writerMock = $this->getMockBuilder('Magento\Framework\App\DeploymentConfig\Writer') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->adapterMock = $this->getMockBuilder('Magento\Framework\DB\Adapter\AdapterInterface') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->selectMock = $this->getMockBuilder('Magento\Framework\DB\Select') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->tansactionMock = $this->getMockBuilder('Magento\Framework\Model\Resource\Db\TransactionManagerInterface') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
$this->objRelationMock = $this->getMockBuilder('Magento\Framework\Model\Resource\Db\ObjectRelationProcessor') | ||
->disableOriginalConstructor() | ||
->setMethods([]) | ||
->getMock(); | ||
|
||
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
|
||
$this->model = $helper->getObject( | ||
'Magento\EncryptionKey\Model\Resource\Key\Change', | ||
[ | ||
'filesystem' => $this->filesystemMock, | ||
'structure' => $this->structureMock, | ||
'encryptor' => $this->encryptMock, | ||
'writer' => $this->writerMock, | ||
'adapterInterface' => $this->adapterMock, | ||
'resource' => $this->resourceMock, | ||
'transactionManager' => $this->tansactionMock, | ||
'relationProcessor' => $this->objRelationMock | ||
] | ||
); | ||
} | ||
|
||
public function testChangeEncryptionKey() | ||
{ | ||
$paths = ['path1', 'path2']; | ||
$table = ['item1', 'item2']; | ||
$values = [ | ||
'key1' => 'value1', | ||
'key2' => 'value2' | ||
]; | ||
$key = 'key'; | ||
|
||
$this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(true); | ||
$this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->adapterMock); | ||
$this->adapterMock->expects($this->once())->method('beginTransaction'); | ||
$this->structureMock->expects($this->once())->method('getFieldPathsByAttribute')->willReturn($paths); | ||
$this->resourceMock->expects($this->atLeastOnce())->method('getTableName')->willReturn($table); | ||
$this->adapterMock->expects($this->any())->method('select')->willReturn($this->selectMock); | ||
$this->adapterMock->expects($this->any())->method('fetchPairs')->willReturn($values); | ||
$this->selectMock->expects($this->any())->method('from')->willReturnSelf(); | ||
$this->selectMock->expects($this->atLeastOnce())->method('where')->willReturnSelf(); | ||
$this->selectMock->expects($this->any())->method('update')->willReturnSelf(); | ||
$this->writerMock->expects($this->once())->method('saveConfig'); | ||
$this->adapterMock->expects($this->once())->method('getTransactionLevel')->willReturn(1); | ||
|
||
$this->assertEquals($key, $this->model->changeEncryptionKey($key)); | ||
} | ||
|
||
public function testChangeEncryptionKeyThrowsException() | ||
{ | ||
$key = 'key'; | ||
$this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(false); | ||
|
||
try { | ||
$this->model->changeEncryptionKey($key); | ||
} catch (\Exception $e) { | ||
return; | ||
} | ||
|
||
$this->fail('An excpected exception was not signaled.'); | ||
} | ||
} |
Oops, something went wrong.