Exemple #1
0
    /**
     * Render data
     *
     * @param UiComponentInterface $component
     * @param string $template
     * @return string
     * @throws \Exception
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function render(UiComponentInterface $component, $template = '')
    {
        $data = $component->getContext()->getDataSourceData($component);
        $data = reset($data);

        return $this->encoder->encode($data['config']['data']);
    }
 /**
  * Test render method.
  */
 public function testRender()
 {
     $arrayToRender = ['key' => 'value'];
     /** Assert that jsonEncode method in mocked helper will run once */
     $this->encoderMock->expects($this->once())->method('encode');
     $this->_restJsonRenderer->render($arrayToRender);
 }
 /**
  * Return JS layout
  *
  * @return string
  */
 public function getJsLayout()
 {
     $jsLayout = $this->jsLayout;
     foreach ($this->layoutProcessors as $processor) {
         $jsLayout = $processor->process($jsLayout, $this->getItem());
     }
     return $this->jsonEncoder->encode($jsLayout);
 }
 /**
  * @return void
  */
 public function testGetSessionCheckerJson()
 {
     $requestUrl = 'http://host/index.php/security/session/check';
     $redirectUrl = 'http://host/index.php/admin';
     $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($requestUrl, $redirectUrl);
     $value = ['requestUrl' => $requestUrl, 'redirectUrl' => $redirectUrl];
     $this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
     $this->assertEquals(json_encode($value), $this->block->getSessionCheckerJson());
 }
 public function testGetJsLayout()
 {
     /**
      * @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock
      */
     $itemMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock();
     $this->layoutProcessorMock->expects($this->once())->method('process')->with($this->jsLayout, $itemMock)->willReturnArgument(0);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->with($this->jsLayout)->willReturnArgument(0);
     $this->model->setItem($itemMock);
     $this->assertEquals($this->jsLayout, $this->model->getJsLayout());
 }
