Location: PHPKode > projects > Moc10 PHP Library > tests/Moc10/FormTest.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_Form
 * @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_FormTest extends PHPUnit_Framework_TestCase
{

    public function testFormConstructor()
    {
        $f = new Moc10_Form('action.php', 'post');
        $class = 'Moc10_Form';
        $this->assertTrue($f instanceof $class);
    }

    public function testFormSetTemplate()
    {
        $f = new Moc10_Form('action.php', 'post');
        $tmpl = "<table><tr><td>FORM TEMPLATE</td></tr><table>";
        $f->setTemplate($tmpl);
        $this->assertEquals($tmpl, $f->getTemplate());
    }

    public function testFormSetAttributes()
    {
        $f = new Moc10_Form('action.php', 'post');
        $f->setAttributes('id', 'loginForm');
        $attributes = $f->getAttributes();
        $this->assertTrue(array_key_exists('id', $attributes));
        $this->assertTrue(in_array('loginForm', $attributes));
    }

    public function testFormSetElements()
    {
        $f = new Moc10_Form('action.php', 'post');
        $name = new Moc10_Form_Element('text', 'name', '');
        $f->addElements($name);
        $elements = $f->getElements();
        $class = 'Moc10_Form_Element';
        $this->assertTrue($elements[0] instanceof $class);
    }

    public function testFormElementConstructor()
    {
        $f = new Moc10_Form_Element('text', 'email', '');
        $class = 'Moc10_Form_Element';
        $this->assertTrue($f instanceof $class);
    }

    public function testFormElementSetAttributes()
    {
        $f = new Moc10_Form_Element('text', 'email', '');
        $attribute = 'class';
        $value = 'red';
        $f->setAttributes($attribute, $value);
        $attributes = $f->getAttributes();
        $this->assertTrue(array_key_exists($attribute, $attributes));
        $this->assertTrue(in_array($value, $attributes));
    }

    public function testFormElementSetLabel()
    {
        $f = new Moc10_Form_Element('text', 'email', '');
        $label = 'email';
        $f->setLabel($label);
        $this->assertEquals($label, $f->label);
    }

    public function testFormElementSetRequired()
    {
        $f = new Moc10_Form_Element('text', 'email', '');
        $f->setRequired(true);
        $this->assertTrue($f->required);
    }

    public function testFormElementAddValidator()
    {
        $f = new Moc10_Form_Element('text', 'email', '');
        $validator = 'Alpha';
        $f->addValidator($validator);
        $this->assertTrue(array_key_exists('type', $f->validators[0]));
        $this->assertTrue(in_array('Alpha', $f->validators[0]));
    }

}

?>
Return current item: Moc10 PHP Library