DBUIHelpers_DOMTest.php 4.92 KB
<?php
require_once 'basepath.inc.php';

require_once $__BASEPATH_EX.'include/config.php';

/**
 * Language
 */

require_once $__BASEPATH_EX.'include/Forest/mensch.coop/php/class_Language.mensch.coop.inc.php';
require_once $__BASEPATH_EX.'include/System/php/class_Language.inc.php';
require_once $__BASEPATH_EX.'include/System/php/class_CONSTKindOf.inc.php';

/**
 * Converter
 */
require_once $__BASEPATH_EX . 'include/Lib/Tools/mcClasses/mcPUIX/class_Converter.inc.php';

require_once $__BASEPATH_EX.'include/Lib/Tools/mcClasses/mcPUIX/class_mcPUIX_DOM.inc.php';

$_PHPUNIT_mcPUIX_DOMTest_XSD =  $__BASEPATH_EX . 'include/Lib/Tools/mcClasses/mcPUIX/Element.xsd';
$_PHPUNIT_mcPUIX_DOMTest_XSL =  $__BASEPATH_EX . 'include/Lib/Tools/mcClasses/mcPUIX/mcPUIX.xsl';

/**
 * Test class for mcPUIX_DOM.
 * Generated by PHPUnit on 2010-07-13 at 14:12:14.
 */
class mcPUIX_DOMTest extends PHPUnit_Framework_TestCase {

	protected $stylesheet;
	protected $processor;

	protected function setUp() {
		global $_PHPUNIT_mcPUIX_DOMTest_XSL;
		$this->stylesheet = new DOMDocument;
		$this->stylesheet->load($_PHPUNIT_mcPUIX_DOMTest_XSL);
		$this->processor = new XSLTProcessor;
		$this->processor->importStylesheet($this->stylesheet);

	}

	protected function tearDown() {

	}

	private function checkXML(DOMDocument $param_DOMDocument) {
		$DOMHtml = new DOMDocument;
		$this->assertTrue($DOMHtml->loadHTML($this->processor->transformToDoc($param_DOMDocument)->saveXML()), 'validate DOMElement with xsd');
		return  $DOMHtml;
	}

	private function checkXMLString(DOMDocument $param_DOMDocument, array $param_SearchStringArray, $param_SearchStringDirection=false) {

		$this->checkXML($param_DOMDocument);

		$HTMLString = $this->processor->transformToDoc($param_DOMDocument)->saveXML();
		foreach($param_SearchStringArray as $TagName) {
			$this->assertTrue(substr_count($HTMLString, $TagName)>0, 'found string('.$TagName.')');
//                        $this->assertTrue(substr_count($HTMLString, $TagName.'l')>0, 'found string('.$TagName.')');
			if($param_SearchStringDirection) {
				$HTMLString = strstr($HTMLString, $TagName);
			}
		}
		return $HTMLString;
	}

	private function checkGetDOMElement_Element(array $param_OptionalAttributes=array(), array $param_SearchStringArray=array()) {
		global $_LOSP_CHARSET;
		global $_PHPUNIT_mcPUIX_DOMTest_XSD;
		$DOMDocument = new DOMDocument('1.0', $_LOSP_CHARSET);
		$DOMDocument->appendChild(mcPUIX_DOM::getDOMElement_Element($DOMDocument, 'objvar', $param_OptionalAttributes));

		echo "\n".$DOMDocument->saveXML()."\n";

		$this->assertTrue($DOMDocument->schemaValidate($_PHPUNIT_mcPUIX_DOMTest_XSD), 'validate DOMElement with xsd');
		$this->checkXMLString($DOMDocument, $param_SearchStringArray, true);		
	}

	private function checkGetDOMElement_DBUIArray(array $param_Array, array $param_SearchStringArray=array()) {
		global $_LOSP_CHARSET;
		global $_PHPUNIT_mcPUIX_DOMTest_XSD;

		$DOMDocument = new DOMDocument('1.0', $_LOSP_CHARSET);
		$DOMDocument->appendChild(mcPUIX_DOM::getDOMElement_DBUIArray($DOMDocument, $param_Array));

		$this->assertTrue($DOMDocument->schemaValidate($_PHPUNIT_mcPUIX_DOMTest_XSD), 'validate DOMElement with xsd');

		
	}

	public function testGetDOMElement_Element() {

		/**
		 * test default
		 */
//		$this->checkGetDOMElement_Element();

		/**
		 * test as text
		 */
		$var_OptionalAttributes = array(
			'type' => 'text',
			'show' => true,
			'edit' => true
		);
		$this->checkGetDOMElement_Element($var_OptionalAttributes, array('textarea'));

		/**
		 * teset as select
		 */
		$var_OptionalAttributes = array(
			'type' => 'select',
			'show' => true,
			'edit' => true,
			'value' => '1',
			'values' => array('1' => 'eins', '2' => 'zwei')
		);
//		$this->checkGetDOMElement_Element($var_OptionalAttributes, array('select', 'option'));

	}

	public function testGetDOMElement_DBUIArray() {
		$array = array(
				array(
					'INT'	=> array('type'=> 'int', 'show'=> true, 'value' => 1),
					'KEY'	=> array('show'=> true, 'value' => 'key'),
					'TEXT'	=> array('type'=> 'text', 'show'=> true, 'value' => 1, 'edit' => true),
					'SELECT'=> array('type'=> 'select', 'show'=> true, 'value' => '', 'values' =>  array('select1', 'select2'), 'edit' => true),
				),
				array(
					'ID'	=> array('type'=> 'int', 'show'=> true, 'value' => 1),
					'Key'	=> array('show'=> true, 'value' => 'key'),
					'value'	=> array('type'=> 'text', 'show'=> true, 'value' => 1),
					'select'=> array('type'=> 'select', 'show'=> true, 'values' => array('select1', 'select2')),
				),
				array(
					'ID'	=> array('type'=>'int', 'show'=> true, 'value' => 1),
					'Key'	=> array('show'=>true,	'value'=>'key'),
					'value'	=> array('type'=>'text', 'show'=>true, 'value'=>1, 'edit'=>true, 'fixed'=>true),
					'select'=> array('type'=>'select', 'show'=> true, 'values' => array('select1', 'select2'), 'value' => 1),
				)
		);
//		$this->checkGetDOMElement_DBUIArray($array, array('<option value="1" selected="selected">', '</textarea>', '</select>', '</option>'));
	}

}

?>