From 06fdaf88cb1a355e445294beba4a89d0209ac71e Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 13 Aug 2014 19:15:12 +0200 Subject: Extend rcmail::url() to produce absolute and fully qualified URLs --- tests/RcmailFunc.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/phpunit.xml | 1 + 2 files changed, 86 insertions(+) create mode 100644 tests/RcmailFunc.php (limited to 'tests') diff --git a/tests/RcmailFunc.php b/tests/RcmailFunc.php new file mode 100644 index 000000000..09b54b22c --- /dev/null +++ b/tests/RcmailFunc.php @@ -0,0 +1,85 @@ +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" + ); + } +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 4d50ad6a0..5c27d0e0d 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -46,6 +46,7 @@ Framework/VCard.php Framework/Washtml.php MailFunc.php + RcmailFunc.php ./../plugins/acl/tests/Acl.php -- cgit v1.2.3