* @author Kornel Lesiński * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: ParserTest.php 888 2010-06-08 09:48:33Z kornel $ * @link http://phptal.org/ */ class ParserTest extends PHPTAL_TestCase { public function testParseSimpleDocument() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); $tree = $parser->parseFile(new PHPTAL_Dom_PHPTALDocumentBuilder(), 'input/parser.01.xml')->getResult(); if ($tree instanceof DOMNode) $this->markTestSkipped(); $children = $tree->childNodes; $this->assertEquals(3, count($children)); $this->assertEquals(5, count($children[2]->childNodes)); } public function testByteOrderMark() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); try { $tree = $parser->parseFile(new PHPTAL_Dom_PHPTALDocumentBuilder(), 'input/parser.02.xml')->getResult(); $this->assertTrue(true); } catch (Exception $e) { $this->assertTrue(false); } } public function testBadAttribute() { try { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); $parser->parseFile(new PHPTAL_Dom_PHPTALDocumentBuilder(), 'input/parser.03.xml')->getResult(); } catch (Exception $e) { $this->assertContains( 'href', $e->getMessage() ); $this->assertContains( 'quote', $e->getMessage() ); } } public function testLegalElementNames() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), ' ')->getResult(); } public function testXMLNS() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), ' ')->getResult(); } public function testIllegalElementNames1() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); try { $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), ' <1element />')->getResult(); $this->fail("Accepted invalid element name starting with a number"); } catch(PHPTAL_Exception $e) {} } public function testIllegalElementNames2() { $parser = new PHPTAL_Dom_SaxXmlParser('UTF-8'); try { $parser->parseString(new PHPTAL_Dom_PHPTALDocumentBuilder(), ''); $this->fail("Accepted invalid element name")->getResult(); } catch(PHPTAL_Exception $e) {} } }