From d6c0ef3a956bb087d451b84c041a3484dbbb14e7 Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Wed, 21 Jan 2015 14:40:35 +0200 Subject: [PATCH] Fixed issue with custom payment gateway and system render method --- src/bb-library/Payment/Adapter/Custom.php | 2 +- src/bb-modules/System/Service.php | 6 +---- tests/bb-modules/System/ServiceTest.php | 28 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/bb-library/Payment/Adapter/Custom.php b/src/bb-library/Payment/Adapter/Custom.php index df6df2c28..1f3576d44 100644 --- a/src/bb-library/Payment/Adapter/Custom.php +++ b/src/bb-library/Payment/Adapter/Custom.php @@ -71,7 +71,7 @@ class Payment_Adapter_Custom '_tpl' => ($subscription) ? $this->config['recurrent'] : $this->config['single'], ); $systemService = $this->di['mod_service']('System'); - return $systemService->renderString($vars['_tpl'], false, $vars); + return $systemService->renderString($vars['_tpl'], true, $vars); } public function process($tx) diff --git a/src/bb-modules/System/Service.php b/src/bb-modules/System/Service.php index ee37486be..ccf31e62f 100644 --- a/src/bb-modules/System/Service.php +++ b/src/bb-modules/System/Service.php @@ -313,11 +313,7 @@ class Service $parsed = $template->render($vars); } catch (\Exception $e) { $parsed = $tpl; - if ($e instanceof \Twig_Error_Syntax || $e instanceof \Twig_Error_Loader) { - if (!$try_render) { - throw $e; - } - } else { + if (!$try_render) { throw $e; } } diff --git a/tests/bb-modules/System/ServiceTest.php b/tests/bb-modules/System/ServiceTest.php index fecf4da4f..29a417774 100644 --- a/tests/bb-modules/System/ServiceTest.php +++ b/tests/bb-modules/System/ServiceTest.php @@ -282,6 +282,34 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { $this->service->renderString('test', false, $vars); } + public function testrenderStringTemplate() + { + $vars = array( + '_client_id' => 1 + ); + + $twigMock = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock(); + $twigMock->expects($this->atLeastOnce()) + ->method('addGlobal'); + $twigMock->expects($this->atLeastOnce()) + ->method('loadTemplate') + ->willThrowException(new \Twig_Error_Syntax('Exception created with PHPUNIT')); + + $dbMock = $this->getMockBuilder('\Box_Database')->getMock(); + $dbMock->expects($this->atLeastOnce()) + ->method('load') + ->will($this->returnValue(new \Model_Client())); + + $di = new \Box_Di(); + $di['db'] = $dbMock; + $di['twig'] = $twigMock; + $di['api_client'] = new \Model_Client(); + $this->service->setDi($di); + + $string = $this->service->renderString('test', true, $vars); + $this->assertEquals($string, 'test'); + } + public function testclearCache() { $toolsMock = $this->getMockBuilder('\Box_Tools')->getMock();