summaryrefslogtreecommitdiff
path: root/tests/units/Helper/UrlHelperTest.php
blob: 34ab7604cf9842851e43b24769663951f4c8b98d (plain)
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
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Helper\UrlHelper;
use Kanboard\Model\Config;
use Kanboard\Core\Http\Request;

class UrlHelperTest extends Base
{
    public function testPluginLink()
    {
        $h = new UrlHelper($this->container);
        $this->assertEquals(
            '<a href="?controller=a&amp;action=b&amp;d=e&amp;plugin=something" class="f" title=\'g\' target="_blank">label</a>',
            $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true)
        );
    }

    public function testPluginLinkWithRouteDefined()
    {
        $this->container['route']->enable();
        $this->container['route']->addRoute('/myplugin/something/:d', 'a', 'b', 'something');

        $h = new UrlHelper($this->container);
        $this->assertEquals(
            '<a href="myplugin/something/e" class="f" title=\'g\' target="_blank">label</a>',
            $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true)
        );
    }

    public function testAppLink()
    {
        $h = new UrlHelper($this->container);
        $this->assertEquals(
            '<a href="?controller=a&amp;action=b&amp;d=e" class="f" title=\'g\' target="_blank">label</a>',
            $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true)
        );
    }

    public function testHref()
    {
        $h = new UrlHelper($this->container);
        $this->assertEquals(
            '?controller=a&amp;action=b&amp;d=e',
            $h->href('a', 'b', array('d' => 'e'))
        );
    }

    public function testTo()
    {
        $h = new UrlHelper($this->container);
        $this->assertEquals(
            '?controller=a&action=b&d=e',
            $h->to('a', 'b', array('d' => 'e'))
        );
    }

    public function testDir()
    {
        $this->container['request'] = new Request($this->container, array(
                'PHP_SELF' => '/kanboard/index.php',
                'REQUEST_METHOD' => 'GET'
            )
        );

        $h = new UrlHelper($this->container);
        $this->assertEquals('/kanboard/', $h->dir());

        $this->container['request'] = new Request($this->container, array(
                'PHP_SELF' => '/index.php',
                'REQUEST_METHOD' => 'GET'
            )
        );

        $h = new UrlHelper($this->container);
        $this->assertEquals('/', $h->dir());
    }

    public function testServer()
    {
        $this->container['request'] = new Request($this->container, array(
                'PHP_SELF' => '/index.php',
                'REQUEST_METHOD' => 'GET',
                'SERVER_NAME' => 'localhost',
                'SERVER_PORT' => 80,
            )
        );

        $h = new UrlHelper($this->container);
        $this->assertEquals('http://localhost/', $h->server());

        $this->container['request'] = new Request($this->container, array(
                'PHP_SELF' => '/index.php',
                'REQUEST_METHOD' => 'GET',
                'SERVER_NAME' => 'kb',
                'SERVER_PORT' => 1234,
            )
        );

        $h = new UrlHelper($this->container);
        $this->assertEquals('http://kb:1234/', $h->server());
    }

    public function testBase()
    {
        $this->container['request'] = new Request($this->container, array(
                'PHP_SELF' => '/index.php',
                'REQUEST_METHOD' => 'GET',
                'SERVER_NAME' => 'kb',
                'SERVER_PORT' => 1234,
            )
        );

        $h = new UrlHelper($this->container);
        $this->assertEquals('http://kb:1234/', $h->base());

        $c = new Config($this->container);
        $c->save(array('application_url' => 'https://mykanboard/'));
        $this->container['memoryCache']->flush();

        $h = new UrlHelper($this->container);
        $this->assertEquals('https://mykanboard/', $c->get('application_url'));
        $this->assertEquals('https://mykanboard/', $h->base());
    }
}