1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* PHP version 5 |
18
|
|
|
* |
19
|
|
|
* @category Payone |
20
|
|
|
* @package Payone_Magento2_Plugin |
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
22
|
|
|
* @copyright 2003 - 2017 Payone GmbH |
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
24
|
|
|
* @link http://www.payone.de |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace Payone\Core\Test\Unit\Controller\Adminhtml\Config\Export; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Controller\Adminhtml\Config\Export\Index as ClassToTest; |
30
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
31
|
|
|
use Magento\Backend\App\Action\Context; |
32
|
|
|
use Magento\Framework\View\Result\PageFactory; |
33
|
|
|
use Magento\Framework\View\Result\Page; |
34
|
|
|
use Magento\Framework\View\Page\Config; |
35
|
|
|
use Magento\Framework\View\Page\Title; |
36
|
|
|
use Magento\Framework\AuthorizationInterface; |
37
|
|
|
use Payone\Core\Model\Config\Export; |
38
|
|
|
use Magento\Framework\Controller\Result\RawFactory; |
39
|
|
|
use Magento\Framework\Controller\Result\Raw; |
40
|
|
|
|
41
|
|
|
class IndexTest extends \PHPUnit_Framework_TestCase |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @var ClassToTest |
45
|
|
|
*/ |
46
|
|
|
private $classToTest; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var ObjectManager |
50
|
|
|
*/ |
51
|
|
|
private $objectManager; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var Export|\PHPUnit_Framework_MockObject_MockObject |
55
|
|
|
*/ |
56
|
|
|
private $configExport; |
57
|
|
|
|
58
|
|
|
protected function setUp() |
59
|
|
|
{ |
60
|
|
|
$this->objectManager = new ObjectManager($this); |
61
|
|
|
|
62
|
|
|
$authorization = $this->getMockBuilder(AuthorizationInterface::class)->disableOriginalConstructor()->getMock(); |
63
|
|
|
$authorization->method('isAllowed')->willReturn(true); |
64
|
|
|
|
65
|
|
|
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); |
66
|
|
|
$context->method('getAuthorization')->willReturn($authorization); |
67
|
|
|
|
68
|
|
|
$this->configExport = $this->getMockBuilder(Export::class)->disableOriginalConstructor()->getMock(); |
69
|
|
|
|
70
|
|
|
$raw = $this->getMockBuilder(Raw::class)->disableOriginalConstructor()->getMock(); |
71
|
|
|
|
72
|
|
|
$resultRawFactory = $this->getMockBuilder(RawFactory::class) |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->setMethods(['create']) |
75
|
|
|
->getMock(); |
76
|
|
|
$resultRawFactory->method('create')->willReturn($raw); |
77
|
|
|
|
78
|
|
|
$this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
79
|
|
|
'context' => $context, |
80
|
|
|
'configExport' => $this->configExport, |
81
|
|
|
'resultRawFactory' => $resultRawFactory |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testExecute() |
86
|
|
|
{ |
87
|
|
|
$this->configExport->method('generateConfigExportXml')->willReturn('export xml'); |
88
|
|
|
|
89
|
|
|
$result = $this->classToTest->execute(); |
90
|
|
|
$this->assertInstanceOf(Raw::class, $result); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testExecuteException() |
94
|
|
|
{ |
95
|
|
|
$exception = new \Exception(); |
96
|
|
|
$this->configExport->method('generateConfigExportXml')->willThrowException($exception); |
97
|
|
|
|
98
|
|
|
$result = $this->classToTest->execute(); |
99
|
|
|
$this->assertInstanceOf(Raw::class, $result); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|