1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-01 14:30:32 +02:00

[ticket/12273] Add more tests for the event exporter

PHPBB3-12273
This commit is contained in:
Joas Schilling
2014-04-18 00:31:06 +02:00
parent 4a3756741c
commit 91deb4419b
6 changed files with 424 additions and 40 deletions

View File

@@ -48,17 +48,21 @@ class phpbb_event_exporter_test extends phpbb_test_case
),
),
array(
'legacy_alpha1_version.test',
'trigger.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',
'core.trigger' => array(
'event' => 'core.trigger',
'file' => 'trigger.test',
'arguments' => array('attachments', 'cp_row', 'current_row_number', 'end', 'post_row', 'row', 'start', 'user_poster_data'),
'since' => '3.1.0-a3',
'description' => 'Event after the post data has been assigned to the template',
),
),
),
array(
'none.test',
array(),
),
);
}
@@ -145,6 +149,289 @@ class phpbb_event_exporter_test extends phpbb_test_case
$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->assertEquals($expected, $this->exporter->get_dispatch_name('', $event_line));
}
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->get_dispatch_name('', $event_line);
}
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->assertEquals($expected, $this->exporter->get_trigger_event_name('', $event_line));
}
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->get_trigger_event_name('', $event_line);
}
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->assertEquals($expected, $this->exporter->get_vars_from_array('', '', $lines, $event_line));
}
static public function get_vars_from_array_throws_data()
{
return array(
array(
array(
'/**',
'*/',
'$vars = $bertie;',
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
1,
),
array(
array(
'/**',
'*/',
'$vars = array();',
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
1,
),
array(
array(
'/**',
'*/',
'$vars = array(\'\');',
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
2,
),
array(
array(
'/**',
'*/',
'$vars = array(\'$bertie\');',
'$phpbb_dispatcher->dispatch(\'test\');',
),
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->get_vars_from_array('', '', $lines, $event_line);
}
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->assertEquals($expected, $this->exporter->get_vars_from_docblock('', '', $lines, $event_line));
}
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->get_vars_from_docblock('', '', $lines, $event_line);
}
static public function find_since_data()
{
return array(

View File

@@ -1,9 +0,0 @@
<?php
/**
* Description
*
* @event legacy_alpha1_version.dispatch
* @since 3.1-A1
*/
$phpbb_dispatcher->dispatch('legacy_alpha1_version.dispatch');

View File

@@ -0,0 +1,18 @@
<?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
* @var array post_row Template block array of the post
* @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)));

View File

@@ -0,0 +1,6 @@
<?php
/**
* Hi there :)
*/
echo 1 + 2;

View File

@@ -0,0 +1,18 @@
<?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
* @var array post_row Template block array of the post
* @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)));