- Add test folder
[xhtml-compiler.git] / tests / functions-test.php
blob11a9e0819e7fc9300c4db640b61b3aaa3be760aa
1 <?php
3 class XHTMLCompiler_FunctionsTest extends UnitTestCase
6 protected $mock;
8 function setUp() {
9 $this->mock = new XHTMLCompilerMock();
10 XHTMLCompiler::setInstance($this->mock);
13 function tearDown() {
14 $this->mock->tally();
17 function test_set_response_code() {
18 $this->mock->expectAt(0, 'header', array($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404));
19 $this->mock->expectAt(1, 'header', array('Status: 404 Not Found'));
20 set_response_code(404);
23 function test_display_error_and_quit() {
24 $this->mock->expectCallCount('quit', 3);
25 $this->mock->expect('paint', array(new PatternExpectation('/404 Not Found/')));
26 display_error_and_quit(404);
27 $this->mock->expect('paint', array(new PatternExpectation('/WTF/')));
28 display_error_and_quit(404, 'WTF');
29 $this->mock->expect('paint', array(new PatternExpectation('/404 Not Found.+?Could not find the file/')));
30 display_error_and_quit(404, false, 'Could not find the file');
33 function test_get_page_from_server() {
34 $this->mock->setReturnValue('getRequestURI', '/index.html');
35 $this->mock->setReturnValue('getPHPSelf', '/xhtml-compiler/main.php');
36 $this->assertEqual(get_page_from_server(), 'index.html');
39 function testInSubdir_get_page_from_server() {
40 $this->mock->setReturnValue('getRequestURI', '/subdir/foobar.html');
41 $this->mock->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
42 $this->assertEqual(get_page_from_server(), 'foobar.html');
45 function testInSubdirDifferentAppDir_get_page_from_server() {
46 $this->mock->setReturnValue('getRequestURI', '/subdir/foobar.html');
47 $this->mock->setReturnValue('getPHPSelf', '/subdir/xc/main.php');
48 $this->assertEqual(get_page_from_server(), 'foobar.html');
51 function testInSubdirPageInDirectory_get_page_from_server() {
52 $this->mock->setReturnValue('getRequestURI', '/subdir/foo/foobar.html');
53 $this->mock->setReturnValue('getPHPSelf', '/subdir/xhtml-compiler/main.php');
54 $this->assertEqual(get_page_from_server(), 'foo/foobar.html');