summaryrefslogtreecommitdiff
path: root/tests/RcmailFunc.php
blob: 09b54b22c5f3732e4c5f9ade21eeb9bffa8b0053 (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
<?php

/**
 * Test class to test rcmail class
 *
 * @package Tests
 */
class RcmailFunc extends PHPUnit_Framework_TestCase
{
    function setUp()
    {
        // set some HTTP env vars
        $_SERVER['HTTP_HOST'] = 'mail.example.org';
        $_SERVER['SERVER_PORT'] = '443';
        $_SERVER['SCRIPT_NAME'] = '/sub/index.php';
        $_SERVER['HTTPS'] = true;

        rcmail::get_instance()->filename = '';
    }

    /**
     * Class constructor
     */
    function test_class()
    {
        $object = rcmail::get_instance();
        $this->assertInstanceOf('rcmail', $object, "Class singleton");
    }

    /**
     * Test rcmail::url()
     */
    function test_url()
    {
        $rcmail = rcmail::get_instance();
        $this->assertEquals(
            './?_task=cli&_action=test',
            $rcmail->url('test'),
            "Action only"
        );
        $this->assertEquals(
            './?_task=cli&_action=test&_a=AA',
            $rcmail->url(array('action' => 'test', 'a' => 'AA')),
            "Unprefixed parameters"
        );
        $this->assertEquals(
            './?_task=cli&_action=test&_b=BB',
            $rcmail->url(array('_action' => 'test', '_b' => 'BB', '_c' => null)),
            "Prefixed parameters (skip empty)"
        );
        $this->assertEquals(
            '/sub/?_task=cli&_action=test&_mode=ABS',
            $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
            "Absolute URL"
        );

        $this->assertEquals(
            'https://mail.example.org/sub/?_task=calendar&_action=test&_mode=FQ',
            $rcmail->url(array('task' => 'calendar', '_action' => 'test', '_mode' => 'FQ'), true, true),
            "Fully Qualified URL"
        );

        // with different SCRIPT_NAME values
        $_SERVER['SCRIPT_NAME'] = 'index.php';
        $this->assertEquals(
            '/?_task=cli&_action=test&_mode=ABS',
            $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
            "Absolute URL (root)"
        );
        $_SERVER['SCRIPT_NAME'] = '';
        $this->assertEquals(
            '/?_task=cli&_action=test&_mode=ABS',
            $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
            "Absolute URL (root)"
        );

        $_SERVER['HTTPS'] = false;
        $_SERVER['SERVER_PORT'] = '8080';
        $this->assertEquals(
            'http://mail.example.org:8080/?_task=cli&_action=test&_mode=ABS',
            $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true, true),
            "Full URL with port"
        );
    }
}