Example #1
0
 public function testBeforeSave()
 {
     $this->pageMock->expects($this->any())->method('getData')->willReturnMap([['identifier', null, 'test'], ['custom_theme_from', null, null], ['custom_theme_to', null, '10/02/2016']]);
     $this->dateTimeMock->expects($this->once())->method('formatDate')->with('10/02/2016')->willReturn('10 Feb 2016');
     $this->pageMock->expects($this->any())->method('setData')->withConsecutive(['custom_theme_from', null], ['custom_theme_to', '10 Feb 2016']);
     $this->model->beforeSave($this->pageMock);
 }
Example #2
0
 protected function setUp()
 {
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->eventManagerMock = $this->getMockBuilder('Magento\\Framework\\Event\\ManagerInterface')->disableOriginalConstructor()->getMock();
     $this->context = $objectManager->getObject('Magento\\Framework\\Model\\Context', ['eventDispatcher' => $this->eventManagerMock]);
     $this->resourcePageMock = $this->getMockBuilder('Magento\\Cms\\Model\\ResourceModel\\Page')->disableOriginalConstructor()->setMethods(['getIdFieldName', 'checkIdentifier'])->getMock();
     $this->thisMock = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->setConstructorArgs([$this->context, $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Magento\\Framework\\Model\\ModelResource\\AbstractResource')->disableOriginalConstructor()->setMethods(['_construct', 'getConnection'])->getMockForAbstractClass(), $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->disableOriginalConstructor()->getMockForAbstractClass()])->setMethods(['_construct', '_getResource', 'load'])->getMock();
     $this->thisMock->expects($this->any())->method('_getResource')->willReturn($this->resourcePageMock);
     $this->thisMock->expects($this->any())->method('load')->willReturnSelf();
 }
Example #3
0
 public function testDeleteActionThrowsException()
 {
     $errorMsg = 'Can\'t delete the page';
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock);
     $this->pageMock->expects($this->once())->method('load')->with($this->pageId);
     $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title);
     $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg)));
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
 /**
  * @return void
  */
 public function testExecuteWithoutDataChanged()
 {
     $this->pageMock->expects($this->any())->method('dataHasChangedFor')->willReturnMap([['identifier', false], ['store_id', false]]);
     $this->pageMock->expects($this->never())->method('getId');
     $this->cmsPageUrlRewriteGeneratorMock->expects($this->never())->method('generate');
     $this->urlPersistMock->expects($this->never())->method('deleteByData');
     $this->urlPersistMock->expects($this->never())->method('replace');
     $this->observer->execute($this->eventObserverMock);
 }
Example #5
0
 public function testSetCmsPageData()
 {
     $extendedPageData = ['page_id' => '2', 'title' => 'Home Page', 'page_layout' => '1column', 'identifier' => 'home', 'content_heading' => 'Home Page', 'content' => 'CMS homepage content goes here.', 'is_active' => '1', 'sort_order' => '1', 'custom_theme' => '3', 'store_id' => ['0']];
     $pageData = ['page_id' => '2', 'title' => 'Home Page', 'page_layout' => '1column', 'identifier' => 'home', 'is_active' => '1', 'custom_theme' => '3'];
     $getData = ['page_id' => '2', 'title' => 'Home Page', 'page_layout' => '1column', 'identifier' => 'home', 'content_heading' => 'Home Page', 'content' => 'CMS homepage content goes here.', 'is_active' => '1', 'sort_order' => '1', 'custom_theme' => '3', 'custom_root_template' => '1column', 'store_id' => ['0']];
     $mergedData = ['page_id' => '2', 'title' => 'Home Page', 'page_layout' => '1column', 'identifier' => 'home', 'content_heading' => 'Home Page', 'content' => 'CMS homepage content goes here.', 'is_active' => '1', 'sort_order' => '1', 'custom_theme' => '3', 'custom_root_template' => '1column', 'store_id' => ['0']];
     $this->cmsPage->expects($this->once())->method('getData')->willReturn($getData);
     $this->cmsPage->expects($this->once())->method('setData')->with($mergedData)->willReturnSelf();
     $this->assertSame($this->controller, $this->controller->setCmsPageData($this->cmsPage, $extendedPageData, $pageData));
 }
Example #6
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));
 }
 public function testSaveActionThrowsException()
 {
     $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['page_id' => $this->pageId]);
     $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['page_id', null, $this->pageId], ['back', null, true]]);
     $this->dataProcessorMock->expects($this->any())->method('filter')->willReturnArgument(0);
     $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Page'))->willReturn($this->pageMock);
     $this->pageMock->expects($this->any())->method('load')->willReturnSelf();
     $this->pageMock->expects($this->any())->method('getId')->willReturn(true);
     $this->pageMock->expects($this->once())->method('setData');
     $this->pageMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException');
     $this->dataPersistorMock->expects($this->any())->method('set')->with('cms_page', ['page_id' => $this->pageId]);
     $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->saveController->execute());
 }
