コード例 #1
0
 /**
  * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
  * @param string $elementValue
  * @param integer|null $modelBlockId
  *
  * @dataProvider prepareElementHtmlDataProvider
  */
 public function testPrepareElementHtml($elementValue, $modelBlockId)
 {
     $elementId = 1;
     $uniqId = '126hj4h3j73hk7b347jhkl37gb34';
     $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
     $config = ['key1' => 'value1'];
     $fieldsetId = 2;
     $html = 'some html';
     $title = 'some title';
     $this->this->setConfig($config);
     $this->this->setFieldsetId($fieldsetId);
     $this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
     $this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
     $this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
     $this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
     $this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
     $this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
     $this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock);
     $this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf();
     $this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId);
     $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
     $this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
     $this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
     $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
 }
コード例 #2
0
ファイル: IndexTest.php プロジェクト: nblair/magescotch
 public function testExecute()
 {
     $this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]);
     $this->titleMock->expects($this->atLeastOnce())->method('prepend');
     $this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock);
     $this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->blockMock->expects($this->atLeastOnce())->method('addLink');
     $this->blockMock->expects($this->once())->method('setActive');
     $this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock);
     $this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock);
     $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf();
     $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock);
     $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock);
     $this->action->executeInternal();
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $this->requestMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\RequestInterface', ['isDispatched', 'initForward', 'setDispatched', 'isForwarded']);
     $this->breadcrumbsBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['addLink']);
     $this->menuBlockMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\View\\Element\\BlockInterface', ['setActive', 'getMenuModel']);
     $this->viewMock = $this->getMockForAbstractClassBuilder('Magento\\Framework\\App\\ViewInterface');
     $this->layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->disableOriginalConstructor()->getMock();
     $this->switcherBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\BlockInterface')->disableOriginalConstructor()->getMock();
     $this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
     $this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http\\FileFactory')->disableOriginalConstructor()->getMock();
     $this->menuModelMock = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock();
     $this->abstractBlockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->setMethods(['getCsvFile', 'getExcelFile', 'setSaveParametersInSession', 'getCsv', 'getExcel'])->disableOriginalConstructor()->getMock();
     $this->menuModelMock->expects($this->any())->method('getParentItems')->willReturn([]);
     $this->menuBlockMock->expects($this->any())->method('getMenuModel')->willReturn($this->menuModelMock);
     $this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
     $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
     $this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
     $this->layoutMock->expects($this->any())->method('getBlock')->will($this->returnValueMap([['breadcrumbs', $this->breadcrumbsBlockMock], ['menu', $this->menuBlockMock], ['store_switcher', $this->switcherBlockMock]]));
     $this->layoutMock->expects($this->any())->method('getChildBlock')->willReturn($this->abstractBlockMock);
 }
