public function testGetSampleData() { $expectingFileData = ['sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']]; $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getSamples')->will($this->returnValue([$this->downloadableSampleModel])); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title')); $this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null)); $this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $sampleData = $this->block->getSampleData(); foreach ($sampleData as $sample) { $fileSave = $sample->getFileSave(0); $this->assertEquals($expectingFileData['sample_file'], $fileSave); } }
public function testGetTreeLoaderUrl() { $requestParams = [\Magento\Theme\Helper\Storage::PARAM_THEME_ID => 1, \Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, \Magento\Theme\Helper\Storage::PARAM_NODE => 'root']; $expectedUrl = 'some_url'; $this->_helperStorage->expects($this->once())->method('getRequestParams')->will($this->returnValue($requestParams)); $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/*/treeJson', $requestParams)->will($this->returnValue($expectedUrl)); $this->assertEquals($expectedUrl, $this->_filesTree->getTreeLoaderUrl()); }
public function testGetJsUploadUrl() { $themeId = 2; $uploadUrl = 'upload_url'; $themeMock = $this->getMock('Magento\\Theme\\Model\\Theme', ['isVirtual', 'getId', '__wakeup'], [], '', false); $themeMock->expects($this->any())->method('getId')->will($this->returnValue($themeId)); $this->_model->expects($this->any())->method('_getCurrentTheme')->will($this->returnValue($themeMock)); $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/system_design_theme/uploadjs', ['id' => $themeId])->will($this->returnValue($uploadUrl)); $this->assertEquals($uploadUrl, $this->_model->getJsUploadUrl()); }
/** * Get HTML output for override hint UI * * @param \Magento\Config\Block\System\Config\Form $form * @param array $overridden * @return string */ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form $form, array $overridden) { $title = __('This setting is overridden at a more specific scope. Click for details.'); $formatted = '<a class="overridden-hint-list-toggle" title="' . $title . '" href="#"><span>' . $title . '</span></a>' . '<ul class="overridden-hint-list">'; foreach ($overridden as $overriddenScope) { $scope = $overriddenScope['scope']; $scopeId = $overriddenScope['scope_id']; $scopeLabel = $scopeId; $url = '#'; $section = $form->getSectionCode(); switch ($scope) { case 'website': $url = $this->urlBuilder->getUrl('*/*/*', array('section' => $section, 'website' => $scopeId)); $scopeLabel = sprintf('website <a href="%s">%s</a>', $url, $this->storeManager->getWebsite($scopeId)->getName()); break; case 'store': $store = $this->storeManager->getStore($scopeId); $website = $store->getWebsite(); $url = $this->urlBuilder->getUrl('*/*/*', array('section' => $section, 'store' => $store->getId())); $scopeLabel = sprintf('store view <a href="%s">%s</a>', $url, $website->getName() . ' / ' . $store->getName()); break; } $formatted .= "<li class='{$scope}'>Overridden on {$scopeLabel}</li>"; } $formatted .= '</ul>'; return $formatted; }
public function testGetLinkData() { $expectingFileData = array('file' => array('file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'), 'sample_file' => array('file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old')); $this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable')); $this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel)); $this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0)); $this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue(array($this->downloadableLinkModel))); $this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel)); $this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title')); $this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10')); $this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6')); $this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null)); $this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif')); $this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file')); $this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif')); $this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title')); $this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title')); $this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif')); $this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true)); $this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1')); $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url')); $linkData = $this->block->getLinkData(); foreach ($linkData as $link) { $fileSave = $link->getFileSave(0); $sampleFileSave = $link->getSampleFileSave(0); $this->assertEquals($expectingFileData['file'], $fileSave); $this->assertEquals($expectingFileData['sample_file'], $sampleFileSave); } }
public function testGetContentsUrl() { $expectedUrl = 'some_url'; $expectedRequest = 'some_request'; $requestParams = [\Magento\Theme\Helper\Storage::PARAM_THEME_ID => 1, \Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE => \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE, \Magento\Theme\Helper\Storage::PARAM_NODE => 'root']; $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/*/contents', ['type' => $expectedRequest] + $requestParams)->will($this->returnValue($expectedUrl)); $this->_request->expects($this->once())->method('getParam')->with('type')->will($this->returnValue($expectedRequest)); $this->_helperStorage->expects($this->once())->method('getRequestParams')->will($this->returnValue($requestParams)); $this->assertEquals($expectedUrl, $this->_filesContent->getContentsUrl()); }
/** * @param null|string $requestCountry * @param null|string $requestDefaultCountry * @param bool $canUseDefault * @param bool $inherit * @dataProvider renderDataProvider */ public function testRender($requestCountry, $requestDefaultCountry, $canUseDefault, $inherit) { $this->_request->expects($this->any())->method('getParam')->will($this->returnCallback(function ($param) use($requestCountry, $requestDefaultCountry) { if ($param == \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY) { return $requestCountry; } if ($param == Country::REQUEST_PARAM_DEFAULT_COUNTRY) { return $requestDefaultCountry; } return $param; })); $this->_element->setInherit($inherit); $this->_element->setCanUseDefaultValue($canUseDefault); $constraints = [new \PHPUnit_Framework_Constraint_StringContains('document.observe("dom:loaded", function() {'), new \PHPUnit_Framework_Constraint_StringContains('$("' . $this->_element->getHtmlId() . '").observe("change", function () {')]; if ($canUseDefault && $requestCountry == 'US' && $requestDefaultCountry) { $constraints[] = new \PHPUnit_Framework_Constraint_StringContains('$("' . $this->_element->getHtmlId() . '_inherit").observe("click", function () {'); } $this->_jsHelper->expects($this->once())->method('getScript')->with(new \PHPUnit_Framework_Constraint_And($constraints)); $this->_url->expects($this->once())->method('getUrl')->with('*/*/*', ['section' => 'section', 'website' => 'website', 'store' => 'store', \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__']); $this->_model->render($this->_element); }
/** * Check that secret key generation is based on usage of routeName extracted from request Forward info */ public function testGetSecretKeyGenerationWithRouteNameInForwardInfo() { $routeName = 'adminhtml'; $controllerName = 'catalog'; $actionName = 'index'; $keyFromParams = $this->_model->getSecretKey($routeName, $controllerName, $actionName); $this->_requestMock->expects($this->at(0))->method('getBeforeForwardInfo')->with('route_name')->will($this->returnValue('adminhtml')); $this->_requestMock->expects($this->at(1))->method('getBeforeForwardInfo')->with('route_name')->will($this->returnValue('adminhtml')); $this->_requestMock->expects($this->at(2))->method('getBeforeForwardInfo')->with('controller_name')->will($this->returnValue('catalog')); $this->_requestMock->expects($this->at(3))->method('getBeforeForwardInfo')->with('controller_name')->will($this->returnValue('catalog')); $this->_requestMock->expects($this->at(4))->method('getBeforeForwardInfo')->with('action_name')->will($this->returnValue('index')); $this->_requestMock->expects($this->at(5))->method('getBeforeForwardInfo')->with('action_name')->will($this->returnValue('index')); $this->_model->setRequest($this->_requestMock); $keyFromRequest = $this->_model->getSecretKey(); $this->assertEquals($keyFromParams, $keyFromRequest); }
/** * Get country selector html * * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $urlParams = ['section' => $this->getRequest()->getParam('section'), 'website' => $this->getRequest()->getParam('website'), 'store' => $this->getRequest()->getParam('store'), StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__']; $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); $jsString = ' $("' . $element->getHtmlId() . '").observe("change", function () { location.href = \'' . $urlString . '\'.replace("__country__", this.value); }); '; if ($this->_defaultCountry) { $urlParams[self::REQUEST_PARAM_DEFAULT_COUNTRY] = '__default__'; $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); $jsParentCountry = $this->_escaper->escapeJsQuote($this->_defaultCountry); $jsString .= ' $("' . $element->getHtmlId() . '_inherit").observe("click", function () { if (this.checked) { location.href = \'' . $urlString . '\'.replace("__country__", \'' . $jsParentCountry . '\') .replace("__default__", "1"); } }); '; } return parent::_getElementHtml($element) . $this->_jsHelper->getScript('require([\'prototype\'], function(){document.observe("dom:loaded", function() {' . $jsString . '});});'); }
public function testGetSaveCustomCssUrl() { $expectedUrl = 'some_url'; $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/system_design_editor_tools/saveCssContent', ['theme_id' => self::TEST_THEME_ID])->will($this->returnValue($expectedUrl)); $this->assertEquals($expectedUrl, $this->_model->getSaveCustomCssUrl()); }
public function testGetUrlWithUrlInRoutePath() { $routePath = 'https://localhost/index.php/catalog/product/view/id/100/?foo=bar#anchor'; static::assertEquals($routePath, $this->_model->getUrl($routePath)); }
public function testGetRedirectIframeUrl() { $params = array('some params'); $this->_urlBuilder->expects($this->once())->method('getUrl')->with($this->equalTo('adminhtml/authorizenet_directpost_payment/redirect'), $this->equalTo($params))->will($this->returnValue('some value')); $this->assertEquals('some value', $this->_model->getRedirectIframeUrl($params)); }
public function testGetRedirectIframeUrl() { $params = ['some params', '_secure' => true]; $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('adminhtml/authorizenet_directpost_payment/redirect', $params)->willReturn('some value'); $this->assertEquals('some value', $this->dataHelper->getRedirectIframeUrl($params)); }
/** * @covers \Magento\DesignEditor\Block\Adminhtml\Editor\Tools\Code\Js::getJsReorderUrl */ public function testGetJsReorderUrl() { $expectedUrl = 'some_url'; $this->_urlBuilder->expects($this->once())->method('getUrl')->with('adminhtml/system_design_editor_tools/reorderjs', array('theme_id' => self::TEST_THEME_ID))->will($this->returnValue($expectedUrl)); $this->assertEquals($expectedUrl, $this->_model->getJsReorderUrl()); }