Example #8
0
 /**
  * @param int $pageId
  * @param string $label
  * @param string $title
  * @dataProvider editActionData
  */
 public function testEditAction($pageId, $label, $title)
 {
     $this->requestMock->expects($this->once())->method('getParam')->with('page_id')->willReturn($pageId);
     $this->pageMock->expects($this->any())->method('load')->with($pageId);
     $this->pageMock->expects($this->any())->method('getId')->willReturn($pageId);
     $this->pageMock->expects($this->any())->method('getTitle')->willReturn('Test title');
     $this->coreRegistryMock->expects($this->once())->method('register')->with('cms_page', $this->pageMock);
     $resultPageMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Page', [], [], '', false);
     $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock);
     $titleMock = $this->getMock('Magento\\Framework\\View\\Page\\Title', [], [], '', false);
     $titleMock->expects($this->at(0))->method('prepend')->with(__('Pages'));
     $titleMock->expects($this->at(1))->method('prepend')->with($this->getTitle());
     $pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', [], [], '', false);
     $pageConfigMock->expects($this->exactly(2))->method('getTitle')->willReturn($titleMock);
     $resultPageMock->expects($this->once())->method('setActiveMenu')->willReturnSelf();
     $resultPageMock->expects($this->any())->method('addBreadcrumb')->willReturnSelf();
     $resultPageMock->expects($this->at(3))->method('addBreadcrumb')->with(__($label), __($title))->willReturnSelf();
     $resultPageMock->expects($this->exactly(2))->method('getConfig')->willReturn($pageConfigMock);
     $this->assertSame($resultPageMock, $this->editController->execute());
 }
 /**
  * @test
  */
 public function testGetList()
 {
     $field = 'name';
     $value = 'magento';
     $condition = 'eq';
     $total = 10;
     $currentPage = 3;
     $pageSize = 2;
     $sortField = 'id';
     $criteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMock();
     $filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->getMock();
     $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
     $storeFilter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
     $sortOrder = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->getMock();
     $criteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $criteria->expects($this->once())->method('getSortOrders')->willReturn([$sortOrder]);
     $criteria->expects($this->once())->method('getCurrentPage')->willReturn($currentPage);
     $criteria->expects($this->once())->method('getPageSize')->willReturn($pageSize);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$storeFilter, $filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn($condition);
     $filter->expects($this->any())->method('getField')->willReturn($field);
     $filter->expects($this->once())->method('getValue')->willReturn($value);
     $storeFilter->expects($this->any())->method('getField')->willReturn('store_id');
     $storeFilter->expects($this->once())->method('getValue')->willReturn(1);
     $sortOrder->expects($this->once())->method('getField')->willReturn($sortField);
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_DESC);
     /** @var \Magento\Framework\Api\SearchCriteriaInterface $criteria */
     $this->collection->addItem($this->page);
     $this->pageSearchResult->expects($this->once())->method('setSearchCriteria')->with($criteria)->willReturnSelf();
     $this->collection->expects($this->once())->method('addFieldToFilter')->with($field, [$condition => $value])->willReturnSelf();
     $this->pageSearchResult->expects($this->once())->method('setTotalCount')->with($total)->willReturnSelf();
     $this->collection->expects($this->once())->method('getSize')->willReturn($total);
     $this->collection->expects($this->once())->method('setCurPage')->with($currentPage)->willReturnSelf();
     $this->collection->expects($this->once())->method('setPageSize')->with($pageSize)->willReturnSelf();
     $this->collection->expects($this->once())->method('addOrder')->with($sortField, 'DESC')->willReturnSelf();
     $this->page->expects($this->once())->method('getData')->willReturn(['data']);
     $this->pageSearchResult->expects($this->once())->method('setItems')->with(['someData'])->willReturnSelf();
     $this->dataHelper->expects($this->once())->method('populateWithArray')->with($this->pageData, ['data'], 'Magento\\Cms\\Api\\Data\\PageInterface');
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($this->pageData, 'Magento\\Cms\\Api\\Data\\PageInterface')->willReturn('someData');
     $this->assertEquals($this->pageSearchResult, $this->repository->getList($criteria));
 }
Example #10
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));
 }
Example #11
0
 public function testAroundDeleteNegative()
 {
     $this->cmsPageMock->expects($this->once())->method('isDeleted')->willReturn(false);
     $this->urlPersistMock->expects($this->never())->method('deleteByData');
     $this->assertEquals('URL Rewrite Result', $this->pageObject->aroundDelete($this->cmsPageResourceMock, $this->closureMock, $this->cmsPageMock));
 }
Example #12
0
 /**
  * @param array $availableStatuses
  * @param array $expected
  * @return void
  * @dataProvider getAvailableStatusesDataProvider
  */
 public function testToOptionArray(array $availableStatuses, array $expected)
 {
     $this->cmsPageMock->expects($this->once())->method('getAvailableStatuses')->willReturn($availableStatuses);
     $this->assertSame($expected, $this->object->toOptionArray());
 }