Exemplo n.º 1
0
 protected function setUp()
 {
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->block = $objectManager->getObject('Magento\\Cms\\Block\\Page');
     $this->page = $objectManager->getObject('Magento\\Cms\\Model\\Page');
     $this->page->setId(1);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  * @covers \Magento\Cms\Model\Page::checkIdentifier
  */
 public function testCheckIdentifier()
 {
     $identifier = 1;
     $storeId = 2;
     $fetchOneResult = 'some result';
     $this->resourcePageMock->expects($this->atLeastOnce())->method('checkIdentifier')->with($identifier, $storeId)->willReturn($fetchOneResult);
     $this->assertInternalType('string', $this->thisMock->checkIdentifier($identifier, $storeId));
 }
Exemplo n.º 4
0
 /**
  * Get options
  *
  * @param array $options
  * @return array
  */
 public function getOptions(array $options = [])
 {
     $newOptions = $this->cmsPage->getAvailableStatuses();
     foreach ($newOptions as $key => $value) {
         $newOptions[$key] = ['label' => $value, 'value' => $key];
     }
     return array_merge_recursive($newOptions, $options);
 }
Exemplo n.º 5
0
 /**
  * Get options
  *
  * @return array
  */
 public function toOptionArray()
 {
     $options = [];
     $availableOptions = $this->cmsPage->getAvailableStatuses();
     foreach ($availableOptions as $key => $value) {
         $options[$key] = ['label' => $value, 'value' => $key];
     }
     return $options;
 }
Exemplo n.º 6
0
 /**
  * Append the CMS page viewed identifier and title to the list of tracked variables
  *
  * @return array
  */
 public function getVariables()
 {
     $variables = [];
     if ($this->page->getId()) {
         $variables['cms.identifier'] = $this->page->getIdentifier();
         $variables['cms.title'] = $this->page->getTitle();
     }
     return $variables;
 }
Exemplo n.º 7
0
 protected function setUp()
 {
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->block = $objectManager->getObject('Magento\\Cms\\Block\\Page');
     $this->page = $objectManager->getObject('Magento\\Cms\\Model\\Page');
     $reflection = new \ReflectionClass($this->page);
     $reflectionProperty = $reflection->getProperty('_idFieldName');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->page, 'page_id');
     $this->page->setId(1);
 }
Exemplo n.º 8
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());
 }
Exemplo n.º 9
0
 /**
  * Renders CMS page
  *
  * @param Action $action
  * @param int $pageId
  * @param bool $renderLayout
  * @return bool
  */
 protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
 {
     if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
         $delimiterPosition = strrpos($pageId, '|');
         if ($delimiterPosition) {
             $pageId = substr($pageId, 0, $delimiterPosition);
         }
         $this->_page->setStoreId($this->_storeManager->getStore()->getId());
         if (!$this->_page->load($pageId)) {
             return false;
         }
     }
     if (!$this->_page->getId()) {
         return false;
     }
     $inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo());
     if ($this->_page->getCustomTheme()) {
         if ($inRange) {
             $this->_design->setDesignTheme($this->_page->getCustomTheme());
         }
     }
     $this->_view->getLayout()->getUpdate()->addHandle('default')->addHandle('cms_page_view');
     $this->_view->addPageLayoutHandles(array('id' => $this->_page->getIdentifier()));
     $this->_view->addActionLayoutHandles();
     if ($this->_page->getRootTemplate()) {
         if ($this->_page->getCustomRootTemplate() && $this->_page->getCustomRootTemplate() != 'empty' && $inRange) {
             $handle = $this->_page->getCustomRootTemplate();
         } else {
             $handle = $this->_page->getRootTemplate();
         }
         $this->_pageLayout->applyHandle($handle);
     }
     $this->_eventManager->dispatch('cms_page_render', array('page' => $this->_page, 'controller_action' => $action));
     $this->_view->loadLayoutUpdates();
     if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
         $layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
     } else {
         $layoutUpdate = $this->_page->getLayoutUpdateXml();
     }
     if (!empty($layoutUpdate)) {
         $this->_view->getLayout()->getUpdate()->addUpdate($layoutUpdate);
     }
     $this->_view->generateLayoutXml()->generateLayoutBlocks();
     $contentHeadingBlock = $this->_view->getLayout()->getBlock('page_content_heading');
     if ($contentHeadingBlock) {
         $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
         $contentHeadingBlock->setContentHeading($contentHeading);
     }
     if ($this->_page->getRootTemplate()) {
         $this->_pageLayout->applyTemplate($this->_page->getRootTemplate());
     }
     /* @TODO: Move catalog and checkout storage types to appropriate modules */
     $messageBlock = $this->_view->getLayout()->getMessagesBlock();
     $messageBlock->addStorageType($this->messageManager->getDefaultGroup());
     $messageBlock->addMessages($this->messageManager->getMessages(true));
     if ($renderLayout) {
         $this->_view->renderLayout();
     }
     return true;
 }
