Various improvements.
[xhtml-compiler.git] / tests / XHTMLCompiler / FunctionsTest.php
blobd3516d2fbb30932ca64c73943857ad4a6cc4437a
1 <?php
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->xc->setReturnValue('getConf', XHTMLCOMPILER . '/error.xsl', array('error_xsl'));
14 $this->php->expect('paint', array(new PatternExpectation('/404 Not Found/')));
15 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404));
16 $this->php->expect('paint', array(new PatternExpectation('/WTF/')));
17 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404, 'WTF'));
18 $this->php->expect('paint', array(new PatternExpectation('/Could not find the file/')));
19 xhtmlcompiler_exception_handler(new XHTMLCompiler_Exception(404, false, 'Could not find the file'));
22 function test_get_page_from_server() {
23 $this->php->setReturnValue('getRequestURI', '/index.html');
24 $this->php->setReturnValue('getPHPSelf', '/xhtml-compiler/main.php');
25 $this->assertEqual(get_page_from_server(), 'index.html');
28 function test_get_page_from_server_InSubdir() {
29 $this->php->setReturnValue('getRequestURI', '/subdir/foobar.html');
30 $this->php->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
31 $this->assertEqual(get_page_from_server(), 'foobar.html');
34 function test_get_page_from_server_InSubdirDifferentAppDir() {
35 $this->php->setReturnValue('getRequestURI', '/subdir/foobar.html');
36 $this->php->setReturnValue('getPHPSelf', '/subdir/xc/main.php');
37 $this->assertEqual(get_page_from_server(), 'foobar.html');
40 function test_get_page_from_server_InSubdirPageInDirectory() {
41 $this->php->setReturnValue('getRequestURI', '/subdir/foo/foobar.html');
42 $this->php->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
43 $this->assertEqual(get_page_from_server(), 'foo/foobar.html');
46 function test_normalize_index_Blank() {
47 $this->assertEqual(normalize_index('', 'index.html'), 'index.html');
50 function test_normalize_index_File() {
51 $this->php->expectOnce('isDir', array('main.html'));
52 $this->php->setReturnValue('isDir', false);
53 $this->assertEqual(normalize_index('main.html', 'index.html'), 'main.html');
56 function test_normalize_index_LooksLikeFileButIsDir() {
57 $this->php->expectOnce('isDir', array('main.html'));
58 $this->php->setReturnValue('isDir', true);
59 $this->assertEqual(normalize_index('main.html', 'index.html'), 'main.html/index.html');
62 function test_normalize_index_SubDir() {
63 $this->php->expectOnce('isDir', array('foo/'));
64 $this->php->setReturnValue('isDir', true);
65 $this->assertEqual(normalize_index('foo/', 'index.html'), 'foo/index.html');
68 function test_normalize_index_SubDirMissingSlash() {
69 $this->php->expectOnce('isDir', array('foo'));
70 $this->php->setReturnValue('isDir', true);
71 $this->assertEqual(normalize_index('foo', 'index.html'), 'foo/index.html');
74 function test_normalize_index_FileWithoutExtension() {
75 $this->php->expectOnce('isDir', array('foo'));
76 $this->php->setReturnValue('isDir', false);
77 $this->assertEqual(normalize_index('foo', 'index.html'), 'foo');