示例#1
0
 /**
  * Run test deleteById method
  *
  * @return void
  */
 public function testDeleteById()
 {
     $id = 20;
     $pageMock = $this->getMockForAbstractClass('Magento\\Cms\\Model\\Page', [], '', false, true, true, ['getId']);
     $this->pageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($pageMock));
     $this->resourceMock->expects($this->once())->method('load')->with($pageMock, $id);
     $pageMock->expects($this->once())->method('getId')->will($this->returnValue($id));
     $this->resourceMock->expects($this->once())->method('delete')->with($pageMock);
     $this->assertTrue($this->pageRepository->deleteById($id));
 }
示例#2
0
 /**
  * @covers \Magento\Cms\Helper\Page::getPageUrl
  * @param integer|null $pageId
  * @param integer|null $internalPageId
  * @param integer $pageLoadResultIndex
  * @param string|null $expectedResult
  *
  * @dataProvider getPageUrlDataProvider
  */
 public function testGetPageUrl($pageId, $internalPageId, $pageLoadResultIndex, $expectedResult)
 {
     $storeId = 321;
     $pageIdentifier = 111;
     $url = '/some/url';
     $pageLoadResultCollection = [null, $this->pageMock];
     $this->pageFactoryMock->expects($this->any())->method('create')->willReturn($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('getIdentifier')->willReturn($pageIdentifier);
     $this->urlBuilderMock->expects($this->any())->method('getUrl')->with(null, ['_direct' => $pageIdentifier])->willReturn($url);
     $this->assertEquals($expectedResult, $this->object->getPageUrl($pageId));
 }
示例#3
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));
 }