* @license PHP License * @package WB * @subpackage unittest */ /** * Unit Test * * * * @version 0.1.1 * @package WB * @subpackage unittest */ class TestCasePatFormsElementXinha extends UnitTestCase { /** * keep error reporting level */ protected $oldErrorReportingLevel; protected $formDef = array( 'article' => array( 'type' => 'Xinha', 'attributes' => array( 'maxlength' => 1000 ) ) ); /** * set up error reporting level */ public function __construct() { $this->req = WBClass::create('WBRequest'); $this->oldErrorReportingLevel = error_reporting(E_ALL); } /** * reset error reporting level */ public function __destruct() { $this->req->import(array('save' => null)); error_reporting($this->oldErrorReportingLevel); } /** * load class and start */ public function xtestInit() { $form = $this->mkForm(); $el = $form->getElementByName('article'); /** @var $el patForms_Element */ $this->assertIsA($el, 'patForms_Element'); $this->assertIsA($el, 'patForms_Element_Xinha'); $this->assertFalse($el->validate('anything'), 'Element should not be valid'); $errors = $el->getValidationErrors(); $this->assertEqual(count($errors), 1, 'There should be 1 error'); } public function testSetGet() { $form = $this->mkForm(); $set = array(); $set['article'] = '

Simple Article

'; $set['article'] = '

Simple Article with Link in it

'; $form->setValues($set); $get = $form->getValues(); } public function xtestFilter() { $filter = patForms::createFilter('XmlXinha'); $dir = dirname(__FILE__) . '/xinha'; $di = new DirectoryIterator($dir); // build filename with path $realpath = $dir . '/%s.%s'; foreach ($di as $file) { if ($file->isDot() || $file->isDir()) { continue; } list($name, $ext) = explode('.', $file->getFilename(), 2); if ($ext != 'xml') { continue; } $xml = file_get_contents(sprintf($realpath, $name, 'xml')); $xml = trim($xml); $in = $filter->in($xml); $in = trim($in); $in = WBString::replaceSuperPlaceholders($in); $xinha = @file_get_contents(sprintf($realpath, $name, 'xinha')); $xinha = trim($xinha); if (empty($xinha)) { echo "Missing: $name.xinha\n"; echo "
" . htmlspecialchars($in) . '

' . "\n"; continue; } $xinha = WBString::replaceSuperPlaceholders($xinha); $this->assertEqual($in, $xinha); $out = $filter->out($xinha); $out = trim($out); $this->assertEqual($out, $xml); } } /** * create form object * * create and configure form with elements * * @return patForms */ protected function mkForm() { $params = array(); $params['elements'] = $this->formDef; $form = WBClass::create('patForms', $params); $this->assertIsA($form, 'patForms'); return $form; } } ?>