|
| 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 | +} |
0 commit comments