aboutsummaryrefslogtreecommitdiffstats
path: root/tests/event
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-04-17 15:00:14 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-04-18 12:55:12 +0200
commit22de4a5927eccf05d614a6da7f6eb6f993838487 (patch)
tree2149f6a1d5f264ab319020377dedbc4a564bf61a /tests/event
parent0da5e3bee9567138431d097aa1a4bea6d1fe2281 (diff)
downloadforums-22de4a5927eccf05d614a6da7f6eb6f993838487.tar
forums-22de4a5927eccf05d614a6da7f6eb6f993838487.tar.gz
forums-22de4a5927eccf05d614a6da7f6eb6f993838487.tar.bz2
forums-22de4a5927eccf05d614a6da7f6eb6f993838487.tar.xz
forums-22de4a5927eccf05d614a6da7f6eb6f993838487.zip
[ticket/12273] Add a basic set of tests for the exporter
PHPBB3-12273
Diffstat (limited to 'tests/event')
-rw-r--r--tests/event/exporter_test.php341
-rw-r--r--tests/event/fixtures/default.test9
-rw-r--r--tests/event/fixtures/extra_description.test11
-rw-r--r--tests/event/fixtures/legacy_alpha1_version.test9
4 files changed, 370 insertions, 0 deletions
diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php
new file mode 100644
index 0000000000..ee9c9267b2
--- /dev/null
+++ b/tests/event/exporter_test.php
@@ -0,0 +1,341 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/develop/event_exporter.php';
+
+class phpbb_event_exporter_test extends phpbb_test_case
+{
+ /** @var \event_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->exporter = new \event_exporter(dirname(__FILE__) . '/fixtures/');
+ }
+
+ static public function check_for_events_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(
+ 'legacy_alpha1_version.test',
+ array(
+ 'legacy_alpha1_version.dispatch' => array(
+ 'event' => 'legacy_alpha1_version.dispatch',
+ 'file' => 'legacy_alpha1_version.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-a1',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider check_for_events_data
+ */
+ public function test_check_for_events($file, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->check_for_events($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-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', 1),
+ array('* @since 3.1.0-a1 ', 1),
+ array('* @since 3.1.0-a1 bertie is cool', 2),
+ array('bertie* @since 3.1.0-a1', 2),
+ array('* @since 3.1-A2', 2),
+ array('* @since 3.1-B3', 2),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_since_throws($since, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $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'),
+ );
+ }
+
+ /**
+ * @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', 1),
+ 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 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->assertEquals($expected, $this->exporter->find_since('', '', $lines, $event_line));
+ }
+
+ 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->find_since('', '', $lines, $event_line);
+ }
+
+ 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->assertEquals($expected, $this->exporter->find_description('', '', $lines, $event_line));
+ }
+
+ 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->find_description('', '', $lines, $event_line);
+ }
+}
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/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/legacy_alpha1_version.test b/tests/event/fixtures/legacy_alpha1_version.test
new file mode 100644
index 0000000000..064af4daf8
--- /dev/null
+++ b/tests/event/fixtures/legacy_alpha1_version.test
@@ -0,0 +1,9 @@
+<?php
+
+/**
+* Description
+*
+* @event legacy_alpha1_version.dispatch
+* @since 3.1-A1
+*/
+$phpbb_dispatcher->dispatch('legacy_alpha1_version.dispatch');