/** * Get options * * @return array */ public function toOptionArray() { $availableOptions = $this->cmsBlock->getAvailableStatuses(); $options = []; foreach ($availableOptions as $key => $value) { $options[] = ['label' => $value, 'value' => $key]; } return $options; }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Edit::getHeaderText * @param integer|null $modelBlockId * * @dataProvider getHeaderTextDataProvider */ public function testGetHeaderText($modelBlockId) { $title = 'some title'; $escapedTitle = 'escaped title'; $this->registryMock->expects($this->atLeastOnce())->method('registry')->with('cms_block')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->atLeastOnce())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($title)->willReturn($escapedTitle); $this->assertInstanceOf('Magento\\Framework\\Phrase', $this->this->getHeaderText()); }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Edit::getHeaderText * @param integer|null $modelBlockId * * @dataProvider getHeaderTextDataProvider */ public function testGetHeaderText($modelBlockId) { $title = 'some title'; $escapedTitle = 'escaped title'; $this->registryMock->expects($this->atLeastOnce())->method('registry')->with('cms_block')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->atLeastOnce())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($title)->willReturn($escapedTitle); $this->assertInternalType('string', $this->this->getHeaderText()); }
public function testDeleteAction() { $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->blockId); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Block')->willReturn($this->blockMock); $this->blockMock->expects($this->once())->method('load')->with($this->blockId); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('The block has been deleted.')); $this->messageManagerMock->expects($this->never())->method('addError'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->deleteController->execute()); }
public function prepareMocksForTestExecute() { $postData = [1 => ['title' => 'Catalog Events Lister', 'identifier' => 'Catalog Events Lister']]; $this->request->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true); $this->request->expects($this->at(1))->method('getParam')->with('items', [])->willReturn($postData); $this->blockRepository->expects($this->once())->method('getById')->with(1)->willReturn($this->cmsBlock); $this->cmsBlock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); $this->cmsBlock->expects($this->once())->method('getData')->willReturn(['identifier' => 'test-identifier']); $this->cmsBlock->expects($this->once())->method('setData')->with(['title' => 'Catalog Events Lister', 'identifier' => 'Catalog Events Lister']); $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); }
/** * @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)); }
/** * @test */ public function testDeleteById() { $locationId = '123'; $this->location->expects($this->once())->method('getId')->willReturn(true); $this->locationResource->expects($this->once())->method('load')->with($this->location, $locationId)->willReturn($this->location); $this->locationResource->expects($this->once())->method('delete')->with($this->location)->willReturnSelf(); $this->assertTrue($this->repository->deleteById($locationId)); }
public function testSaveActionThrowsException() { $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['block_id' => 1]); $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['block_id', null, 1], ['back', null, true]]); $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Block'))->willReturn($this->blockMock); $this->blockMock->expects($this->any())->method('load')->willReturnSelf(); $this->blockMock->expects($this->any())->method('getId')->willReturn(true); $this->blockMock->expects($this->once())->method('setData'); $this->blockMock->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_block', ['block_id' => 1]); $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf(); $this->assertSame($this->resultRedirect, $this->saveController->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->block); $this->blockSearchResult->expects($this->once())->method('setSearchCriteria')->with($criteria)->willReturnSelf(); $this->collection->expects($this->once())->method('addFieldToFilter')->with($field, [$condition => $value])->willReturnSelf(); $this->blockSearchResult->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->block->expects($this->once())->method('getData')->willReturn(['data']); $this->blockSearchResult->expects($this->once())->method('setItems')->with(['someData'])->willReturnSelf(); $this->dataHelper->expects($this->once())->method('populateWithArray')->with($this->blockData, ['data'], 'Magento\\Cms\\Api\\Data\\BlockInterface'); $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($this->blockData, 'Magento\\Cms\\Api\\Data\\BlockInterface')->willReturn('someData'); $this->assertEquals($this->blockSearchResult, $this->repository->getList($criteria)); }
/** * @return \Magento\Framework\Phrase|string */ protected function getTitle() { return $this->blockMock->getId() ? $this->blockMock->getTitle() : __('New Block'); }
/** * @param array $availableStatuses * @param array $expected * @return void * @dataProvider getAvailableStatusesDataProvider */ public function testToOptionArray(array $availableStatuses, array $expected) { $this->cmsBlockMock->expects($this->once())->method('getAvailableStatuses')->willReturn($availableStatuses); $this->assertSame($expected, $this->object->toOptionArray()); }