diff --git a/phpBB/phpbb/template/twig/tokenparser/event.php b/phpBB/phpbb/template/twig/tokenparser/event.php index 7c11d32b69..19a876ec3f 100644 --- a/phpBB/phpbb/template/twig/tokenparser/event.php +++ b/phpBB/phpbb/template/twig/tokenparser/event.php @@ -35,30 +35,36 @@ class event extends \Twig\TokenParser\AbstractTokenParser $this->phpbb_dispatcher = $phpbb_dispatcher; $template_event_priority_array = []; - /** - * Allow assigning priority to template events - *f - * @event core.twig_tokenparser_constructor - * @var array template_event_priority_array Array with template event priority assignments per extension namespace - * Usage: - * '_' => array( - * 'event/' => priority_number, - * ), - * Example: - * 'phpbb_viglink' => array( - * 'event/acp_help_phpbb_stats_after' => 80, - * 'event/overall_footer_after' => 100, - * ), - * @since 3.3.12-RC1 - */ + * Allow assigning priority to template events + * + * The higher number - the higher tempate event listener priority value is. + * In case of equal priority values, corresponding template event listeners will be handled in default compilation order. + * If not set, template event listener priority will be assigned to the value of 0. + * + * @event core.twig_tokenparser_constructor + * @var array template_event_priority_array Array with template event priority assignments per extension namespace + * Usage: + * '_' => [ + * 'event/' => priority_number, + * ], + * + * Example: + * 'phpbb_viglink' => [ + * 'event/acp_help_phpbb_stats_after' => 80, + * 'event/overall_footer_after' => 100, + * ], + * + * @since 4.0.0-a1 + */ if ($this->phpbb_dispatcher) { - $vars = array('template_event_priority_array'); + $vars = ['template_event_priority_array']; extract($this->phpbb_dispatcher->trigger_event('core.twig_tokenparser_constructor', compact($vars))); } $this->template_event_priority_array = $template_event_priority_array; + unset($template_event_priority_array); } /** diff --git a/tests/console/user/base.php b/tests/console/user/base.php index 511cfff9a3..605493bd80 100644 --- a/tests/console/user/base.php +++ b/tests/console/user/base.php @@ -190,7 +190,7 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case 'autoescape' => false, ] ); - $twig_extension = new \phpbb\template\twig\extension($context, $twig, $this->language); + $twig_extension = new \phpbb\template\twig\extension($context, $twig, $this->language, $phpbb_dispatcher); $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 5c42a2353b..4cc5e2d2a9 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -16,8 +16,6 @@ */ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - private static $helper; protected static $fixtures = array( diff --git a/tests/functional/extension_global_lang_test.php b/tests/functional/extension_global_lang_test.php index 85275d73b0..1fb1d053e3 100644 --- a/tests/functional/extension_global_lang_test.php +++ b/tests/functional/extension_global_lang_test.php @@ -16,8 +16,6 @@ */ class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - private static $helper; protected static $fixtures = array( @@ -47,10 +45,20 @@ class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_ $this->purge_cache(); } + protected function tearDown(): void + { + $this->uninstall_ext('foo/bar'); + + parent::tearDown(); + } + + protected static function setup_extensions() + { + return ['foo/bar']; + } + public function test_load_extension_lang_globally() { - $this->phpbb_extension_manager->enable('foo/bar'); - // The board index, which should contain an overwritten translation $crawler = self::request('GET', 'index.php'); @@ -59,7 +67,5 @@ class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_ // language from ext/foo/bar/language/en/foo_global.php $this->assertStringContainsString('Overwritten by foo', $crawler->filter('.skiplink')->text()); - - $this->phpbb_extension_manager->purge('foo/bar'); } } diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index 0e56e43c78..08ec7e5012 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -17,8 +17,6 @@ require_once __DIR__ . '/../../phpBB/includes/acp/acp_modules.php'; */ class phpbb_functional_extension_module_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - private static $helper; protected static $fixtures = array( diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 13812a08b6..e7dcb4ebcd 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -16,8 +16,6 @@ */ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - private static $helper; protected static $fixtures = array( @@ -76,7 +74,5 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t // language from ext/foo/bar/language/en/permissions_foo.php $this->assertStringContainsString('Can view foobar', $crawler->filter('body')->text()); - - $this->phpbb_extension_manager->purge('foo/bar'); } } diff --git a/tests/functional/extension_template_event_order_test.php b/tests/functional/extension_template_event_order_test.php index c931c95bc1..44586fc719 100644 --- a/tests/functional/extension_template_event_order_test.php +++ b/tests/functional/extension_template_event_order_test.php @@ -16,8 +16,6 @@ */ class phpbb_functional_extension_template_event_order_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - static private $helper; static protected $fixtures = [ @@ -43,11 +41,22 @@ class phpbb_functional_extension_template_event_order_test extends phpbb_functio { parent::setUp(); - $this->phpbb_extension_manager = $this->get_extension_manager(); - $this->purge_cache(); } + protected function tearDown(): void + { + $this->uninstall_ext('foo/bar'); + $this->uninstall_ext('foo/foo'); + + parent::tearDown(); + } + + protected static function setup_extensions() + { + return ['foo/bar', 'foo/foo']; + } + /** * Check a controller for extension foo/bar. */ @@ -55,32 +64,28 @@ class phpbb_functional_extension_template_event_order_test extends phpbb_functio { global $phpbb_root_path; - $this->phpbb_extension_manager->enable('foo/bar'); - $this->phpbb_extension_manager->enable('foo/foo'); $crawler = self::request('GET', 'index.php'); $quick_links_menu = $crawler->filter('ul[role="menu"]')->eq(0); $quick_links_menu_nodes_count = (int) $quick_links_menu->filter('li')->count(); // Ensure foo/foo template event goes before foo/bar one - $this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 2)->filter('span')->text()); - $this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 1)->filter('span')->text()); + $this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 4)->filter('span')->text()); + $this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 3)->filter('span')->text()); // Change template events order to default, put foo/bar event before foo/foo one - $this->phpbb_extension_manager->disable('foo/bar'); - $this->phpbb_extension_manager->disable('foo/foo'); + $this->disable_ext('foo/bar'); + $this->disable_ext('foo/foo'); + $this->assertTrue(copy(__DIR__ . '/fixtures/ext/foo/bar/event/template_event_order_higher.php', $phpbb_root_path . 'ext/foo/bar/event/template_event_order.php')); $this->assertTrue(copy(__DIR__ . '/fixtures/ext/foo/foo/event/template_event_order_lower.php', $phpbb_root_path . 'ext/foo/foo/event/template_event_order.php')); - $this->phpbb_extension_manager->enable('foo/bar'); - $this->phpbb_extension_manager->enable('foo/foo'); - $this->purge_cache(); - sleep(3); + + $this->install_ext('foo/bar'); + $this->install_ext('foo/foo'); + $crawler = self::request('GET', 'index.php'); $quick_links_menu = $crawler->filter('ul[role="menu"]')->eq(0); $quick_links_menu_nodes_count = (int) $quick_links_menu->filter('li')->count(); // Ensure foo/foo template event goes before foo/bar one - $this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 2)->filter('span')->text()); - $this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 1)->filter('span')->text()); - - $this->phpbb_extension_manager->purge('foo/bar'); - $this->phpbb_extension_manager->purge('foo/foo'); + $this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 4)->filter('span')->text()); + $this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 3)->filter('span')->text()); } } diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 8b4eb8fde5..206a72b2eb 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -16,8 +16,6 @@ */ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case { - protected $phpbb_extension_manager; - private static $helper; protected static $fixtures = array( diff --git a/tests/template/twig_test.php b/tests/template/twig_test.php index 69280caa15..a3bb071b0f 100644 --- a/tests/template/twig_test.php +++ b/tests/template/twig_test.php @@ -65,6 +65,7 @@ class twig_test extends \phpbb_test_case $loader = new \phpbb\template\twig\loader(''); $log = new \phpbb\log\dummy(); $assets_bag = new \phpbb\template\assets_bag(); + $dispatcher = new \phpbb\event\dispatcher(); $twig = new \phpbb\template\twig\environment( $assets_bag, $config, @@ -73,7 +74,7 @@ class twig_test extends \phpbb_test_case $cache_path, null, $loader, - new \phpbb\event\dispatcher(), + $dispatcher, [ 'cache' => false, 'debug' => false, @@ -81,7 +82,7 @@ class twig_test extends \phpbb_test_case 'autoescape' => false, ] ); - $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user))); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user, $dispatcher))); $twig->setLexer(new \phpbb\template\twig\lexer($twig)); } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 79a3baf05e..59e0864961 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -146,9 +146,6 @@ class phpbb_functional_test_case extends phpbb_test_case // Close the database connections again this test $this->db->sql_close(); } - - $this->purge_cache(); - sleep(3); // Give it some time to delete all the files correctly } /** @@ -410,7 +407,7 @@ class phpbb_functional_test_case extends phpbb_test_case 'autoescape' => false, ] ); - $twig_extension = new \phpbb\template\twig\extension($context, $twig, $lang); + $twig_extension = new \phpbb\template\twig\extension($context, $twig, $lang, $phpbb_dispatcher); $container->set('template.twig.extensions.phpbb', $twig_extension); $twig_extensions_collection = new \phpbb\di\service_collection($container); @@ -647,7 +644,7 @@ class phpbb_functional_test_case extends phpbb_test_case $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); - // Wait for extension to be fully enabled + // Wait for extension to be fully disabled while (count($meta_refresh)) { preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match);