/** * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $scope = $this->getRequest()->getParam('scope'); $scopeId = (int) $this->getRequest()->getParam('scope_id'); $data = $this->getRequestData(); try { $designConfigData = $this->configFactory->create($scope, $scopeId, $data); $this->designConfigRepository->save($designConfigData); $this->messageManager->addSuccess(__('You saved the configuration.')); $this->dataPersistor->clear('theme_design_config'); $returnToEdit = (bool) $this->getRequest()->getParam('back', false); $resultRedirect->setPath('theme/design_config/'); if ($returnToEdit) { $resultRedirect->setPath('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); } return $resultRedirect; } catch (LocalizedException $e) { $messages = explode("\n", $e->getMessage()); foreach ($messages as $message) { $this->messageManager->addError(__('%1', $message)); } } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving this configuration:') . ' ' . $e->getMessage()); } $this->dataPersistor->set('theme_design_config', $data); $resultRedirect->setPath('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); return $resultRedirect; }
public function testDelete() { $this->designConfig->expects($this->exactly(2))->method('getExtensionAttributes')->willReturn($this->designExtension); $this->designExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]); $this->configStorage->expects($this->once())->method('delete')->with($this->designConfig); $this->reinitableConfig->expects($this->once())->method('reinit'); $this->indexerRegistry->expects($this->once())->method('get')->with(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->willReturn($this->indexer); $this->indexer->expects($this->once())->method('reindexAll'); $this->assertSame($this->designConfig, $this->repository->delete($this->designConfig)); }
public function testSaveWithException() { $scope = 'sadfa'; $scopeId = 0; $this->redirectFactory->expects($this->once())->method('create')->willReturn($this->redirect); $this->request->expects($this->exactly(2))->method('getParam')->withConsecutive(['scope'], ['scope_id'])->willReturnOnConsecutiveCalls($scope, $scopeId); $this->request->expects($this->once())->method('getParams')->willReturn(['header_default_title' => 'Default title']); $this->request->expects($this->once())->method('getFiles')->willReturn($this->fileParams); $this->fileParams->expects($this->once())->method('toArray')->willReturn(['header_logo' => ['tmp_name' => '', 'error' => 4]]); $this->configFactory->expects($this->once())->method('create')->with($scope, $scopeId, ['header_default_title' => 'Default title'])->willReturn($this->designConfig); $exception = new \Exception(__('Exception message')); $this->designConfigRepository->expects($this->once())->method('save')->with($this->designConfig)->willThrowException($exception); $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Something went wrong while saving this configuration: Exception message'); $this->dataPersistor->expects($this->once())->method('set')->with('theme_design_config', ['header_default_title' => 'Default title']); $this->redirect->expects($this->once())->method('setPath')->with('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); $this->assertSame($this->redirect, $this->controller->execute()); }