コード例 #4
0
ファイル: PageTest.php プロジェクト: shabbirvividads/magento2
 /**
  * @covers \Magento\Cms\Helper\Page::prepareResultPage
  * @param integer|null $pageId
  * @param integer|null $internalPageId
  * @param integer $pageLoadResultIndex
  * @param string $customPageLayout
  * @param string $handle
  * @param string $customLayoutUpdateXml
  * @param string $layoutUpdate
  * @param boolean $expectedResult
  *
  * @dataProvider renderPageExtendedDataProvider
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testPrepareResultPage($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult)
 {
     $storeId = 321;
     $customThemeFrom = 'customThemeFrom';
     $customThemeTo = 'customThemeTo';
     $isScopeDateInInterval = true;
     $customTheme = 'customTheme';
     $pageLayout = 'pageLayout';
     $pageIdentifier = 111;
     $layoutUpdateXml = 'layoutUpdateXml';
     $contentHeading = 'contentHeading';
     $escapedContentHeading = 'escapedContentHeading';
     $defaultGroup = 'defaultGroup';
     $pageLoadResultCollection = [null, $this->pageMock];
     $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId);
     $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf();
     $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]);
     $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom);
     $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo);
     $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval);
     $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme);
     $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf();
     $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout);
     $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout);
     $this->resultPageFactory->expects($this->any())->method('create')->will($this->returnValue($this->resultPageMock));
     $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf();
     $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf();
     $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
     $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock);
     $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf();
     $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier);
     $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]);
     $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml);
     $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml);
     $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf();
     $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock);
     $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading);
     $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading);
     $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf();
     $this->layoutMock->expects($this->any())->method('getMessagesBlock')->willReturn($this->messagesBlockMock);
     $this->messageManagerMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup);
     $this->messagesBlockMock->expects($this->any())->method('addStorageType')->with($defaultGroup);
     $this->messageManagerMock->expects($this->any())->method('getMessages')->with(true)->willReturn($this->messageCollectionMock);
     $this->messagesBlockMock->expects($this->any())->method('addMessages')->with($this->messageCollectionMock)->willReturnSelf();
     if ($expectedResult) {
         $expectedResult = $this->resultPageMock;
     }
     $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId));
 }
コード例 #5
0
 /**
  * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
  *
  * @param string $elementValue
  * @param integer|null $cmsPageId
  *
  * @dataProvider prepareElementHtmlDataProvider
  */
 public function testPrepareElementHtml($elementValue, $cmsPageId)
 {
     //$elementValue = 12345;
     //$cmsPageId    = 1;
     $elementId = 1;
     $uniqId = '126hj4h3j73hk7b347jhkl37gb34';
     $sourceUrl = 'cms/page_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
     $config = ['key1' => 'value1'];
     $fieldsetId = 2;
     $html = 'some html';
     $title = 'some "><img src=y onerror=prompt(document.domain)>; title';
     $titleEscaped = 'some &quot;&gt;&lt;img src=y onerror=prompt(document.domain)&gt;; title';
     $this->this->setConfig($config);
     $this->this->setFieldsetId($fieldsetId);
     $this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
     $this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
     $this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/page_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
     $this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
     $this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
     $this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
     $this->pageFactoryMock->expects($this->any())->method('create')->willReturn($this->cmsPageMock);
     $this->cmsPageMock->expects($this->any())->method('load')->with((int) $elementValue)->willReturnSelf();
     $this->cmsPageMock->expects($this->any())->method('getId')->willReturn($cmsPageId);
     $this->cmsPageMock->expects($this->any())->method('getTitle')->willReturn($title);
     $this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
     if (!empty($elementValue) && !empty($cmsPageId)) {
         $this->escaper->expects($this->atLeastOnce())->method('escapeHtml')->willReturn($titleEscaped);
         $this->chooserMock->expects($this->atLeastOnce())->method('setLabel')->with($titleEscaped)->willReturnSelf();
     }
     $this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
     $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
 }
コード例 #6
0
 /**
  *  test execute method
  */
 public function testExecute()
 {
     $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
     $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
     $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
     $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
     $this->titleMock->expects($this->exactly(3))->method('add')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
     $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
     $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
     $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
     $this->viewMock->expects($this->once())->method('loadLayout');
     $this->viewMock->expects($this->once())->method('renderLayout');
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo('menu'))->will($this->returnValue($this->blockMenuMock));
     $this->blockMenuMock->expects($this->once())->method('setActive')->with($this->equalTo('Magento_Sales::sales_order'));
     $this->blockMenuMock->expects($this->once())->method('getMenuModel')->will($this->returnValue($this->modelMenuMock));
     $this->modelMenuMock->expects($this->once())->method('getParentItems')->will($this->returnValue([$this->modelMenuItem]));
     $this->modelMenuItem->expects($this->once())->method('getTitle')->will($this->returnValue('item-title'));
     $this->assertNull($this->controller->execute());
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function getConfiguration()
 {
     return array_merge((array) $this->block->getData('config'), (array) $this->getData('config'));
 }
コード例 #8
0
ファイル: Block.php プロジェクト: tingyeeh/magento2
 /**
  * @return string
  */
 public function render()
 {
     return $this->block->toHtml();
 }