Passed
Push — master ( ecde40...94c840 )
by Lucien
01:50
created

RouterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetupRoutes() 0 41 1
A setUp() 0 3 1
1
<?php
2
3
namespace TwinDigital\WPTools\Router;
4
5
use WP_UnitTestCase;
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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