Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkProviderTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Analytics\Api\Data\LinkInterfaceFactory;
17 
18 class LinkProviderTest extends \PHPUnit\Framework\TestCase
19 {
23  private $objectManagerHelper;
24 
28  private $linkInterfaceFactoryMock;
29 
33  private $fileInfoManagerMock;
34 
38  private $storeManagerInterfaceMock;
39 
43  private $linkInterfaceMock;
44 
48  private $fileInfoMock;
49 
53  private $storeMock;
54 
58  private $linkProvider;
59 
63  protected function setUp()
64  {
65  $this->linkInterfaceFactoryMock = $this->getMockBuilder(LinkInterfaceFactory::class)
66  ->disableOriginalConstructor()
67  ->setMethods(['create'])
68  ->getMock();
69  $this->fileInfoManagerMock = $this->getMockBuilder(FileInfoManager::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72  $this->storeManagerInterfaceMock = $this->getMockBuilder(StoreManagerInterface::class)
73  ->getMockForAbstractClass();
74  $this->linkInterfaceMock = $this->getMockBuilder(LinkInterface::class)
75  ->getMockForAbstractClass();
76  $this->fileInfoMock = $this->getMockBuilder(FileInfo::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79  $this->storeMock = $this->getMockBuilder(Store::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82  $this->objectManagerHelper = new ObjectManagerHelper($this);
83  $this->linkProvider = $this->objectManagerHelper->getObject(
84  LinkProvider::class,
85  [
86  'linkFactory' => $this->linkInterfaceFactoryMock,
87  'fileInfoManager' => $this->fileInfoManagerMock,
88  'storeManager' => $this->storeManagerInterfaceMock
89  ]
90  );
91  }
92 
93  public function testGet()
94  {
95  $baseUrl = 'http://magento.local/pub/media/';
96  $fileInfoPath = 'analytics/data.tgz';
97  $fileInitializationVector = 'er312esq23eqq';
98  $this->fileInfoManagerMock->expects($this->once())
99  ->method('load')
100  ->willReturn($this->fileInfoMock);
101  $this->linkInterfaceFactoryMock->expects($this->once())
102  ->method('create')
103  ->with(
104  [
105  'initializationVector' => base64_encode($fileInitializationVector),
106  'url' => $baseUrl . $fileInfoPath
107  ]
108  )
109  ->willReturn($this->linkInterfaceMock);
110  $this->storeManagerInterfaceMock->expects($this->once())
111  ->method('getStore')->willReturn($this->storeMock);
112  $this->storeMock->expects($this->once())
113  ->method('getBaseUrl')
114  ->with(
116  )
117  ->willReturn($baseUrl);
118  $this->fileInfoMock->expects($this->atLeastOnce())
119  ->method('getPath')
120  ->willReturn($fileInfoPath);
121  $this->fileInfoMock->expects($this->atLeastOnce())
122  ->method('getInitializationVector')
123  ->willReturn($fileInitializationVector);
124  $this->assertEquals($this->linkInterfaceMock, $this->linkProvider->get());
125  }
126 
135  public function testFileNotReady($fileInfoPath, $fileInitializationVector)
136  {
137  $this->fileInfoManagerMock->expects($this->once())
138  ->method('load')
139  ->willReturn($this->fileInfoMock);
140  $this->fileInfoMock->expects($this->once())
141  ->method('getPath')
142  ->willReturn($fileInfoPath);
143  $this->fileInfoMock->expects($this->any())
144  ->method('getInitializationVector')
145  ->willReturn($fileInitializationVector);
146  $this->linkProvider->get();
147  }
148 
152  public function fileNotReadyDataProvider()
153  {
154  return [
155  [null, 'initVector'],
156  ['path', null],
157  ['', 'initVector'],
158  ['path', ''],
159  ['', ''],
160  [null, null]
161  ];
162  }
163 }