Skip to content

Commit e44d61d

Browse files
committed
Add tests
1 parent c3d4e01 commit e44d61d

5 files changed

Lines changed: 278 additions & 0 deletions

File tree

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<directory suffix=".php">./language/</directory>
2929
<directory suffix=".php">./migrations/</directory>
3030
<directory suffix=".php">./tests/</directory>
31+
<file>./routing/page_loader_phpbb4.php</file>
3132
</exclude>
3233
</whitelist>
3334
</filter>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\pages\tests\routing;
12+
13+
class page_loader_core_test extends \phpbb_database_test_case
14+
{
15+
protected static function setup_extensions()
16+
{
17+
return array('phpbb/pages');
18+
}
19+
20+
/** @var \phpbb\db\driver\driver_interface */
21+
protected $db;
22+
23+
/** @var \phpbb\pages\routing\page_loader_core */
24+
protected $loader;
25+
26+
public function getDataSet()
27+
{
28+
return $this->createXMLDataSet(__DIR__ . '/../operators/fixtures/page.xml');
29+
}
30+
31+
protected function setUp(): void
32+
{
33+
parent::setUp();
34+
$this->db = $this->new_dbal();
35+
$this->loader = new \phpbb\pages\routing\page_loader_core($this->db, 'phpbb_pages');
36+
}
37+
38+
public function test_load_routes_returns_collection()
39+
{
40+
$collection = $this->loader->load_routes();
41+
self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
42+
}
43+
44+
public static function route_data()
45+
{
46+
return array(
47+
array(1, '/page_1'),
48+
array(2, '/page_2'),
49+
array(3, '/page_3'),
50+
array(4, '/page_4'),
51+
);
52+
}
53+
54+
/**
55+
* @dataProvider route_data
56+
*/
57+
public function test_routes_have_correct_paths($id, $expected)
58+
{
59+
$collection = $this->loader->load_routes();
60+
$route = $collection->get('phpbb_pages_dynamic_route_' . $id);
61+
self::assertInstanceOf('Symfony\Component\Routing\Route', $route);
62+
self::assertSame($expected, $route->getPath());
63+
}
64+
65+
public function test_supports_type()
66+
{
67+
self::assertTrue($this->loader->supports_type('phpbb_pages_route'));
68+
self::assertFalse($this->loader->supports_type('other_type'));
69+
self::assertFalse($this->loader->supports_type(null));
70+
}
71+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\pages\tests\routing;
12+
13+
use ReflectionMethod;
14+
use Symfony\Component\Config\Loader\LoaderInterface;
15+
16+
class page_loader_phpbb3_test extends \phpbb_database_test_case
17+
{
18+
protected static function setup_extensions()
19+
{
20+
return array('phpbb/pages');
21+
}
22+
23+
/** @var \phpbb\db\driver\driver_interface */
24+
protected $db;
25+
26+
/** @var \phpbb\pages\routing\page_loader_phpbb3 */
27+
protected $loader;
28+
29+
public function getDataSet()
30+
{
31+
return $this->createXMLDataSet(__DIR__ . '/../operators/fixtures/page.xml');
32+
}
33+
34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
$method = new ReflectionMethod(LoaderInterface::class, 'load');
39+
if ($method->hasReturnType())
40+
{
41+
self::markTestSkipped('phpbb3 adapter tests only run on Symfony 3-6 (phpBB3)');
42+
}
43+
44+
$this->db = $this->new_dbal();
45+
$this->loader = new \phpbb\pages\routing\page_loader_phpbb3($this->db, 'phpbb_pages');
46+
}
47+
48+
public function test_load_returns_collection()
49+
{
50+
$collection = $this->loader->load('resource', 'phpbb_pages_route');
51+
self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
52+
}
53+
54+
public function test_load_with_null_type()
55+
{
56+
$collection = $this->loader->load('resource', null);
57+
self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
58+
}
59+
60+
public function test_load_throws_on_invalid_type()
61+
{
62+
$this->expectException(\InvalidArgumentException::class);
63+
$this->expectExceptionMessage('Type must be string or null');
64+
$this->loader->load('resource', 123);
65+
}
66+
67+
public function test_supports()
68+
{
69+
self::assertTrue($this->loader->supports('resource', 'phpbb_pages_route'));
70+
self::assertFalse($this->loader->supports('resource', 'other_type'));
71+
}
72+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\pages\tests\routing;
12+
13+
use ReflectionMethod;
14+
use Symfony\Component\Config\Loader\LoaderInterface;
15+
16+
class page_loader_phpbb4_test extends \phpbb_database_test_case
17+
{
18+
protected static function setup_extensions()
19+
{
20+
return array('phpbb/pages');
21+
}
22+
23+
/** @var \phpbb\db\driver\driver_interface */
24+
protected $db;
25+
26+
/** @var \phpbb\pages\routing\page_loader_phpbb4 */
27+
protected $loader;
28+
29+
public function getDataSet()
30+
{
31+
return $this->createXMLDataSet(__DIR__ . '/../operators/fixtures/page.xml');
32+
}
33+
34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
$method = new ReflectionMethod(LoaderInterface::class, 'load');
39+
if (!$method->hasReturnType())
40+
{
41+
self::markTestSkipped('phpbb4 adapter tests only run on Symfony 7+ (phpBB4)');
42+
}
43+
44+
$this->db = $this->new_dbal();
45+
$this->loader = new \phpbb\pages\routing\page_loader_phpbb4($this->db, 'phpbb_pages');
46+
}
47+
48+
public function test_load_returns_collection()
49+
{
50+
$collection = $this->loader->load('resource', 'phpbb_pages_route');
51+
self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
52+
}
53+
54+
public function test_load_with_null_type()
55+
{
56+
$collection = $this->loader->load('resource', null);
57+
self::assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
58+
}
59+
60+
public function test_supports()
61+
{
62+
self::assertTrue($this->loader->supports('resource', 'phpbb_pages_route'));
63+
self::assertFalse($this->loader->supports('resource', 'other_type'));
64+
}
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\pages\tests\routing;
12+
13+
use ReflectionMethod;
14+
use Symfony\Component\Config\Loader\LoaderInterface;
15+
16+
class page_loader_version_detection_test extends \phpbb_test_case
17+
{
18+
protected static function setup_extensions()
19+
{
20+
return array('phpbb/pages');
21+
}
22+
23+
public function test_page_loader_class_exists()
24+
{
25+
self::assertTrue(class_exists(\phpbb\pages\routing\page_loader::class));
26+
}
27+
28+
public function test_page_loader_extends_correct_adapter()
29+
{
30+
$method = new ReflectionMethod(LoaderInterface::class, 'load');
31+
32+
if ($method->hasReturnType())
33+
{
34+
self::assertInstanceOf(\phpbb\pages\routing\page_loader_phpbb4::class,
35+
new \phpbb\pages\routing\page_loader($this->createMock(\phpbb\db\driver\driver_interface::class), 'test_table'),
36+
'page_loader should extend page_loader_phpbb4 when LoaderInterface::load() has return type (Symfony 7/phpBB4)'
37+
);
38+
}
39+
else
40+
{
41+
self::assertInstanceOf(\phpbb\pages\routing\page_loader_phpbb3::class,
42+
new \phpbb\pages\routing\page_loader($this->createMock(\phpbb\db\driver\driver_interface::class), 'test_table'),
43+
'page_loader should extend page_loader_phpbb3 when LoaderInterface::load() has no return type (Symfony 3-6/phpBB3)'
44+
);
45+
}
46+
}
47+
48+
public function test_version_detection_logic()
49+
{
50+
$method = new ReflectionMethod(LoaderInterface::class, 'load');
51+
$hasReturnType = $method->hasReturnType();
52+
53+
$reflection = new \ReflectionClass(\phpbb\pages\routing\page_loader::class);
54+
$parent = $reflection->getParentClass();
55+
56+
if ($hasReturnType)
57+
{
58+
self::assertSame(\phpbb\pages\routing\page_loader_phpbb4::class, $parent->getName(),
59+
'Symfony 7+ detected: page_loader must extend page_loader_phpbb4'
60+
);
61+
}
62+
else
63+
{
64+
self::assertSame(\phpbb\pages\routing\page_loader_phpbb3::class, $parent->getName(),
65+
'Symfony 3-6 detected: page_loader must extend page_loader_phpbb3'
66+
);
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)