1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @group functional
*/
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
{
protected $phpbb_extension_manager;
/**
* This should only be called once before the tests are run.
* This is used to copy the fixtures to the phpBB install
*/
static public function setUpBeforeClass()
{
global $phpbb_root_path;
parent::setUpBeforeClass();
// these directories need to be created before the files can be copied
$directories = array(
$phpbb_root_path . 'ext/error/class/',
$phpbb_root_path . 'ext/error/classtype/',
$phpbb_root_path . 'ext/error/disabled/',
$phpbb_root_path . 'ext/foo/bar/',
$phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/',
$phpbb_root_path . 'ext/foobar/',
$phpbb_root_path . 'ext/foobar/styles/prosilver/template/',
);
foreach ($directories as $dir)
{
if (!is_dir($dir))
{
mkdir($dir, 0777, true);
}
}
$fixtures = array(
'error/class/controller.php',
'error/class/ext.php',
'error/classtype/controller.php',
'error/classtype/ext.php',
'error/disabled/controller.php',
'error/disabled/ext.php',
'foo/bar/controller.php',
'foo/bar/ext.php',
'foo/bar/styles/prosilver/template/foobar_body.html',
'foobar/controller.php',
'foobar/ext.php',
'foobar/styles/prosilver/template/foobar_body.html',
);
foreach ($fixtures as $fixture)
{
if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"))
{
echo 'Could not copy file ' . $fixture;
}
}
}
public static function tearDownAfterClass()
{
$phpbb_root_path = self::$config['phpbb_functional_path'];
// @todo delete the fixtures from the $phpbb_root_path board
// Note that it might be best to find a public domain function
// and port it into here instead of writing it from scratch
}
public function setUp()
{
parent::setUp();
$this->phpbb_extension_manager = $this->get_extension_manager();
$this->purge_cache();
}
/**
* Check an extension at ./ext/foobar/ which should have the class
* phpbb_ext_foobar_controller
*/
public function test_foobar()
{
$this->phpbb_extension_manager->enable('foobar');
$crawler = $this->request('GET', 'index.php?ext=foobar');
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
$this->phpbb_extension_manager->purge('foobar');
}
/**
* Check an extension at ./ext/foo/bar/ which should have the class
* phpbb_ext_foo_bar_controller
*/
public function test_foo_bar()
{
$this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'index.php?ext=foo/bar');
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
$this->phpbb_extension_manager->purge('foo/bar');
}
/**
* Check the error produced by extension at ./ext/error/class which has class
* phpbb_ext_foobar_controller
*/
public function test_error_class_name()
{
$this->phpbb_extension_manager->enable('error/class');
$crawler = $this->request('GET', 'index.php?ext=error/class');
$this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text());
$this->phpbb_extension_manager->purge('error/class');
}
/**
* Check the error produced by extension at ./ext/error/classtype which has class
* phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface
*/
public function test_error_class_type()
{
$this->phpbb_extension_manager->enable('error/classtype');
$crawler = $this->request('GET', 'index.php?ext=error/classtype');
$this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text());
$this->phpbb_extension_manager->purge('error/classtype');
}
/**
* Check the error produced by extension at ./ext/error/disabled that is (obviously)
* a disabled extension
*/
public function test_error_ext_disabled()
{
$crawler = $this->request('GET', 'index.php?ext=error/disabled');
$this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text());
}
/**
* Check the error produced by extension at ./ext/error/404 that is (obviously)
* not existant
*/
public function test_error_ext_missing()
{
$crawler = $this->request('GET', 'index.php?ext=error/404');
$this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text());
}
}
|