Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CcConfigTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class CcConfigTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $model;
14 
16  protected $configMock;
17 
19  protected $repositoryMock;
20 
22  protected $requestMock;
23 
25  protected $urlMock;
26 
28  protected $loggerMock;
29 
30  protected function setUp()
31  {
32  $this->configMock = $this->createMock(\Magento\Payment\Model\Config::class);
33  $this->repositoryMock = $this->createMock(\Magento\Framework\View\Asset\Repository::class);
34  $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
35  $this->urlMock = $this->createMock(\Magento\Framework\UrlInterface::class);
36  $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
37 
38  $this->model = new \Magento\Payment\Model\CcConfig(
39  $this->configMock,
40  $this->repositoryMock,
41  $this->requestMock,
42  $this->urlMock,
43  $this->loggerMock
44  );
45  }
46 
47  public function testGetCcAvailableTypes()
48  {
49  $data = [1, 2, 3];
50  $this->configMock->expects($this->once())
51  ->method('getCcTypes')
52  ->willReturn($data);
53 
54  $this->assertEquals($data, $this->model->getCcAvailableTypes());
55  }
56 
57  public function testGetCcMonths()
58  {
59  $data = [1, 2, 3];
60  $this->configMock->expects($this->once())
61  ->method('getMonths')
62  ->willReturn($data);
63 
64  $this->assertEquals($data, $this->model->getCcMonths());
65  }
66 
67  public function testGetCcYears()
68  {
69  $data = [1, 2, 3];
70  $this->configMock->expects($this->once())
71  ->method('getYears')
72  ->willReturn($data);
73 
74  $this->assertEquals($data, $this->model->getCcYears());
75  }
76 
77  public function testHasVerification()
78  {
79  $this->assertEquals(true, $this->model->hasVerification());
80  }
81 
82  public function testGetCvvImageUrl()
83  {
84  $params = ['_secure' => true];
85  $fileId = 'Magento_Checkout::cvv.png';
86  $fileUrl = 'file url';
87 
88  $this->requestMock->expects($this->once())
89  ->method('isSecure')
90  ->willReturn(true);
91 
92  $this->repositoryMock->expects($this->once())
93  ->method('getUrlWithParams')
94  ->with($fileId, $params)
95  ->willReturn($fileUrl);
96 
97  $this->assertEquals($fileUrl, $this->model->getCvvImageUrl());
98  }
99 
100  public function getViewFileUrlWithException()
101  {
102  $params = ['a' => 'b'];
103  $paramsSecure = ['a' => 'b', '_secure' => false];
104  $fileId = 'file id';
105  $fileUrl = 'exception url';
106 
107  $this->requestMock->expects($this->once())
108  ->method('isSecure')
109  ->willReturn(false);
110 
111  $exception = new LocalizedException('message');
112 
113  $this->repositoryMock->expects($this->once())
114  ->method('getUrlWithParams')
115  ->with($fileId, $paramsSecure)
116  ->willThrowException($exception);
117 
118  $this->loggerMock->expects($this->once())
119  ->method('critical')
120  ->with($exception);
121 
122  $this->urlMock->expects($this->once())
123  ->method('getUrl')
124  ->with('', ['_direct' => 'core/index/notFound'])
125  ->willReturn($fileUrl);
126 
127  $this->assertEquals($fileUrl, $this->model->getViewFileUrl($fileId, $params));
128  }
129 }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18