Example #1
0
 /**
  * Get filter object for template processing log
  *
  * @return Filter
  */
 public function getTemplateFilter()
 {
     if (empty($this->_templateFilter)) {
         $this->_templateFilter = $this->_emailFilterFactory->create();
         $this->_templateFilter->setUseAbsoluteLinks($this->getUseAbsoluteLinks())->setStoreId($this->getDesignConfig()->getStore());
     }
     return $this->_templateFilter;
 }
Example #2
0
    /**
     * @covers \Magento\Framework\Filter\Template::afterFilter
     * @covers \Magento\Framework\Filter\Template::addAfterFilterCallback
     * @covers \Magento\Framework\Filter\Template::resetAfterFilterCallbacks
     */
    public function testAfterFilterCallbackReset()
    {
        $value = 'test string';
        $expectedResult = 'TEST STRING';

        // Build arbitrary object to pass into the addAfterFilterCallback method
        $callbackObject = $this->getMockBuilder('stdObject')
            ->setMethods(['afterFilterCallbackMethod'])
            ->getMock();

        $callbackObject->expects($this->once())
            ->method('afterFilterCallbackMethod')
            ->with($value)
            ->will($this->returnValue($expectedResult));

        $this->templateFilter->addAfterFilterCallback([$callbackObject, 'afterFilterCallbackMethod']);

        // Callback should run and filter content
        $this->assertEquals($expectedResult, $this->templateFilter->filter($value));

        // Callback should *not* run as callbacks should be reset
        $this->assertEquals($value, $this->templateFilter->filter($value));
    }
Example #3
0
 /**
  * Filter the string as template
  *
  * Overrides parent method in order to handle exceptions
  *
  * @param string $value
  * @return string
  * @SuppressWarnings(PHPMD.ConstructorWithNameAsEnclosingClass)
  */
 public function filter($value)
 {
     try {
         $value = parent::filter($value);
     } catch (\Exception $e) {
         // Since a single instance of this class can be used to filter content multiple times, reset callbacks to
         // prevent callbacks running for unrelated content (e.g., email subject and email body)
         $this->resetAfterFilterCallbacks();
         if ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
             $value = sprintf(__('Error filtering template: %s'), $e->getMessage());
         } else {
             $value = __("We're sorry, an error has occurred while generating this email.");
         }
         $this->_logger->critical($e);
     }
     return $value;
 }
Example #4
0
 /**
  * @covers \Magento\Framework\Filter\Template::varDirective
  * @covers \Magento\Framework\Filter\Template::getVariable
  * @covers \Magento\Framework\Filter\Template::getStackArgs
  * @dataProvider varDirectiveDataProvider
  */
 public function testVarDirective($construction, $variables, $expectedResult)
 {
     $this->templateFilter->setVariables($variables);
     $this->assertEquals($expectedResult, $this->templateFilter->filter($construction));
 }
Example #5
0
 /**
  * @param \Magento\Framework\Stdlib\StringUtils $string
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\View\Asset\Repository $assetRepo
  * @param array $variables
  */
 public function __construct(\Magento\Framework\Stdlib\StringUtils $string, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Asset\Repository $assetRepo, $variables = [])
 {
     $this->_storeManager = $storeManager;
     $this->_assetRepo = $assetRepo;
     parent::__construct($string, $variables);
 }
Example #6
0
 /**
  * Filter the string as template.
  * Rewrited for logging exceptions
  *
  * @param string $value
  * @return string
  * @SuppressWarnings(PHPMD.ConstructorWithNameAsEnclosingClass)
  */
 public function filter($value)
 {
     try {
         $value = parent::filter($value);
     } catch (\Exception $e) {
         $value = '';
         $this->_logger->logException($e);
     }
     return $value;
 }