Exemple #6
0
 /**
  * Render data
  *
  * @param UiComponentInterface $component
  * @param string $template
  * @return string
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render(UiComponentInterface $component, $template = '')
 {
     $context = $component->getContext();
     $isComponent = $context->getRequestParam('componentJson');
     if ($isComponent) {
         $data = $this->structure->generate($component);
         return $this->encoder->encode($data);
     } else {
         $data = $component->getContext()->getDataSourceData($component);
         $data = reset($data);
         return $this->encoder->encode($data['config']['data']);
     }
 }
 /**
  * Format error data according to required format.
  *
  * @param string $errorMessage
  * @param string $trace
  * @param int $httpCode
  * @param string $format
  * @return array|string
  */
 protected function _formatError($errorMessage, $trace, $httpCode, $format)
 {
     $errorData = [];
     $message = ['code' => $httpCode, 'message' => $errorMessage];
     $isDeveloperMode = $this->_appState->getMode() == State::MODE_DEVELOPER;
     if ($isDeveloperMode) {
         $message['trace'] = $trace;
     }
     $errorData['messages']['error'][] = $message;
     switch ($format) {
         case self::DATA_FORMAT_JSON:
             $errorData = $this->encoder->encode($errorData);
             break;
         case self::DATA_FORMAT_XML:
             $errorData = '<?xml version="1.0"?>'
                 . '<error>'
                 . '<messages>'
                 . '<error>'
                 . '<data_item>'
                 . '<code>' . $httpCode . '</code>'
                 . '<message><![CDATA[' . $errorMessage . ']]></message>'
                 . ($isDeveloperMode ? '<trace><![CDATA[' . $trace . ']]></trace>' : '')
                 . '</data_item>'
                 . '</error>'
                 . '</messages>'
                 . '</error>';
             break;
     }
     return $errorData;
 }
 /**
  * @return Json Object
  */
 public function getOptions()
 {
     $options = array();
     $sliderData = self::getSlider();
     if (isset($sliderData)) {
         $options['animateOut'] = self::getSlider()->getAnimateOut();
         $options['animateIn'] = self::getSlider()->getAnimateIn();
         if ($this->getBannerCount() > 1) {
             $options['loop'] = (int) self::getSlider()->getLoop();
         } else {
             $options['loop'] = 0;
         }
         $options['nav'] = (int) self::getSlider()->getNav();
         $options['dots'] = (int) self::getSlider()->getDots();
         $options['items'] = (int) 1;
         if ($this->getBannerCount() > 1) {
             $options['autoplay'] = (int) self::getSlider()->getAutoPlay();
         } else {
             $options['autoplay'] = 0;
         }
         $options['autoplayTimeout'] = (int) self::getSlider()->getAutoplayTimeout();
         $options['autoplaySpeed'] = (int) self::getSlider()->getAutoplaySpeed();
         $options['startPosition'] = (int) self::getSlider()->getStartPosition();
         $options['video'] = (int) 1;
         $options['lazyLoad'] = (int) 1;
     }
     return $this->encoder->encode($options);
 }
 /**
  * Test default render format is JSON.
  * @return void
  */
 public function testRenderDefaultFormat()
 {
     /** Set undefined rendering format. */
     $_SERVER['HTTP_ACCEPT'] = 'undefined';
     /** Assert that jsonEncode method will be executed at least once. */
     $this->encoderMock->expects($this->atLeastOnce())->method('encode');
     $this->_errorProcessor->renderErrorMessage('Message');
 }
 /**
  * Return an array of selected resource ids.
  *
  * If everything is allowed then iterate through all
  * available resources to generate a comprehensive array of all resource ids, rather than just
  * returning "Magento_Backend::all".
  *
  * @return string
  */
 public function getSelectedResourcesJson()
 {
     $selectedResources = $this->_selectedResources;
     if ($this->isEverythingAllowed()) {
         $resources = $this->_resourceProvider->getAclResources();
         $selectedResources = $this->_getAllResourceIds($resources[1]['children']);
     }
     return $this->encoder->encode($selectedResources);
 }
 /**
  * Execute method.
  */
 public function execute()
 {
     $attribute = $this->getRequest()->getParam('attribute');
     $conditionName = $this->getRequest()->getParam('condition');
     $valueName = $this->getRequest()->getParam('value');
     if ($attribute && $conditionName && $valueName) {
         $type = $this->ruleType->getInputType($attribute);
         $conditionOptions = $this->ruleCondition->getInputTypeOptions($type);
         $response['condition'] = $this->_getOptionHtml('conditions', $conditionName, $conditionOptions);
         $elmType = $this->ruleValue->getValueElementType($attribute);
         if ($elmType == 'select') {
             $valueOptions = $this->ruleValue->getValueSelectOptions($attribute);
             $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
         } elseif ($elmType == 'text') {
             $html = "<input style='width:160px' title='cvalue' class='' id='' name={$valueName} />";
             $response['cvalue'] = $html;
         }
         $this->http->getHeaders()->clearHeaders();
         $this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response));
     }
 }
 public function testGetGiftOptionsConfigJson()
 {
     $this->compositeConfigProvider->expects($this->once())->method('getConfig')->willReturn($this->jsLayout);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->with($this->jsLayout)->willReturnArgument(0);
     $this->assertEquals($this->jsLayout, $this->model->getGiftOptionsConfigJson());
 }
Exemple #13
0
 /**
  * Convert data to JSON.
  *
  * @param object|array|int|string|bool|float|null $data
  * @return string
  */
 public function render($data)
 {
     return $this->encoder->encode($data);
 }
 /**
  * Retrieve gift message configuration
  *
  * @return array
  */
 public function getGiftOptionsConfigJson()
 {
     return $this->jsonEncoder->encode($this->configProvider->getConfig());
 }
Exemple #15
0
 /**
  * Set config
  *
  * @param array $config
  * @return $this
  */
 public function setConfig($config)
 {
     return $this->setData(self::CONFIG, $this->jsonEncoder->encode($config));
 }