1<?php 2/** 3 * PHPTAL templating engine 4 * 5 * PHP Version 5 6 * 7 * @category HTML 8 * @package PHPTAL 9 * @author Laurent Bedubourg <lbedubourg@motion-twin.com> 10 * @author Kornel Lesiński <kornel@aardvarkmedia.co.uk> 11 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License 12 * @version SVN: $Id$ 13 * @link http://phptal.org/ 14 */ 15 16 17class ReadableErrorTest extends PHPTAL_TestCase 18{ 19 function testSimple() 20 { 21 $this->assertThrowsInLine(2, 'input/error-01.html'); 22 } 23 24 function testMacro() 25 { 26 $this->assertThrowsInLine(2, 'input/error-02.html', 'input/error-02.macro.html'); 27 } 28 29 function testAfterMacro() 30 { 31 $this->assertThrowsInLine(3, 'input/error-03.html'); 32 } 33 34 function testParseError() 35 { 36 $this->assertThrowsInLine(7, 'input/error-04.html'); 37 } 38 39 function testMissingVar() 40 { 41 $this->assertThrowsInLine(5, 'input/error-05.html'); 42 } 43 44 function testMissingVarInterpol() 45 { 46 $this->markTestSkipped("can't fix it now"); 47 $this->assertThrowsInLine(5, 'input/error-06.html'); 48 } 49 50 function testMissingExpr() 51 { 52 $this->assertThrowsInLine(6, 'input/error-07.html'); 53 } 54 55 function testPHPSyntax() 56 { 57 $this->assertThrowsInLine(9, 'input/error-08.html'); 58 } 59 60 function testTranslate() 61 { 62 $this->assertThrowsInLine(8, 'input/error-09.html'); 63 } 64 65 function testMacroName() 66 { 67 $this->assertThrowsInLine(4, 'input/error-10.html'); 68 } 69 70 function testTALESParse() 71 { 72 $this->assertThrowsInLine(2, 'input/error-11.html'); 73 } 74 75 function testMacroNotExists() 76 { 77 $this->assertThrowsInLine(3, 'input/error-12.html'); 78 } 79 80 function testLocalMacroNotExists() 81 { 82 $this->assertThrowsInLine(5, 'input/error-13.html'); 83 } 84 85 function assertThrowsInLine($line, $file, $expected_file = NULL) 86 { 87 try { 88 $tpl = $this->newPHPTAL($file); 89 $tpl->a_number = 1; 90 $res = $tpl->execute(); 91 $this->fail("Not thrown"); 92 } 93 catch (PHPTAL_TemplateException $e) { 94 $msg = $e->getMessage(); 95 $this->assertInternalType('string',$e->srcFile, $msg); 96 $this->assertContains($expected_file ? $expected_file : $file, $e->srcFile, $msg); 97 $this->assertEquals($line, $e->srcLine, "Wrong line number: ". $msg . "\n". $tpl->getCodePath()); 98 } 99 } 100} 101 102