|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TwinDigital\WPTools\Router; |
|
4
|
|
|
|
|
5
|
|
|
use WP_UnitTestCase; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class RouterTest extends WP_UnitTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Setup |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testSetupRoutes() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->set_permalink_structure('/%postname%/'); |
|
25
|
|
|
add_action('testhook', '__return_true'); |
|
26
|
|
|
add_filter( |
|
27
|
|
|
'td_wptools_route_routes', |
|
28
|
|
|
function () { |
|
29
|
|
|
return |
|
30
|
|
|
[ |
|
31
|
|
|
'testroute' => |
|
32
|
|
|
(new Route('testhookurl', 'testhook', 'page')), |
|
33
|
|
|
]; |
|
34
|
|
|
}, |
|
35
|
|
|
10, |
|
36
|
|
|
1 |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$router = Router::init(); |
|
40
|
|
|
$this->assertFalse( |
|
41
|
|
|
get_option($router->getRouteVariable() . '_hash'), |
|
42
|
|
|
'router-compile should not be saved yet' |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
$router->registerRoutes(); |
|
46
|
|
|
$this->assertNotEmpty(get_option($router->getRouteVariable() . '_hash')); |
|
47
|
|
|
|
|
48
|
|
|
flush_rewrite_rules(true); |
|
49
|
|
|
$this->assertEquals('a', $router->loadRouteTemplate('a')); |
|
50
|
|
|
|
|
51
|
|
|
$this->go_to(site_url('/')); |
|
52
|
|
|
$this->assertTrue(is_home()); |
|
53
|
|
|
$this->go_to(site_url('/testhookurl')); |
|
54
|
|
|
$this->assertFalse(is_404()); |
|
55
|
|
|
$this->assertEquals(1, did_action('init')); |
|
56
|
|
|
$this->assertEquals(1, did_action('testhook')); |
|
57
|
|
|
$this->assertStringEndsWith('page.php', $router->loadRouteTemplate('post')); |
|
58
|
|
|
|
|
59
|
|
|
$this->go_to(site_url('/')); |
|
60
|
|
|
$router->deleteRoute('testroute'); |
|
61
|
|
|
$this->expectException('WPDieException'); |
|
62
|
|
|
$this->go_to(site_url('/testhookurl')); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths