/** * @covers \Magento\Framework\Url\Encoder::encode * @covers \Magento\Framework\Url\Decoder::decode */ public function testDecode() { $urlBuilderMock = $this->getMock('Magento\\Framework\\UrlInterface', [], [], '', false); /** @var $urlBuilderMock \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ $decoder = new Decoder($urlBuilderMock); $encoder = new Encoder(); $data = uniqid(); $result = $encoder->encode($data); $urlBuilderMock->expects($this->once())->method('sessionUrlVar')->with($this->equalTo($data))->will($this->returnValue($result)); $this->assertNotContains('&', $result); $this->assertNotContains('%', $result); $this->assertNotContains('+', $result); $this->assertNotContains('=', $result); $this->assertEquals($result, $decoder->decode($result)); }
/** * @param Object $row * @return string */ public function render(Object $row) { $download = $this->getColumn()->getData('download'); $id = $row->getSafeId(); $packageName = $this->decoder->decode($id); $downloader = $this->getDownloader($download); $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); $file = $downloader->getRelativePath($packageName); $file = $rootDir->getRelativePath(Settings::VAR_DIR_NAME . '/' . $file); if ($rootDir->isFile($file) && $rootDir->isReadable($file)) { return '<a href="' . $this->getUrl('umc/module/download', array('type' => $download, 'id' => $id)) . '">' . $this->getLabel() . '</a>'; } return '<span style="color:red;">' . __('File does not exist or is not readable') . '</span>'; }
/** * run the action * * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\Controller\Result\Raw */ public function execute() { $type = $this->getRequest()->getParam('type'); $id = $this->getRequest()->getParam('id'); $packageName = $this->decoder->decode($id); $downloader = $this->downloader->getDownloader($type); $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); $file = $downloader->getRelativePath($packageName); $relativeFile = Settings::VAR_DIR_NAME . '/' . $file; $absoluteFile = $rootDir->getAbsolutePath($relativeFile); if ($rootDir->isFile($relativeFile) && $rootDir->isReadable($relativeFile)) { $fileName = basename($absoluteFile); $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $rootDir->stat($relativeFile)['size']); $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($rootDir->readFile($relativeFile)); return $resultRaw; } else { $result = $this->resultRedirectFactory->create(); $result->setPath('umc/module/index'); $this->messageManager->addError(__('The requested file does not exist or is not readable')); return $result; } }
/** * run action * * @return \Magento\Framework\View\Result\Page */ public function execute() { $pageResult = $this->resultPageFactory->create(); $pageResult->getConfig()->getTitle()->set(__('Ultimate Module Creator')); $id = $this->getRequest()->getParam('id'); $module = $this->moduleFactory->create(); if ($id) { try { $moduleName = $this->decoder->decode($id); $path = $this->settings->getXmlRootPath(); $moduleName = basename($moduleName); $xmlFile = $moduleName . '.xml'; $rootDir = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); $file = $rootDir->getRelativePath(Settings::VAR_DIR_NAME . '/' . $xmlFile); if ($rootDir->isFile($file) && $rootDir->isReadable($file)) { $this->xmlParser->load($path . '/' . $xmlFile); $data = $this->xmlParser->xmlToArray(); $data = $data[$module->getEntityCode()]; $entityIdsByCode = []; if (isset($data['entities']['entity'][0])) { $entities = $data['entities']['entity']; } else { $entities = [$data['entities']['entity']]; } if (isset($data[$this->settings->getEntityCode()])) { $settings = $data[$this->settings->getEntityCode()]; unset($data[$this->settings->getEntityCode()]); } else { $settings = []; } foreach ($entities as $key => $entity) { if (isset($entity['attributes']['attribute'])) { if (isset($entity['attributes']['attribute'][0])) { $entities[$key]['attributes'] = $entity['attributes']['attribute']; } else { $entities[$key]['attributes'] = [$entity['attributes']['attribute']]; } } $entityIdsByCode[$entity['name_singular']] = $key; } unset($data['entities']); $relationsByCode = []; if (isset($data['relations'])) { if (isset($data['relations']['relation'][0])) { foreach ($data['relations']['relation'] as $relationArray) { $relationsByCode = array_merge($relationsByCode, $relationArray); } } else { $relationsByCode = $data['relations']['relation']; } } $relations = []; foreach ($relationsByCode as $code => $value) { $parts = explode('_', $code); if (count($parts) != 2) { continue; } if (isset($entityIdsByCode[$parts[0]]) && isset($entityIdsByCode[$parts[1]])) { $entity0 = $entityIdsByCode[$parts[0]]; $entity1 = $entityIdsByCode[$parts[1]]; $relations[$entity0][$entity1] = $value; } } unset($data['relations']); $data = [$module->getEntityCode() => $data, 'entity' => $entities, $this->settings->getEntityCode() => $settings, 'relation' => $relations]; } else { $data = []; } } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); $pageRedirect = $this->pageRedirectFactory->create(); $pageRedirect->setPath('umc/*/index'); return $pageRedirect; } } else { $data = []; } $module->initFromData($data); $this->coreRegistry->register('current_module', $module); if ($id) { $title = __('Edit Module "%1"', $module->getNamespace() . '_' . $module->getModuleName()); } else { $title = __('Create module'); } $pageResult->getConfig()->getTitle()->prepend($title); $this->_setActiveMenu('Umc_Base::umc')->_addBreadcrumb(__('Ultimate Module Creator'), __('Ultimate Module Creator'))->_addBreadcrumb($title, $title); return $pageResult; }