From 6a48cad4a261fdf84d30c2002e14d2f0f049315b Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 19 Jun 2016 23:09:36 +0700 Subject: [ticket/14660] Add test case. PHPBB3-14660 --- tests/email/email_parsing_test.php | 138 +++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 tests/email/email_parsing_test.php (limited to 'tests/email/email_parsing_test.php') diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php new file mode 100644 index 0000000000..8def27c945 --- /dev/null +++ b/tests/email/email_parsing_test.php @@ -0,0 +1,138 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_email_parsing_test extends phpbb_test_case +{ + static protected $reflection; + protected $messenger; + protected $reflection_template_property; + + public function setUp() + { + global $phpbb_container, $config, $phpbb_root_path, $phpEx, $request, $user; + + $phpbb_container = new phpbb_mock_container_builder; + + $config = new \phpbb\config\config(array()); + $default_config = array( + 'board_email_sig' => '-- Thanks, The Management', + 'sitename' => 'yourdomain.com', + 'default_lang' => 'en', + ); + foreach ($default_config as $config_name => $config_value) + { + if (!isset($config[$config_name])) + { + $config[$config_name] = $config_value; + } + } + $phpbb_container->set('config', $config, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + $request = new phpbb_mock_request; + $symfony_request = new \phpbb\symfony_request( + $request + ); + $filesystem = new \phpbb\filesystem\filesystem(); + $phpbb_path_helper = new \phpbb\path_helper( + $symfony_request, + $filesystem, + $request, + $phpbb_root_path, + $phpEx + ); + $phpbb_container->set('path_helper', $phpbb_path_helper, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $phpbb_container->set('filesystem', $filesystem, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + $cache_path = 'cache/' . PHPBB_ENVIRONMENT . '/twig'; + $phpbb_container->setParameter('core.template.cache_path', $cache_path, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $user = new \phpbb\user($lang, '\phpbb\datetime'); + $phpbb_container->set('user', $user, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'vendor2/foo' => array( + 'ext_name' => 'vendor2/foo', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor2/foo/', + ), + ) + ); + $phpbb_container->set('ext.manager', $extension_manager, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + $context = new \phpbb\template\context(); + $phpbb_container->set('template.twig.extensions.collection', array(new \phpbb\template\twig\extension($context, $user)), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + $twig = new \phpbb\template\twig\environment( + $config, + $filesystem, + $phpbb_path_helper, + $cache_path, + null, + new \phpbb\template\twig\loader($filesystem, ''), + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + + if (!class_exists('messenger')) + { + include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + } + + $this->messenger = new \messenger(); + + $reflection = new ReflectionObject($this->messenger); + $this->reflection_template_property = $reflection->getProperty('template'); + $this->reflection_template_property->setAccessible(true); + } + + public function test_email_parsing() + { + global $phpbb_container, $config, $phpbb_root_path, $phpEx, $user, $request; + + $this->messenger->set_addresses($user->data); + + $this->messenger->assign_vars(array( + 'EMAIL_SIG' => str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])), + 'SITENAME' => htmlspecialchars_decode($config['sitename']), + + 'AUTHOR_NAME' => 'Author username', + 'FORUM_NAME' => 'Any forum', + 'TOPIC_TITLE' => 'The topic title', + 'USERNAME' => 'Dear user', + + 'U_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?f=1", + 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?uid=2&f=1&unwatch=forum", + )); + $this->messenger->template('newtopic_notify', $user->data['user_lang'], '', ''); + + $reflection_template = $this->reflection_template_property->getValue($this->messenger); + $msg = trim($reflection_template->assign_display('body')); + + $this->assertContains('Author username', $msg); + $this->assertContains('Any forum', $msg); + $this->assertContains('The topic title', $msg); + $this->assertContains('Dear user', $msg); + $this->assertContains(htmlspecialchars_decode($config['sitename']), $msg); + $this->assertContains(str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])), $msg); + $this->assertNotContains('EMAIL_SIG', $msg); + $this->assertNotContains('U_STOP_WATCHING_FORUM', $msg); + } +} -- cgit v1.2.1 From 471a773bcf73d95c8c875070de459397292113bd Mon Sep 17 00:00:00 2001 From: lavigor Date: Sun, 26 Jun 2016 14:29:45 +0300 Subject: [ticket/14696] Fix email template test for '0' username PHPBB3-14696 --- tests/email/email_parsing_test.php | 39 +++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'tests/email/email_parsing_test.php') diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 8def27c945..4f962c9c29 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -19,7 +19,7 @@ class phpbb_email_parsing_test extends phpbb_test_case public function setUp() { - global $phpbb_container, $config, $phpbb_root_path, $phpEx, $request, $user; + global $phpbb_container, $config, $phpbb_root_path, $phpEx, $request, $user; $phpbb_container = new phpbb_mock_container_builder; @@ -73,7 +73,8 @@ class phpbb_email_parsing_test extends phpbb_test_case $phpbb_container->set('ext.manager', $extension_manager, phpbb_mock_container_builder::SCOPE_PROTOTYPE); $context = new \phpbb\template\context(); - $phpbb_container->set('template.twig.extensions.collection', array(new \phpbb\template\twig\extension($context, $user)), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $twig_extension = new \phpbb\template\twig\extension($context, $user); + $phpbb_container->set('template.twig.extensions.collection', array($twig_extension), phpbb_mock_container_builder::SCOPE_PROTOTYPE); $twig = new \phpbb\template\twig\environment( $config, @@ -89,13 +90,14 @@ class phpbb_email_parsing_test extends phpbb_test_case 'autoescape' => false, ) ); + $twig->addExtension($twig_extension); $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig), phpbb_mock_container_builder::SCOPE_PROTOTYPE); if (!class_exists('messenger')) { include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); } - + $this->messenger = new \messenger(); $reflection = new ReflectionObject($this->messenger); @@ -103,9 +105,20 @@ class phpbb_email_parsing_test extends phpbb_test_case $this->reflection_template_property->setAccessible(true); } - public function test_email_parsing() + public function email_parsing_data() + { + return array( + array('Author username', 'Any forum', 'The topic title', 'Dear user'), + array('0', 'Any forum', 'The topic title', 'Dear user'), + ); + } + + /** + * @dataProvider email_parsing_data + */ + public function test_email_parsing($author_name, $forum_name, $topic_title, $username) { - global $phpbb_container, $config, $phpbb_root_path, $phpEx, $user, $request; + global $config, $phpEx, $user; $this->messenger->set_addresses($user->data); @@ -113,10 +126,10 @@ class phpbb_email_parsing_test extends phpbb_test_case 'EMAIL_SIG' => str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])), 'SITENAME' => htmlspecialchars_decode($config['sitename']), - 'AUTHOR_NAME' => 'Author username', - 'FORUM_NAME' => 'Any forum', - 'TOPIC_TITLE' => 'The topic title', - 'USERNAME' => 'Dear user', + 'AUTHOR_NAME' => $author_name, + 'FORUM_NAME' => $forum_name, + 'TOPIC_TITLE' => $topic_title, + 'USERNAME' => $username, 'U_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?f=1", 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?uid=2&f=1&unwatch=forum", @@ -126,10 +139,10 @@ class phpbb_email_parsing_test extends phpbb_test_case $reflection_template = $this->reflection_template_property->getValue($this->messenger); $msg = trim($reflection_template->assign_display('body')); - $this->assertContains('Author username', $msg); - $this->assertContains('Any forum', $msg); - $this->assertContains('The topic title', $msg); - $this->assertContains('Dear user', $msg); + $this->assertContains($author_name, $msg); + $this->assertContains($forum_name, $msg); + $this->assertContains($topic_title, $msg); + $this->assertContains($username, $msg); $this->assertContains(htmlspecialchars_decode($config['sitename']), $msg); $this->assertContains(str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])), $msg); $this->assertNotContains('EMAIL_SIG', $msg); -- cgit v1.2.1 From 27f16a195ec1c83860cbf0b8c9fa1e6f9f3d3f5e Mon Sep 17 00:00:00 2001 From: lavigor Date: Sun, 26 Jun 2016 16:05:08 +0300 Subject: [ticket/14696] Be perfect PHPBB3-14696 --- tests/email/email_parsing_test.php | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'tests/email/email_parsing_test.php') diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 4f962c9c29..351a38514f 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -13,8 +13,10 @@ class phpbb_email_parsing_test extends phpbb_test_case { - static protected $reflection; + /** @var \messenger */ protected $messenger; + + /** @var \ReflectionProperty */ protected $reflection_template_property; public function setUp() @@ -23,20 +25,12 @@ class phpbb_email_parsing_test extends phpbb_test_case $phpbb_container = new phpbb_mock_container_builder; - $config = new \phpbb\config\config(array()); - $default_config = array( + $config = new \phpbb\config\config(array( 'board_email_sig' => '-- Thanks, The Management', 'sitename' => 'yourdomain.com', 'default_lang' => 'en', - ); - foreach ($default_config as $config_name => $config_value) - { - if (!isset($config[$config_name])) - { - $config[$config_name] = $config_value; - } - } - $phpbb_container->set('config', $config, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + )); + $phpbb_container->set('config', $config); $request = new phpbb_mock_request; $symfony_request = new \phpbb\symfony_request( @@ -50,16 +44,16 @@ class phpbb_email_parsing_test extends phpbb_test_case $phpbb_root_path, $phpEx ); - $phpbb_container->set('path_helper', $phpbb_path_helper, phpbb_mock_container_builder::SCOPE_PROTOTYPE); - $phpbb_container->set('filesystem', $filesystem, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $phpbb_container->set('path_helper', $phpbb_path_helper); + $phpbb_container->set('filesystem', $filesystem); - $cache_path = 'cache/' . PHPBB_ENVIRONMENT . '/twig'; - $phpbb_container->setParameter('core.template.cache_path', $cache_path, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $cache_path = $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/twig'; + $phpbb_container->setParameter('core.template.cache_path', $cache_path); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); $user = new \phpbb\user($lang, '\phpbb\datetime'); - $phpbb_container->set('user', $user, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $phpbb_container->set('user', $user); $extension_manager = new phpbb_mock_extension_manager( dirname(__FILE__) . '/', array( @@ -70,11 +64,15 @@ class phpbb_email_parsing_test extends phpbb_test_case ), ) ); - $phpbb_container->set('ext.manager', $extension_manager, phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $phpbb_container->set('ext.manager', $extension_manager); $context = new \phpbb\template\context(); - $twig_extension = new \phpbb\template\twig\extension($context, $user); - $phpbb_container->set('template.twig.extensions.collection', array($twig_extension), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $twig_extension = new \phpbb\template\twig\extension($context, $lang); + $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); + + $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); + $twig_extensions_collection->add('template.twig.extensions.phpbb'); + $phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection); $twig = new \phpbb\template\twig\environment( $config, @@ -91,7 +89,7 @@ class phpbb_email_parsing_test extends phpbb_test_case ) ); $twig->addExtension($twig_extension); - $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig), phpbb_mock_container_builder::SCOPE_PROTOTYPE); + $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); if (!class_exists('messenger')) { -- cgit v1.2.1 From 1ea114ca20bd4613420284d7bfc4c92ab0a817b4 Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 11 Jan 2017 23:53:12 +0700 Subject: [ticket/14990] Fix event name, email parsing, installer and dispatcher calls PHPBB3-14990 --- tests/email/email_parsing_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/email/email_parsing_test.php') diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 351a38514f..a8366cf076 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -86,7 +86,8 @@ class phpbb_email_parsing_test extends phpbb_test_case 'debug' => false, 'auto_reload' => true, 'autoescape' => false, - ) + ), + new \phpbb\event\dispatcher($phpbb_container) ); $twig->addExtension($twig_extension); $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); -- cgit v1.2.1 From fcc8e155ec309669bebbf6e0370cecfe64c95193 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 16 Apr 2017 20:53:59 +0700 Subject: [ticket/14990] Move dispatcher object to the front of the options array PHPBB3-14990 --- tests/email/email_parsing_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/email/email_parsing_test.php') diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index a8366cf076..8fdfe3035e 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -81,13 +81,13 @@ class phpbb_email_parsing_test extends phpbb_test_case $cache_path, null, new \phpbb\template\twig\loader($filesystem, ''), + new \phpbb\event\dispatcher($phpbb_container), array( 'cache' => false, 'debug' => false, 'auto_reload' => true, 'autoescape' => false, - ), - new \phpbb\event\dispatcher($phpbb_container) + ) ); $twig->addExtension($twig_extension); $phpbb_container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig)); -- cgit v1.2.1