Exemplo n.º 1
0
 public function testExecuteWithException()
 {
     $this->prepareMocksForTestExecute();
     $this->blockRepository->expects($this->once())->method('save')->with($this->cmsBlock)->willThrowException(new \Exception(__('Exception')));
     $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['[Block ID: 1] Exception'], 'error' => true])->willReturnSelf();
     $this->controller->execute();
 }
Exemplo n.º 2
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     if ($this->getRequest()->getParam('isAjax')) {
         $postItems = $this->getRequest()->getParam('items', []);
         if (!count($postItems)) {
             $messages[] = __('Please correct the data sent.');
             $error = true;
         } else {
             foreach (array_keys($postItems) as $blockId) {
                 /** @var \Magento\Cms\Model\Block $block */
                 $block = $this->blockRepository->getById($blockId);
                 try {
                     $block->setData(array_merge($block->getData(), $postItems[$blockId]));
                     $this->blockRepository->save($block);
                 } catch (\Exception $e) {
                     $messages[] = $this->getErrorWithBlockId($block, __($e->getMessage()));
                     $error = true;
                 }
             }
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
 /**
  * Return CMS block ID
  *
  * @return int|null
  */
 public function getBlockId()
 {
     try {
         return $this->blockRepository->getById($this->context->getRequest()->getParam('block_id'))->getId();
     } catch (NoSuchEntityException $e) {
     }
     return null;
 }
 /**
  * Test search \Magento\Cms\Api\Data\BlockInterface
  */
 public function testSearch()
 {
     $blockTitle = 'Block title';
     $blockIdentifier = 'block-title';
     /** @var  \Magento\Cms\Api\Data\BlockInterface $blockDataObject */
     $blockDataObject = $this->blockFactory->create();
     $blockDataObject->setTitle($blockTitle)->setIdentifier($blockIdentifier);
     $this->currentBlock = $this->blockRepository->save($blockDataObject);
     $filterBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
     $searchCriteriaBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     $filter = $filterBuilder->setField(BlockInterface::IDENTIFIER)->setValue($blockIdentifier)->create();
     $searchCriteriaBuilder->addFilter([$filter]);
     $searchData = $searchCriteriaBuilder->create()->__toArray();
     $requestData = ['searchCriteria' => $searchData];
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . "/search" . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'GetList']];
     $searchResult = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertEquals(1, $searchResult['total_count']);
     $this->assertEquals($searchResult['items'][0][BlockInterface::IDENTIFIER], $blockIdentifier);
 }