Exemplo n.º 10
0
 /**
  * Prepare columns
  *
  * @return \Magento\Backend\Block\Widget\Grid\Extended
  */
 protected function _prepareColumns()
 {
     $this->addColumn('title', ['header' => __('Title'), 'index' => 'title']);
     $this->addColumn('identifier', ['header' => __('URL Key'), 'index' => 'identifier']);
     $this->addColumn('page_layout', ['header' => __('Layout'), 'index' => 'page_layout', 'type' => 'options', 'options' => $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions()]);
     /**
      * Check is single store mode
      */
     if (!$this->_storeManager->isSingleStoreMode()) {
         $this->addColumn('store_id', ['header' => __('Store View'), 'index' => 'store_id', 'type' => 'store', 'store_all' => true, 'store_view' => true, 'sortable' => false, 'filter_condition_callback' => [$this, '_filterStoreCondition']]);
     }
     $this->addColumn('is_active', ['header' => __('Status'), 'index' => 'is_active', 'type' => 'options', 'options' => $this->_cmsPage->getAvailableStatuses()]);
     $this->addColumn('creation_time', ['header' => __('Created'), 'index' => 'creation_time', 'type' => 'datetime', 'header_css_class' => 'col-date', 'column_css_class' => 'col-date']);
     $this->addColumn('update_time', ['header' => __('Modified'), 'index' => 'update_time', 'type' => 'datetime', 'header_css_class' => 'col-date', 'column_css_class' => 'col-date']);
     $this->addColumn('page_actions', ['header' => __('Action'), 'sortable' => false, 'filter' => false, 'renderer' => 'Magento\\Cms\\Block\\Adminhtml\\Page\\Grid\\Renderer\\Action', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action']);
     return parent::_prepareColumns();
 }
Exemplo n.º 11
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage This identifier is reserved for "CMS No Cookies Page" in configuration.
  */
 public function testBeforeSaveNoCookiesIdentifier()
 {
     $this->model->setId(1);
     $this->model->setOrigData('identifier', 'no-cookies');
     $this->model->setIdentifier('no-cookies2');
     $this->scopeConfigMock->expects($this->atLeastOnce())->method('getValue')->willReturnMap([[\Magento\Cms\Helper\Page::XML_PATH_NO_COOKIES_PAGE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'no-cookies']]);
     $this->model->beforeSave();
 }
Exemplo n.º 12
0
 /**
  * Prepare columns for pages grid
  *
  * @return $this
  */
 protected function _prepareColumns()
 {
     $this->addColumn('chooser_id', array('header' => __('ID'), 'index' => 'page_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id'));
     $this->addColumn('chooser_title', array('header' => __('Title'), 'index' => 'title', 'header_css_class' => 'col-title', 'column_css_class' => 'col-title'));
     $this->addColumn('chooser_identifier', array('header' => __('URL Key'), 'index' => 'identifier', 'header_css_class' => 'col-url', 'column_css_class' => 'col-url'));
     $this->addColumn('chooser_root_template', array('header' => __('Layout'), 'index' => 'root_template', 'type' => 'options', 'options' => $this->_pageLayout->getOptions(), 'header_css_class' => 'col-layout', 'column_css_class' => 'col-layout'));
     $this->addColumn('chooser_is_active', array('header' => __('Status'), 'index' => 'is_active', 'type' => 'options', 'options' => $this->_cmsPage->getAvailableStatuses(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status'));
     return parent::_prepareColumns();
 }
 /**
  * @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);
 }
Exemplo n.º 14
0
 /**
  * Prepare columns for pages grid
  *
  * @return $this
  */
 protected function _prepareColumns()
 {
     $this->addColumn('chooser_id', ['header' => __('ID'), 'index' => 'page_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']);
     $this->addColumn('chooser_title', ['header' => __('Title'), 'index' => 'title', 'header_css_class' => 'col-title', 'column_css_class' => 'col-title']);
     $this->addColumn('chooser_identifier', ['header' => __('URL Key'), 'index' => 'identifier', 'header_css_class' => 'col-url', 'column_css_class' => 'col-url']);
     $this->addColumn('chooser_page_layout', ['header' => __('Layout'), 'index' => 'page_layout', 'type' => 'options', 'options' => $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions(), 'header_css_class' => 'col-layout', 'column_css_class' => 'col-layout']);
     $this->addColumn('chooser_is_active', ['header' => __('Status'), 'index' => 'is_active', 'type' => 'options', 'options' => $this->_cmsPage->getAvailableStatuses(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status']);
     return parent::_prepareColumns();
 }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
0
 /**
  * Set layout type
  *
  * @param bool $inRange
  * @param \Magento\Framework\View\Result\Page $resultPage
  * @return \Magento\Framework\View\Result\Page
  */
 protected function setLayoutType($inRange, $resultPage)
 {
     if ($this->_page->getPageLayout()) {
         if ($this->_page->getCustomPageLayout() && $this->_page->getCustomPageLayout() != 'empty' && $inRange) {
             $handle = $this->_page->getCustomPageLayout();
         } else {
             $handle = $this->_page->getPageLayout();
         }
         $resultPage->getConfig()->setPageLayout($handle);
     }
     return $resultPage;
 }
Exemplo n.º 17
0
 /**
  * Get CMS page from request
  *
  * @return \Magento\Cms\Model\Page
  */
 private function _getCmsPage()
 {
     if (!$this->_cmsPage) {
         $this->_cmsPage = $this->_objectManager->create('Magento\\Cms\\Model\\Page');
         $cmsPageId = (int) $this->getRequest()->getParam('cms_page', 0);
         if (!$cmsPageId && $this->_getUrlRewrite()->getId() && $this->_getUrlRewrite()->getEntityType() === self::ENTITY_TYPE_CMS_PAGE) {
             $cmsPageId = $this->_getUrlRewrite()->getEntityId();
         }
         if ($cmsPageId) {
             $this->_cmsPage->load($cmsPageId);
         }
     }
     return $this->_cmsPage;
 }
 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());
 }
Exemplo n.º 19
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));
 }
Exemplo n.º 20
0
 /**
  * Get CMS page from request
  *
  * @return \Magento\Cms\Model\Page
  */
 protected function _getCmsPage()
 {
     if (!$this->_cmsPage) {
         $this->_cmsPage = $this->_objectManager->create('Magento\\Cms\\Model\\Page');
         $cmsPageId = (int) $this->getRequest()->getParam('cms_page', 0);
         if (!$cmsPageId && $this->_getUrlRewrite()->getId()) {
             $urlRewriteId = $this->_getUrlRewrite()->getId();
             /** @var $cmsUrlRewrite \Magento\Cms\Model\Page\Urlrewrite */
             $cmsUrlRewrite = $this->_objectManager->create('Magento\\Cms\\Model\\Page\\Urlrewrite');
             $cmsUrlRewrite->load($urlRewriteId, 'url_rewrite_id');
             $cmsPageId = $cmsUrlRewrite->getCmsPageId();
         }
         if ($cmsPageId) {
             $this->_cmsPage->load($cmsPageId);
         }
     }
     return $this->_cmsPage;
 }
Exemplo n.º 21
0
 /**
  * @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));
 }
Exemplo n.º 22
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));
 }
Exemplo n.º 23
0
 /**
  * Get data for saving code model
  *
  * @return array
  */
 protected function _getCodeData()
 {
     return ['entity_type' => \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PAGE, 'entity_id' => $this->_page->getId(), 'store_id' => 0, 'experiment_script' => $this->_params['experiment_script']];
 }
Exemplo n.º 24
0
 /**
  * Get request path
  *
  * @param \Magento\Cms\Model\Page $cmsPage
  * @return string
  */
 public function generateRequestPath($cmsPage)
 {
     return $cmsPage->getIdentifier();
 }
Exemplo n.º 25
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));
 }
