/** * @return void */ public function testGetData() { $themePath = 'blank'; $areaCode = 'adminhtml'; $filePaths = [['path1'], ['path2'], ['path3'], ['path4']]; $jsFilesMap = [['base', $themePath, '*', '*', [$filePaths[0]]], [$areaCode, $themePath, '*', '*', [$filePaths[1]]]]; $staticFilesMap = [['base', $themePath, '*', '*', [$filePaths[2]]], [$areaCode, $themePath, '*', '*', [$filePaths[3]]]]; $expectedResult = ['hello1' => 'hello1translated', 'hello2' => 'hello2translated', 'hello3' => 'hello3translated', 'hello4' => 'hello4translated']; $contentsMap = ['content1$.mage.__("hello1")content1', 'content2$.mage.__("hello2")content2', 'content2$.mage.__("hello3")content3', 'content2$.mage.__("hello4")content4']; $translateMap = [[['hello1'], [], 'hello1translated'], [['hello2'], [], 'hello2translated'], [['hello3'], [], 'hello3translated'], [['hello4'], [], 'hello4translated']]; $patterns = ['~\\$\\.mage\\.__\\(([\'"])(.+?)\\1\\)~']; $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode); $this->filesUtilityMock->expects($this->any())->method('getJsFiles')->willReturnMap($jsFilesMap); $this->filesUtilityMock->expects($this->any())->method('getStaticHtmlFiles')->willReturnMap($staticFilesMap); foreach ($contentsMap as $index => $content) { $this->fileReadMock->expects($this->at($index))->method('readAll')->willReturn($content); } $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns); $this->translateMock->expects($this->any())->method('render')->willReturnMap($translateMap); $this->assertEquals($expectedResult, $this->model->getData($themePath)); }
/** * Return name of the file * * @return string */ public function getFilename() { $this->_getHandle(); if ($this->_linkType == self::LINK_TYPE_FILE) { return pathinfo($this->_resourceFile, PATHINFO_BASENAME); } elseif ($this->_linkType == self::LINK_TYPE_URL) { $stat = $this->_handle->stat($this->_resourceFile); if (isset($stat['disposition'])) { $contentDisposition = explode('; ', $stat['disposition']); if (!empty($contentDisposition[1]) && preg_match('/filename=([^ ]+)/', $contentDisposition[1], $matches)) { return $matches[1]; } } $fileName = @pathinfo($this->_resourceFile, PATHINFO_BASENAME); if ($fileName) { return $fileName; } } return $this->_fileName; }
/** * @param ReadInterface $file * @return array|bool * @throws LocalizedException */ private function getHeaders(ReadInterface $file) { // check and skip headers $headers = $file->readCsv(); if ($headers === false || count($headers) < 5) { throw new LocalizedException(__('Please correct Table Rates File Format.')); } return $headers; }
protected function _setupUrlMocks($size = self::FILE_SIZE, $url = self::URL, $additionalStatData = []) { $this->_handleMock->expects($this->any())->method('stat')->will($this->returnValue(array_merge(['size' => $size, 'type' => self::MIME_TYPE], $additionalStatData))); $this->fileReadFactory->expects($this->once())->method('create')->will($this->returnValue($this->_handleMock)); $this->_helper->setResource($url, DownloadHelper::LINK_TYPE_URL); }
protected function _setupUrlMocks($size = self::FILE_SIZE, $url = self::URL, $additionalStatData = array()) { $this->_handleMock->expects($this->any())->method('stat')->will($this->returnValue(array_merge(array('size' => $size, 'type' => self::MIME_TYPE), $additionalStatData))); $this->_filesystemMock->expects($this->once())->method('getRemoteResource')->with($url)->will($this->returnValue($this->_handleMock)); $this->_helper->setResource($url, DownloadHelper::LINK_TYPE_URL); }