Location: PHPKode > projects > Moc10 PHP Library > tests/Moc10/DomTest.php
<?php
/**
 * Moc10 Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.TXT.
 * It is also available through the world-wide-web at this URL:
 * http://www.moc10phplibrary.com/LICENSE.TXT
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to hide@address.com so we can send you a copy immediately.
 *
 * @category   Moc10
 * @package    Moc10_Dom
 * @author     Nick Sagona, III <hide@address.com>
 * @copyright  Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
 * @license    http://www.moc10phplibrary.com/LICENSE.TXT     New BSD License
 */

require_once dirname(__FILE__) . '/../../library/Moc10/Autoloader.php';
Moc10_Autoloader::bootstrap();

class Moc10_DomTest extends PHPUnit_Framework_TestCase
{

    public function testDomConstructor()
    {
        $d = new Moc10_Dom('XHTML11', 'utf-8');
        $class = 'Moc10_Dom';
        $this->assertTrue($d instanceof $class);
        $this->assertEquals('XHTML11', $d->getType());
        $this->assertEquals('utf-8', $d->getCharset());
    }

    public function testDomChildConstructor()
    {
        $c = new Moc10_Dom_Child('div', 'This is a div.');
        $class = 'Moc10_Dom_Child';
        $this->assertTrue($c instanceof $class);
        $this->assertEquals('div', $c->getName());
        $this->assertEquals('This is a div.', $c->getValue());
    }

    public function testDomAddChildren()
    {
        $c = new Moc10_Dom_Child('div');
        $d = new Moc10_Dom('XHTML11', 'utf-8');
        $d->addChildren($c);
        $this->assertEquals(1, count($d->getChildren()));
    }

    public function testDomChildAddChildren()
    {
        $c1 = new Moc10_Dom_Child('div');
        $c2 = new Moc10_Dom_Child('h1', 'This is a header.');
        $c3 = new Moc10_Dom_Child('p', 'This is a paragraph.');
        $c1->addChildren(array($c2, $c3));
        $this->assertEquals(2, count($c1->getChildren()));
    }

    public function testDomRender()
    {
        $c = new Moc10_Dom_Child('div', 'Hello World!');
        $d = new Moc10_Dom();
        $d->addChildren($c);
        $this->assertEquals("<div>Hello World!</div>\n", $d->render(true));
    }

}

?>
Return current item: Moc10 PHP Library