-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,709 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ composer.lock | |
/node_modules/* | ||
package-lock.json | ||
/test-reports/* | ||
clover.xml | ||
/test-coverage-html/* |
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
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
113 changes: 113 additions & 0 deletions
113
Test/Unit/Block/Adminhtml/Customer/Edit/ResetTFAButtonTest.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,113 @@ | ||
<?php | ||
/** | ||
* @author The S Group <support@sashas.org> | ||
* @copyright 2020 Sashas IT Support Inc. (https://www.sashas.org) | ||
* @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3 (GPL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magetarian\CustomerTwoFactorAuth\Test\Unit\Block\Adminhtml\Customer\Edit; | ||
|
||
use Magetarian\CustomerTwoFactorAuth\Api\ProviderPoolInterface; | ||
use Magetarian\CustomerTwoFactorAuth\Block\Adminhtml\Customer\Edit\ResetTFAButton; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\Registry; | ||
use Magento\Backend\Block\Widget\Context; | ||
use Magento\Framework\Phrase; | ||
|
||
/** | ||
* Class ResetTFAButtonTest | ||
* Test for ResetTFAButtonTest class | ||
*/ | ||
class ResetTFAButtonTest extends TestCase | ||
{ | ||
|
||
/** @var ResetTFAButton object */ | ||
private $object; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $urlBuilder; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $providerPool; | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetResetUrl() | ||
{ | ||
$result = 'customer_tfa/customer/reset/customer_id/1'; | ||
|
||
$this->registry->expects($this->atLeastOnce())->method('registry')->willReturn(1); | ||
$this->urlBuilder->expects($this->atLeastOnce())->method('getUrl')->willReturn($result); | ||
|
||
$this->assertEquals($result, $this->object->getResetUrl()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetButtonData() | ||
{ | ||
$result = [ | ||
'label' => new Phrase('Reset TFA'), | ||
'id' => 'customer-reset-tfa-button', | ||
'on_click' => "location.href = 'test';", | ||
'class' => 'add', | ||
'aclResource' => 'Magetarian_CustomerTwoFactorAuth::reset_tfa', | ||
'sort_order' => 100 | ||
]; | ||
|
||
$this->registry->expects($this->atLeastOnce())->method('registry')->willReturn(1); | ||
$this->urlBuilder->expects($this->atLeastOnce())->method('getUrl')->willReturn('test'); | ||
$this->providerPool->expects($this->atLeastOnce())->method('getEnabledProviders')->willReturn(['test']); | ||
|
||
$this->assertEquals($result, $this->object->getButtonData()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->registry = $this->getMockBuilder(Registry::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->context = $this->getMockBuilder(Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->providerPool = $this->getMockBuilder(ProviderPoolInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->context->expects($this->atLeastOnce())->method('getUrlBuilder')->willReturn($this->urlBuilder); | ||
|
||
$this->object = (new ObjectManager($this))->getObject( | ||
ResetTFAButton::class, | ||
[ | ||
'context' => $this->context, | ||
'registry' => $this->registry, | ||
'providerPool' => $this->providerPool | ||
] | ||
); | ||
} | ||
} |
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,146 @@ | ||
<?php | ||
/** | ||
* @author The S Group <support@sashas.org> | ||
* @copyright 2020 Sashas IT Support Inc. (https://www.sashas.org) | ||
* @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3 (GPL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magetarian\CustomerTwoFactorAuth\Test\Unit\Controller\Adminhtml\Customer; | ||
|
||
use Magento\Backend\App\Action\Context; | ||
use Magetarian\CustomerTwoFactorAuth\Api\ProviderPoolInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\Result\RedirectFactory; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Message\ManagerInterface; | ||
use Magetarian\CustomerTwoFactorAuth\Api\ProviderInterface; | ||
|
||
/** | ||
* Class ResetTest | ||
* Test for ResetTest class | ||
*/ | ||
class ResetTest extends TestCase | ||
{ | ||
|
||
/** @var Reset object */ | ||
private $object; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $providerPool; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $resultRedirectFactory; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $messageManager; | ||
|
||
/** | ||
* @dataProvider dataProviderExecute | ||
*/ | ||
public function testExecute($customerId) | ||
{ | ||
$resultRedirect = $this->getMockBuilder(Redirect::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$provider = $this->getMockBuilder(ProviderInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$resultRedirect->expects($this->atLeastOnce())->method('setPath')->willReturn($resultRedirect); | ||
$this->resultRedirectFactory->expects($this->atLeastOnce())->method('create')->willReturn($resultRedirect); | ||
$this->request->expects($this->atLeastOnce())->method('getParam')->willReturn($customerId); | ||
if ($customerId) { | ||
$provider->expects($this->atLeastOnce())->method('resetConfiguration'); | ||
$this->providerPool->expects($this->atLeastOnce())->method('getProviders')->willReturn([$provider]); | ||
$this->messageManager->expects($this->atLeastOnce())->method('addSuccessMessage'); | ||
} else { | ||
$this->providerPool->expects($this->never())->method('getProviders'); | ||
$this->messageManager->expects($this->never())->method('addSuccessMessage'); | ||
} | ||
|
||
$this->assertEquals($resultRedirect, $this->object->execute()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testExecuteException() | ||
{ | ||
$resultRedirect = $this->getMockBuilder(Redirect::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$resultRedirect->expects($this->atLeastOnce())->method('setPath')->willReturn($resultRedirect); | ||
$this->resultRedirectFactory->expects($this->atLeastOnce())->method('create')->willReturn($resultRedirect); | ||
|
||
$this->request->expects($this->atLeastOnce())->method('getParam')->willReturn(1); | ||
$this->providerPool->expects($this->atLeastOnce())->method('getProviders') | ||
->willThrowException(new \Exception('test')); | ||
$this->messageManager->expects($this->atLeastOnce())->method('addExceptionMessage'); | ||
$this->messageManager->expects($this->never())->method('addSuccessMessage'); | ||
|
||
$this->assertEquals($resultRedirect, $this->object->execute()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function dataProviderExecute(): array | ||
{ | ||
return [ | ||
[1], | ||
[false], | ||
]; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->providerPool = $this->getMockBuilder(ProviderPoolInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->context = $this->getMockBuilder(Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->resultRedirectFactory = $this->getMockBuilder(RedirectFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->request = $this->getMockBuilder(RequestInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->messageManager = $this->getMockBuilder(ManagerInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->context->expects($this->any())->method('getResultRedirectFactory') | ||
->willReturn($this->resultRedirectFactory); | ||
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request); | ||
$this->context->expects($this->any())->method('getMessageManager')->willReturn($this->messageManager); | ||
$this->object = (new ObjectManager($this))->getObject( | ||
Reset::class, | ||
[ | ||
'context' => $this->context, | ||
'providerPool' => $this->providerPool, | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.