summaryrefslogtreecommitdiff
path: root/tests/units/UrlHelperTest.php
blob: d70842aac0266d9159c75596b9e4318973074f2f (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
<?php

require_once __DIR__.'/Base.php';

use Helper\Url;
use Model\Config;

class UrlHelperTest extends Base
{
    public function testLink()
    {
        $h = new Url($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 Url($this->container);
        $this->assertEquals(
            '?controller=a&amp;action=b&amp;d=e',
            $h->href('a', 'b', array('d' => 'e'))
        );
    }

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

    public function testServer()
    {
        $h = new Url($this->container);

        $_SERVER['PHP_SELF'] = '/';
        $_SERVER['SERVER_NAME'] = 'localhost';
        $_SERVER['SERVER_PORT'] = 1234;

        $this->assertEquals('http://localhost:1234/', $h->server());
    }

    public function testBase()
    {
        $h = new Url($this->container);

        $_SERVER['PHP_SELF'] = '/';
        $_SERVER['SERVER_NAME'] = 'localhost';
        $_SERVER['SERVER_PORT'] = 1234;

        $this->assertEquals('http://localhost:1234/', $h->base());

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

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