aboutsummaryrefslogtreecommitdiffstats
path: root/tests/event
diff options
context:
space:
mode:
Diffstat (limited to 'tests/event')
-rw-r--r--tests/event/dispatcher_test.php33
-rw-r--r--tests/event/exception_listener_test.php100
-rw-r--r--tests/event/export_php_test.php49
-rw-r--r--tests/event/fixtures/adm/style/acp_bbcodes.html0
-rw-r--r--tests/event/fixtures/default.test9
-rw-r--r--tests/event/fixtures/duplicate_event.test19
-rw-r--r--tests/event/fixtures/extra_description.test11
-rw-r--r--tests/event/fixtures/missing_var.test17
-rw-r--r--tests/event/fixtures/none.test6
-rw-r--r--tests/event/fixtures/normal_events.md.test20
-rw-r--r--tests/event/fixtures/trigger.test15
-rw-r--r--tests/event/fixtures/trigger_many_vars.test65
-rw-r--r--tests/event/fixtures/trigger_wspace.test15
-rw-r--r--tests/event/md_exporter_test.php160
-rw-r--r--tests/event/php_exporter_test.php740
15 files changed, 1259 insertions, 0 deletions
diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php
new file mode 100644
index 0000000000..7bba5bf337
--- /dev/null
+++ b/tests/event/dispatcher_test.php
@@ -0,0 +1,33 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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_event_dispatcher_test extends phpbb_test_case
+{
+ public function test_trigger_event()
+ {
+ $dispatcher = new \phpbb\event\dispatcher(new phpbb_mock_container_builder());
+
+ $dispatcher->addListener('core.test_event', function (\phpbb\event\data $event) {
+ $event['foo'] = $event['foo'] . '2';
+ $event['bar'] = $event['bar'] . '2';
+ });
+
+ $foo = 'foo';
+ $bar = 'bar';
+
+ $vars = array('foo', 'bar');
+ $result = $dispatcher->trigger_event('core.test_event', compact($vars));
+
+ $this->assertSame(array('foo' => 'foo2', 'bar' => 'bar2'), $result);
+ }
+}
diff --git a/tests/event/exception_listener_test.php b/tests/event/exception_listener_test.php
new file mode 100644
index 0000000000..4d3453cd83
--- /dev/null
+++ b/tests/event/exception_listener_test.php
@@ -0,0 +1,100 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class exception_listener extends phpbb_test_case
+{
+ public function phpbb_exception_data()
+ {
+ return array(
+ array(
+ true,
+ new \Exception(),
+ array(
+ 'status_code' => 500,
+ ),
+ ),
+ array(
+ true,
+ new \Exception('AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 500,
+ 'content' => 'AJAX_ERROR_TEXT',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\runtime_exception('AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 500,
+ 'content' => 'Something went wrong when processing your request.',
+ ),
+ ),
+ array(
+ true,
+ new \Symfony\Component\HttpKernel\Exception\HttpException(404, 'AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 404,
+ 'content' => 'AJAX_ERROR_TEXT',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\http_exception(404, 'AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 404,
+ 'content' => 'Something went wrong when processing your request.',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\http_exception(404, 'CURRENT_TIME', array('today')),
+ array(
+ 'status_code' => 404,
+ 'content' => 'It is currently today',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider phpbb_exception_data
+ */
+ public function test_phpbb_exception($is_ajax, $exception, $expected)
+ {
+ $request = \Symfony\Component\HttpFoundation\Request::create('test.php', 'GET', array(), array(), array(), $is_ajax ? array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') : array());
+
+ $template = $this->getMockBuilder('\phpbb\template\twig\twig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->add_lang('common');
+
+ $exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $user);
+
+ $event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
+ $exception_listener->on_kernel_exception($event);
+
+ $response = $event->getResponse();
+
+ $this->assertEquals($expected['status_code'], $response->getStatusCode());
+ $this->assertEquals($is_ajax, $response instanceof \Symfony\Component\HttpFoundation\JsonResponse);
+
+ if (isset($expected['content']))
+ {
+ $this->assertContains($expected['content'], $response->getContent());
+ }
+ }
+}
diff --git a/tests/event/export_php_test.php b/tests/event/export_php_test.php
new file mode 100644
index 0000000000..21bbb0620a
--- /dev/null
+++ b/tests/event/export_php_test.php
@@ -0,0 +1,49 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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_event_export_php_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path;
+ $this->exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ }
+
+ static public function crawl_php_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ $files = $exporter->get_recursive_file_list($phpbb_root_path);
+
+ $data_provider = array();
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($file);
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file)
+ {
+ $this->assertGreaterThanOrEqual(0, $this->exporter->crawl_php_file($file));
+ }
+}
diff --git a/tests/event/fixtures/adm/style/acp_bbcodes.html b/tests/event/fixtures/adm/style/acp_bbcodes.html
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/event/fixtures/adm/style/acp_bbcodes.html
diff --git a/tests/event/fixtures/default.test b/tests/event/fixtures/default.test
new file mode 100644
index 0000000000..edfe4823dc
--- /dev/null
+++ b/tests/event/fixtures/default.test
@@ -0,0 +1,9 @@
+<?php
+
+/**
+* Description
+*
+* @event default.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('default.dispatch');
diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test
new file mode 100644
index 0000000000..b042ca0377
--- /dev/null
+++ b/tests/event/fixtures/duplicate_event.test
@@ -0,0 +1,19 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @var int start Start item of this page
+ * @since 3.1.0-a3
+ */
+ $vars = array('start');
+ extract($phpbb_dispatcher->trigger_event('duplicate.trigger', compact($vars)));
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @since 3.1.0-b1
+ */
+ $phpbb_dispatcher->dispatch('duplicate.trigger');
diff --git a/tests/event/fixtures/extra_description.test b/tests/event/fixtures/extra_description.test
new file mode 100644
index 0000000000..ce8f97ce89
--- /dev/null
+++ b/tests/event/fixtures/extra_description.test
@@ -0,0 +1,11 @@
+<?php
+
+/**
+* Description
+*
+* NOTE: This will not be exported
+*
+* @event extra_description.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('extra_description.dispatch');
diff --git a/tests/event/fixtures/missing_var.test b/tests/event/fixtures/missing_var.test
new file mode 100644
index 0000000000..7ced5e93dc
--- /dev/null
+++ b/tests/event/fixtures/missing_var.test
@@ -0,0 +1,17 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @var array attachments List of attachments
+ * @var array user_poster_data Poster's data from user cache
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/none.test b/tests/event/fixtures/none.test
new file mode 100644
index 0000000000..6e2267024b
--- /dev/null
+++ b/tests/event/fixtures/none.test
@@ -0,0 +1,6 @@
+<?php
+
+/**
+* Hi there :)
+*/
+echo 1 + 2;
diff --git a/tests/event/fixtures/normal_events.md.test b/tests/event/fixtures/normal_events.md.test
new file mode 100644
index 0000000000..47921c4e57
--- /dev/null
+++ b/tests/event/fixtures/normal_events.md.test
@@ -0,0 +1,20 @@
+acp_bbcodes_actions_append
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a3
+* Changed: 3.1.0-a4
+* Purpose: desc1
+
+acp_bbcodes_actions_prepend
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a5
+* Purpose: desc2
+
+acp_bbcodes_actions_prepend2
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a4
+* Changed: 3.1.0-a5 Moved up
+* Changed: 3.1.0-a6 Moved down
+* Purpose: desc2
diff --git a/tests/event/fixtures/trigger.test b/tests/event/fixtures/trigger.test
new file mode 100644
index 0000000000..7cd6a7b956
--- /dev/null
+++ b/tests/event/fixtures/trigger.test
@@ -0,0 +1,15 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test
new file mode 100644
index 0000000000..5e0720d13b
--- /dev/null
+++ b/tests/event/fixtures/trigger_many_vars.test
@@ -0,0 +1,65 @@
+<?php
+
+ /**
+ * This event allows you to modify template variables for the posting screen
+ *
+ * @event core.posting_modify_template_vars
+ * @var array post_data Array with post data
+ * @var array moderators Array with forum moderators
+ * @var string mode What action to take if the form is submitted
+ * post|reply|quote|edit|delete|bump|smilies|popup
+ * @var string page_title Title of the mode page
+ * @var bool s_topic_icons Whether or not to show the topic icons
+ * @var string form_enctype If attachments are allowed for this form
+ * "multipart/form-data" or empty string
+ * @var string s_action The URL to submit the POST data to
+ * @var string s_hidden_fields Concatenated hidden input tags of posting form
+ * @var int post_id ID of the post
+ * @var int topic_id ID of the topic
+ * @var int forum_id ID of the forum
+ * @var bool submit Whether or not the form has been submitted
+ * @var bool preview Whether or not the post is being previewed
+ * @var bool save Whether or not a draft is being saved
+ * @var bool load Whether or not a draft is being loaded
+ * @var bool delete Whether or not the post is being deleted
+ * @var bool cancel Whether or not to cancel the form (returns to
+ * viewtopic or viewforum depending on if the user
+ * is posting a new topic or editing a post)
+ * @var array error Any error strings; a non-empty array aborts
+ * form submission.
+ * NOTE: Should be actual language strings, NOT
+ * language keys.
+ * @var bool refresh Whether or not to retain previously submitted data
+ * @var array page_data Posting page data that should be passed to the
+ * posting page via $template->assign_vars()
+ * @var object message_parser The message parser object
+ * @since 3.1.0-a1
+ * @changed 3.1.0-b3 Added vars post_data, moderators, mode, page_title,
+ * s_topic_icons, form_enctype, s_action, s_hidden_fields,
+ * post_id, topic_id, forum_id, submit, preview, save, load,
+ * delete, cancel, refresh, error, page_data, message_parser
+ */
+ $vars = array(
+ 'post_data',
+ 'moderators',
+ 'mode',
+ 'page_title',
+ 's_topic_icons',
+ 'form_enctype',
+ 's_action',
+ 's_hidden_fields',
+ 'post_id',
+ 'topic_id',
+ 'forum_id',
+ 'submit',
+ 'preview',
+ 'save',
+ 'load',
+ 'delete',
+ 'cancel',
+ 'refresh',
+ 'error',
+ 'page_data',
+ 'message_parser',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
diff --git a/tests/event/fixtures/trigger_wspace.test b/tests/event/fixtures/trigger_wspace.test
new file mode 100644
index 0000000000..0334a9c80b
--- /dev/null
+++ b/tests/event/fixtures/trigger_wspace.test
@@ -0,0 +1,15 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php
new file mode 100644
index 0000000000..1a51204cbe
--- /dev/null
+++ b/tests/event/md_exporter_test.php
@@ -0,0 +1,160 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_event_md_exporter_test extends phpbb_test_case
+{
+ static public function crawl_eventsmd_data()
+ {
+ return array(
+ array('normal_events.md.test', null, null, array(
+ 'acp_bbcodes_actions_append' => array(
+ 'event' => 'acp_bbcodes_actions_append',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a3',
+ 'changed' => array(
+ '3.1.0-a4' => '',
+ ),
+ 'description' => 'desc1' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend' => array(
+ 'event' => 'acp_bbcodes_actions_prepend',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a5',
+ 'changed' => array(),
+ 'description' => 'desc2' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend2' => array(
+ 'event' => 'acp_bbcodes_actions_prepend2',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a4',
+ 'changed' => array(
+ '3.1.0-a5' => 'Moved up',
+ '3.1.0-a6' => 'Moved down',
+ ),
+ 'description' => 'desc2' . "\n",
+ ),
+ )),
+ array('normal_events.md.test', '3.1.0-a5', '3.1.0-a5', array(
+ 'acp_bbcodes_actions_prepend' => array(
+ 'event' => 'acp_bbcodes_actions_prepend',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a5',
+ 'changed' => array(),
+ 'description' => 'desc2' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend2' => array(
+ 'event' => 'acp_bbcodes_actions_prepend2',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a4',
+ 'changed' => array(
+ '3.1.0-a5' => 'Moved up',
+ '3.1.0-a6' => 'Moved down',
+ ),
+ 'description' => 'desc2' . "\n",
+ ),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_eventsmd_data
+ *
+ * @param string $file
+ * @param string $min_version
+ * @param string $max_version
+ * @param array $events
+ */
+ public function test_crawl_eventsmd($file, $min_version, $max_version, $events)
+ {
+ $exporter = new \phpbb\event\md_exporter(dirname(__FILE__) . '/fixtures/', null, $min_version, $max_version);
+ $this->assertSame(sizeof($events), $exporter->crawl_eventsmd($file, 'adm'));
+ $this->assertEquals($events, $exporter->get_events());
+ }
+
+ static public function crawl_phpbb_eventsmd_data()
+ {
+ return array(
+ array('styles'),
+ array('adm'),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_phpbb_eventsmd_data
+ */
+ public function test_crawl_phpbb_eventsmd($filter)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter));
+ }
+
+ static public function crawl_template_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $data_provider = array();
+
+ $styles = array(
+ 'adm/style/' => 'adm',
+ 'styles/prosilver/template/' => 'styles',
+ 'styles/subsilver2/template/' => 'styles',
+ );
+ foreach ($styles as $path => $filter)
+ {
+ $files = $exporter->get_recursive_file_list($phpbb_root_path . $path, $path);
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($filter, $path . $file);
+ }
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_template_file_data
+ */
+ public function test_crawl_template_file($filter, $file)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $exporter->crawl_eventsmd('docs/events.md', $filter);
+ $events = $exporter->crawl_file_for_events($file);
+
+ $this->assertGreaterThanOrEqual(0, sizeof($events));
+ $this->assertTrue($exporter->validate_events_from_file($file, $events));
+ }
+}
diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php
new file mode 100644
index 0000000000..692a57f93c
--- /dev/null
+++ b/tests/event/php_exporter_test.php
@@ -0,0 +1,740 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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_event_php_exporter_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/');
+ }
+
+ static public function crawl_php_file_data()
+ {
+ return array(
+ array(
+ 'default.test',
+ array(
+ 'default.dispatch' => array(
+ 'event' => 'default.dispatch',
+ 'file' => 'default.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'extra_description.test',
+ array(
+ 'extra_description.dispatch' => array(
+ 'event' => 'extra_description.dispatch',
+ 'file' => 'extra_description.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'trigger.test',
+ array(
+ 'core.trigger' => array(
+ 'event' => 'core.trigger',
+ 'file' => 'trigger.test',
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
+ 'since' => '3.1.0-a3',
+ 'description' => 'Event after the post data has been assigned to the template',
+ ),
+ ),
+ ),
+ array(
+ 'trigger_wspace.test',
+ array(
+ 'core.trigger' => array(
+ 'event' => 'core.trigger',
+ 'file' => 'trigger_wspace.test',
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
+ 'since' => '3.1.0-a3',
+ 'description' => 'Event after the post data has been assigned to the template',
+ ),
+ ),
+ ),
+ array(
+ 'trigger_many_vars.test',
+ array(
+ 'core.posting_modify_template_vars' => array(
+ 'event' => 'core.posting_modify_template_vars',
+ 'file' => 'trigger_many_vars.test',
+ 'arguments' => array(
+ 'cancel', 'delete', 'error', 'form_enctype', 'forum_id',
+ 'load', 'message_parser', 'mode', 'moderators', 'page_data',
+ 'page_title', 'post_data', 'post_id', 'preview', 'refresh',
+ 's_action', 's_hidden_fields', 's_topic_icons', 'save',
+ 'submit', 'topic_id',
+ ),
+ 'since' => '3.1.0-a1',
+ 'description' => 'This event allows you to modify template variables for the posting screen',
+ ),
+ ),
+ ),
+ array(
+ 'none.test',
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file, $expected)
+ {
+ $this->exporter->crawl_php_file($file);
+ $this->assertEquals($expected, $this->exporter->get_events());
+ }
+
+ static public function crawl_php_file_throws_data()
+ {
+ return array(
+ array('missing_var.test', null),
+ array('duplicate_event.test', 10),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_throws_data
+ */
+ public function test_crawl_php_file_throws($file, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->crawl_php_file($file);
+ }
+
+ static public function validate_since_data()
+ {
+ return array(
+ array('* @since 3.1.0-a1', '3.1.0-a1'),
+ array('* @since 3.1.0-b3', '3.1.0-b3'),
+ array(' * @since 3.1.0-b3', '3.1.0-b3'),
+ array('* @since 3.1.0-RC2', '3.1.0-RC2'),
+ array(' * @since 3.1.0-a1', '3.1.0-a1'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_data
+ */
+ public function test_validate_since($since, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_since($since));
+ }
+
+ static public function validate_since_throws_data()
+ {
+ return array(
+ array('* @since 3.1.0-a1 '),
+ array('* @since 3.1.0-a1 bertie is cool'),
+ array('bertie* @since 3.1.0-a1'),
+ array('* @since 3.1-A2'),
+ array('* @since 3.1.0-rc1'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_since_throws($since)
+ {
+ $this->exporter->validate_since($since);
+ }
+
+ static public function validate_event_data()
+ {
+ return array(
+ array('test.event', '* @event test.event', 'test.event'),
+ array('test.event2', ' * @event test.event2', 'test.event2'),
+ array('test.event', ' * @event test.event', 'test.event'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_data
+ */
+ public function test_validate_event($event_name, $event, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_event($event_name, $event));
+ }
+
+ static public function validate_event_throws_data()
+ {
+ return array(
+ array('test.event', '* @event test.event bertie is cool', 2),
+ array('test.event', 'bertie* @event test.event', 2),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_event_throws($event_name, $event, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->validate_event($event_name, $event);
+ }
+
+ static public function validate_vars_docblock_array_data()
+ {
+ return array(
+ array(array('abc', 'def'), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_data
+ */
+ public function test_validate_vars_docblock_array($vars_array, $vars_docblock)
+ {
+ $this->assertNull($this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock));
+ }
+
+ static public function validate_vars_docblock_array_throws_data()
+ {
+ return array(
+ array(array('abc', 'def'), array()),
+ array(array('abc', 'def'), array('abc')),
+ array(array('abc', 'defg'), array('abc', 'def')),
+ array(array('abc'), array('abc', 'def')),
+ array(array(), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock)
+ {
+ $this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock);
+ }
+
+ static public function get_dispatch_name_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'),
+ array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_data
+ */
+ public function test_get_dispatch_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, true));
+ }
+
+ static public function get_dispatch_name_throws_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch();"),
+ array("\$phpbb_dispatcher->dispatch('');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch.2one');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch');"),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_dispatch_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, true);
+ }
+
+ static public function get_trigger_event_name_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'),
+ array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_data
+ */
+ public function test_get_trigger_event_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, false));
+ }
+
+ static public function get_trigger_event_name_throws_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event());"),
+ array("extract(\$phpbb_dispatcher->trigger_event(''));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.2one'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"),
+ array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_trigger_event_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, false);
+ }
+
+ static public function get_vars_from_array_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\');',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ array('bertie'),
+ ),
+ array(
+ array(
+ "\t/**",
+ "\t*/",
+ "\t\$vars = array('_Strange123', 'phpBB3_Test');",
+ "\t\$this->dispatcher->dispatch('test');",
+ ),
+ 3,
+ array('_Strange123', 'phpBB3_Test'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_data
+ */
+ public function test_get_vars_from_array($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_array());
+ }
+
+ static public function get_vars_from_array_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 2,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = $bertie;',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'$bertie\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array();',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'t1\', \'t2\', \'t3\', \'t4\', \'t5\', \'t6\', \'t7\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'test2\', \'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\',\'basically_valid\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_array_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_array();
+ }
+
+ static public function get_vars_from_docblock_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ array('name1', 'name2'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_data
+ */
+ public function test_get_vars_from_docblock($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_docblock());
+ }
+
+ static public function get_vars_from_docblock_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 2,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array $name2 Description',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 4,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_docblock();
+ }
+
+ static public function find_since_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '* @since 3.1.0-a1',
+ '/**',
+ '* @since 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_data
+ */
+ public function test_find_since($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_since());
+ }
+
+ static public function find_since_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @var',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_since_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_since();
+ }
+
+ static public function find_description_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* Hello Bertie!',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ ' /**',
+ ' * Hello Bertie!',
+ ' *',
+ ' * @since 3.1.0-a1',
+ ' * @changed 3.1.0-a2',
+ ' */',
+ ' $phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 6,
+ 1,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_data
+ */
+ public function test_find_description($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_description());
+ }
+
+ static public function find_description_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*',
+ '* @since 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* ',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_description_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_description();
+ }
+}