3 class XHTMLCompiler_FunctionsTest
extends XHTMLCompilerHarness
6 function test_set_response_code() {
7 $this->php
->expectAt(0, 'header', array($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404));
8 $this->php
->expectAt(1, 'header', array('Status: 404 Not Found'));
9 set_response_code(404);
12 function test_exception_handler() {
13 $this->php
->expect('paint', array(new PatternExpectation('/404 Not Found/')));
14 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404));
15 $this->php
->expect('paint', array(new PatternExpectation('/WTF/')));
16 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404, 'WTF'));
17 $this->php
->expect('paint', array(new PatternExpectation('/404 Not Found.+?Could not find the file/')));
18 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404, false, 'Could not find the file'));
21 function test_get_page_from_server() {
22 $this->php
->setReturnValue('getRequestURI', '/index.html');
23 $this->php
->setReturnValue('getPHPSelf', '/xhtml-compiler/main.php');
24 $this->assertEqual(get_page_from_server(), 'index.html');
27 function test_get_page_from_server_InSubdir() {
28 $this->php
->setReturnValue('getRequestURI', '/subdir/foobar.html');
29 $this->php
->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
30 $this->assertEqual(get_page_from_server(), 'foobar.html');
33 function test_get_page_from_server_InSubdirDifferentAppDir() {
34 $this->php
->setReturnValue('getRequestURI', '/subdir/foobar.html');
35 $this->php
->setReturnValue('getPHPSelf', '/subdir/xc/main.php');
36 $this->assertEqual(get_page_from_server(), 'foobar.html');
39 function test_get_page_from_server_InSubdirPageInDirectory() {
40 $this->php
->setReturnValue('getRequestURI', '/subdir/foo/foobar.html');
41 $this->php
->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
42 $this->assertEqual(get_page_from_server(), 'foo/foobar.html');
45 function test_normalize_index_Blank() {
46 $this->assertEqual(normalize_index('', 'index.html'), 'index.html');
49 function test_normalize_index_File() {
50 $this->php
->expectOnce('isDir', array('main.html'));
51 $this->php
->setReturnValue('isDir', false);
52 $this->assertEqual(normalize_index('main.html', 'index.html'), 'main.html');
55 function test_normalize_index_LooksLikeFileButIsDir() {
56 $this->php
->expectOnce('isDir', array('main.html'));
57 $this->php
->setReturnValue('isDir', true);
58 $this->assertEqual(normalize_index('main.html', 'index.html'), 'main.html/index.html');
61 function test_normalize_index_SubDir() {
62 $this->php
->expectOnce('isDir', array('foo/'));
63 $this->php
->setReturnValue('isDir', true);
64 $this->assertEqual(normalize_index('foo/', 'index.html'), 'foo/index.html');
67 function test_normalize_index_SubDirMissingSlash() {
68 $this->php
->expectOnce('isDir', array('foo'));
69 $this->php
->setReturnValue('isDir', true);
70 $this->assertEqual(normalize_index('foo', 'index.html'), 'foo/index.html');
73 function test_normalize_index_FileWithoutExtension() {
74 $this->php
->expectOnce('isDir', array('foo'));
75 $this->php
->setReturnValue('isDir', false);
76 $this->assertEqual(normalize_index('foo', 'index.html'), 'foo');