Aleksander Machniak
2016-05-20 9e64dc2debfa1c7410f82bf71f4d10856751e258
commit | author | age
06fdaf 1 <?php
TB 2
3 /**
4  * Test class to test rcmail class
5  *
6  * @package Tests
7  */
8 class RcmailFunc extends PHPUnit_Framework_TestCase
9 {
10     function setUp()
11     {
12         // set some HTTP env vars
13         $_SERVER['HTTP_HOST'] = 'mail.example.org';
14         $_SERVER['SERVER_PORT'] = '443';
15         $_SERVER['SCRIPT_NAME'] = '/sub/index.php';
16         $_SERVER['HTTPS'] = true;
17
18         rcmail::get_instance()->filename = '';
19     }
20
21     /**
22      * Class constructor
23      */
24     function test_class()
25     {
26         $object = rcmail::get_instance();
27         $this->assertInstanceOf('rcmail', $object, "Class singleton");
28     }
29
30     /**
31      * Test rcmail::url()
32      */
33     function test_url()
34     {
35         $rcmail = rcmail::get_instance();
36         $this->assertEquals(
37             './?_task=cli&_action=test',
38             $rcmail->url('test'),
39             "Action only"
40         );
41         $this->assertEquals(
42             './?_task=cli&_action=test&_a=AA',
43             $rcmail->url(array('action' => 'test', 'a' => 'AA')),
44             "Unprefixed parameters"
45         );
46         $this->assertEquals(
47             './?_task=cli&_action=test&_b=BB',
48             $rcmail->url(array('_action' => 'test', '_b' => 'BB', '_c' => null)),
49             "Prefixed parameters (skip empty)"
50         );
51         $this->assertEquals(
52             '/sub/?_task=cli&_action=test&_mode=ABS',
53             $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
54             "Absolute URL"
55         );
56
57         $this->assertEquals(
58             'https://mail.example.org/sub/?_task=calendar&_action=test&_mode=FQ',
59             $rcmail->url(array('task' => 'calendar', '_action' => 'test', '_mode' => 'FQ'), true, true),
60             "Fully Qualified URL"
61         );
62
63         // with different SCRIPT_NAME values
64         $_SERVER['SCRIPT_NAME'] = 'index.php';
65         $this->assertEquals(
66             '/?_task=cli&_action=test&_mode=ABS',
67             $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
68             "Absolute URL (root)"
69         );
70         $_SERVER['SCRIPT_NAME'] = '';
71         $this->assertEquals(
72             '/?_task=cli&_action=test&_mode=ABS',
73             $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true),
74             "Absolute URL (root)"
75         );
76
77         $_SERVER['HTTPS'] = false;
78         $_SERVER['SERVER_PORT'] = '8080';
79         $this->assertEquals(
80             'http://mail.example.org:8080/?_task=cli&_action=test&_mode=ABS',
81             $rcmail->url(array('_action' => 'test', '_mode' => 'ABS'), true, true),
82             "Full URL with port"
83         );
84     }
85 }