Exemplo n.º 26
0
 /**
  * Create url rewrite object
  *
  * @param int $storeId
  * @param string|null $redirectType Null or one of OptionProvider const
  * @return UrlRewrite
  */
 protected function createUrlRewrite($storeId, $redirectType = null)
 {
     return $this->converter->convertArrayToObject([UrlRewrite::ENTITY_TYPE => self::ENTITY_TYPE, UrlRewrite::ENTITY_ID => $this->cmsPage->getId(), UrlRewrite::STORE_ID => $storeId, UrlRewrite::REQUEST_PATH => $this->cmsPage->getIdentifier(), UrlRewrite::TARGET_PATH => 'cms/page/view/page_id/' . $this->cmsPage->getId(), UrlRewrite::REDIRECT_TYPE => $redirectType]);
 }
 /**
  * Generate CMS page url key based on url_key entered by merchant or page title
  *
  * @param \Magento\Cms\Model\Page $cmsPage
  * @return string
  */
 public function generateUrlKey($cmsPage)
 {
     $urlKey = $cmsPage->getIdentifier();
     return $this->filterManager->translitUrl($urlKey === '' || $urlKey === null ? $cmsPage->getTitle() : $urlKey);
 }
Exemplo n.º 28
0
 /**
  * Prepare breadcrumbs
  *
  * @param \Magento\Cms\Model\Page $page
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return void
  */
 protected function _addBreadcrumbs(\Magento\Cms\Model\Page $page)
 {
     if ($this->_scopeConfig->getValue('web/default/show_cms_breadcrumbs', ScopeInterface::SCOPE_STORE) && ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) && $page->getIdentifier() !== $this->_scopeConfig->getValue('web/default/cms_home_page', ScopeInterface::SCOPE_STORE) && $page->getIdentifier() !== $this->_scopeConfig->getValue('web/default/cms_no_route', ScopeInterface::SCOPE_STORE)) {
         $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->_storeManager->getStore()->getBaseUrl()]);
         $breadcrumbsBlock->addCrumb('cms_page', ['label' => $page->getTitle(), 'title' => $page->getTitle()]);
     }
 }
 /**
  * Create url rewrite object
  *
  * @param int $storeId
  * @param int $redirectType
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite
  */
 protected function createUrlRewrite($storeId, $redirectType = 0)
 {
     return $this->urlRewriteFactory->create()->setStoreId($storeId)->setEntityType(self::ENTITY_TYPE)->setEntityId($this->cmsPage->getId())->setRequestPath($this->cmsPage->getIdentifier())->setTargetPath($this->cmsPageUrlPathGenerator->getCanonicalUrlPath($this->cmsPage))->setIsAutogenerated(1)->setRedirectType($redirectType);
 }
Exemplo n.º 30
0
 public function toOptionArray()
 {
     $pages = $this->_page->getCollection()->addOrder('title', 'asc');
     return ['checkout/cart' => 'Shopping Cart (default page)'] + $pages->toOptionIdArray();
 }