Best Phoronix-test-suite code snippet using pts_validation.xsd_to_rebuilt_xml
pts_validation.php
Source:pts_validation.php
...123 }124 // Rewrite the main XML file to ensure it is properly formatted, elements are ordered according to the schema, etc...125 $writer = new nye_XmlWriter();126 $types = pts_validation::process_xsd_types();127 $ret = pts_validation::xsd_to_rebuilt_xml(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/test-profile.xsd', $types, $test_profile, $writer);128 $writer->saveXMLFile($test_profile->get_file_location());129 // Now re-create the pts_test_profile object around the rewritten XML130 $test_profile = new pts_test_profile($test_profile->get_identifier());131 $valid = $test_profile->validate();132 if($valid == false)133 {134 echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;135 pts_validation::process_libxml_errors();136 return false;137 }138 else139 {140 echo PHP_EOL . 'Test Profile XML Is Valid.' . PHP_EOL;141 }142 // Validate the downloads file143 $download_xml_file = $test_profile->get_file_download_spec();144 if(empty($download_xml_file) == false)145 {146 $writer = new nye_XmlWriter();147 $types = pts_validation::process_xsd_types();148 $ret = pts_validation::xsd_to_rebuilt_xml(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/test-profile-downloads.xsd', $types, $test_profile, $writer);149 $writer->saveXMLFile($download_xml_file);150 $dom = new DOMDocument();151 $dom->load($download_xml_file);152 $valid = $dom->schemaValidate(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/test-profile-downloads.xsd');153 if($valid == false)154 {155 echo PHP_EOL . 'Errors occurred parsing the downloads XML.' . PHP_EOL;156 pts_validation::process_libxml_errors();157 return false;158 }159 else160 {161 echo PHP_EOL . 'Test Downloads XML Is Valid.' . PHP_EOL;162 }163 // Validate the individual download files164 echo PHP_EOL . 'Testing File Download URLs.' . PHP_EOL;165 $files_missing = 0;166 $file_count = 0;167 foreach($test_profile->get_downloads() as $download)168 {169 foreach($download->get_download_url_array() as $url)170 {171 $stream_context = pts_network::stream_context_create();172 stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback'));173 $file_pointer = fopen($url, 'r', false, $stream_context);174 if($file_pointer == false)175 {176 echo 'File Missing: ' . $download->get_filename() . ' / ' . $url . PHP_EOL;177 $files_missing++;178 }179 else180 {181 fclose($file_pointer);182 }183 $file_count++;184 }185 }186 if($files_missing > 0) // && $file_count == $files_missing187 {188 return false;189 }190 }191 // Validate the parser file192 $parser_file = $test_profile->get_file_parser_spec();193 if(empty($parser_file) == false)194 {195 $writer = new nye_XmlWriter();196 $types = pts_validation::process_xsd_types();197 $tp_def = $test_profile->get_results_definition();198 $ret = pts_validation::xsd_to_rebuilt_xml(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/results-parser.xsd', $types, $tp_def, $writer);199 $writer->saveXMLFile($parser_file);200 $dom = new DOMDocument();201 $dom->load($parser_file);202 $valid = $dom->schemaValidate(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/results-parser.xsd');203 if($valid == false)204 {205 echo PHP_EOL . 'Errors occurred parsing the results parser XML.' . PHP_EOL;206 pts_validation::process_libxml_errors();207 return false;208 }209 else210 {211 echo PHP_EOL . 'Test Results Parser XML Is Valid.' . PHP_EOL;212 }213 }214 if(is_file($test_profile->get_resource_dir() . 'changelog.json'))215 {216 pts_file_io::unlink($test_profile->get_resource_dir() . 'changelog.json');217 }218 if(is_file($test_profile->get_resource_dir() . 'generated.json'))219 {220 pts_file_io::unlink($test_profile->get_resource_dir() . 'generated.json');221 }222 // Make sure no extra files are in there223 $allowed_files = pts_validation::test_profile_permitted_files();224 foreach(pts_file_io::glob($test_profile->get_resource_dir() . '*') as $tp_file)225 {226 if(!is_file($tp_file) || !in_array(basename($tp_file), $allowed_files))227 {228 echo PHP_EOL . basename($tp_file) . ' is not allowed in the test package.' . PHP_EOL;229 return false;230 }231 }232 return true;233 }234 public static function process_xsd_types()235 {236 $doc = new DOMDocument();237 $xsd_file = pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/types.xsd';238 if(is_file($xsd_file))239 {240 $doc->loadXML(file_get_contents($xsd_file));241 }242 $xpath = new DOMXPath($doc);243 $xpath->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema');244 $types = array();245 foreach($xpath->evaluate('/xs:schema/xs:simpleType') as $e)246 {247 $name = $e->getAttribute('name');248 $type = $e->getElementsByTagName('restriction')->item(0)->getAttribute('base');249 switch($type)250 {251 case 'xs:integer':252 $type = 'INT';253 break;254 case 'xs:string':255 $type = 'STRING';256 break;257 }258 if($e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('minLength')->length > 0)259 {260 $min_length = $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('minLength')->item(0)->getAttribute('value');261 }262 else263 {264 $min_length = -1;265 }266 if($e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('maxLength')->length > 0)267 {268 $max_length = $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('maxLength')->item(0)->getAttribute('value');269 }270 else271 {272 $max_length = -1;273 }274 if($e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('minInclusive')->length > 0)275 {276 $min_value = $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('minInclusive')->item(0)->getAttribute('value');277 }278 else279 {280 $min_value = -1;281 }282 if($e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('maxInclusive')->length > 0)283 {284 $max_value = $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('maxInclusive')->item(0)->getAttribute('value');285 }286 else287 {288 $max_value = -1;289 }290 $enums = array();291 for($i = 0; $i < $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('enumeration')->length; $i++)292 {293 $enums[] = $e->getElementsByTagName('restriction')->item(0)->getElementsByTagName('enumeration')->item($i)->getAttribute('value');294 }295 $types[$name] = new pts_input_type_restrictions($name, $type, $min_length, $max_length, $min_value, $max_value, $enums);296 }297 return $types;298 }299 public static function xsd_to_cli_creator($xsd_file, &$new_object, $types = null)300 {301 $nodes = self::generate_xsd_element_objects($xsd_file, null, $types);302 self::xsd_nodes_to_cli_prompts($nodes, $new_object);303 }304 public static function xsd_nodes_to_cli_prompts($nodes, &$new_object)305 {306 foreach($nodes as $node)307 {308 $path = $node->get_path();309 if($node->get_documentation() == null)310 {311 continue;312 }313 if(in_array('UNCOMMON', $node->get_flags_array()))314 {315 continue;316 }317 echo pts_client::cli_just_bold($node->get_name());318 /*319 if($node->get_value() != null)320 {321 echo ': ' . pts_client::cli_colored_text($node->get_value(), 'cyan');322 }323 */324 echo PHP_EOL;325 $enums = array();326 $min_value = -1;327 $max_value = -1;328 $type_restrict = null;329 if($node->get_input_type_restrictions() != null)330 {331 $type = $node->get_input_type_restrictions();332 $type_restrict = $type->get_type();333 // echo 'xx' . $type->get_name() . ' ' . $type->get_type() . 'xx' . PHP_EOL;334 $enums = $type->get_enums();335 if(!empty($enums))336 {337 echo pts_client::cli_colored_text('Possible Values: ', 'gray', true) . implode(', ', $enums) . PHP_EOL;338 echo pts_client::cli_colored_text('Multiple Selections Allowed: ', 'gray', true) . ($type->multi_enum_select() ? 'YES' : 'NO') . PHP_EOL;339 }340 $min_value = $type->get_min_value();341 if($min_value > -1)342 {343 echo pts_client::cli_colored_text('Minimum Value: ', 'gray', true) . $min_value . PHP_EOL;344 }345 $max_value = $type->get_max_value();346 if($max_value > 0)347 {348 echo pts_client::cli_colored_text('Maximum Value: ', 'gray', true) . $max_value . PHP_EOL;349 }350 }351 /*if($node->get_api() != null)352 {353 echo pts_client::cli_colored_text('API: ', 'gray', true) . $node->get_api()[0] . '->' . $node->get_api()[1] . '()' . PHP_EOL;354 }*/355 if($node->get_documentation() != null)356 {357 echo $node->get_documentation() . PHP_EOL;358 }359 if($node->get_default_value() != null)360 {361 echo pts_client::cli_colored_text('Default Value: ', 'gray', true) . $node->get_default_value() . PHP_EOL;362 }363 $do_require = in_array('TEST_REQUIRES', $node->get_flags_array());364 if(!empty($enums))365 {366 $input = pts_user_io::prompt_text_menu('Select from the supported options', $enums, $type->multi_enum_select(), false, null);367 if(is_array($input))368 {369 $input = implode(',', $input);370 }371 }372 else373 {374 do375 {376 $input_passes = true;377 $input = pts_user_io::prompt_user_input($path, !($do_require && $node->get_default_value() == null), false);378 if($do_require && $min_value > 0 && strlen($input) < $min_value)379 {380 echo 'Minimum length of ' . $min_value . ' is required.';381 $input_passes = false;382 }383 if($do_require && $max_value > 0 && strlen($input) > $max_value)384 {385 echo 'Maximum length of ' . $max_value . ' is supported.';386 $input_passes = false;387 }388 if(!empty($input) && $type_restrict == 'INT' && !is_numeric($input))389 {390 echo 'Input must be a valid integer number.';391 $input_passes = false;392 }393 if(!empty($input) && $type_restrict == 'xs:decimal' && !is_numeric($input))394 {395 echo 'Input must be a valid number.';396 $input_passes = false;397 }398 }399 while(!$input_passes);400 if(empty($input) && $node->get_default_value() != null)401 {402 $input = $node->get_default_value();403 }404 }405 $new_object->addXmlNodeWNE($path, trim($input));406 echo PHP_EOL;407 }408 }409 public static function xsd_to_html_creator($xsd_file, $types = null)410 {411 $nodes = self::generate_xsd_element_objects($xsd_file, null, $types);412 return self::xsd_nodes_to_html_prompts($nodes);413 }414 public static function xsd_nodes_to_html_prompts($nodes)415 {416 $html = null;417 foreach($nodes as $node)418 {419 $path = $node->get_path();420 if($node->get_documentation() == null)421 {422 continue;423 }424 $uncommon = in_array('UNCOMMON', $node->get_flags_array());425 $html .= '<div style="" class="' . ($uncommon ? 'pts_phoromatic_create_test_option_area_uncommon' : 'pts_phoromatic_create_test_option_area') . '" id="' . str_replace('/', '', $path) . '">';426 $html .= '<h3>' . $node->get_name() . ($uncommon ? ' <sup> Uncommon Option; Hover To Expand</sup>' : '') . '</h3>' . PHP_EOL;427 $enums = array();428 $min_value = -1;429 $max_value = -1;430 $type_restrict = null;431 if($node->get_input_type_restrictions() != null)432 {433 $html .= '<p>';434 $type = $node->get_input_type_restrictions();435 $type_restrict = $type->get_type();436 $enums = $type->get_enums();437 $min_value = $type->get_min_value();438 if($min_value > 0)439 {440 $html .= '<strong>Minimum Value: </strong>' . $min_value;441 }442 $max_value = $type->get_max_value();443 if($max_value > 0)444 {445 $html .= '<strong>Maximum Value: </strong>' . $max_value;446 }447 $html .= '</p>';448 }449 if($node->get_documentation() != null)450 {451 $html .= '<p>' . str_replace($node->get_name(), '<em>' . $node->get_name() . '</em>', $node->get_documentation()) . '</p>';452 }453 $do_require = in_array('TEST_REQUIRES', $node->get_flags_array());454 $html .= '<p>';455 if(!empty($enums))456 {457 $html .= '<select name="' . $path . '" ' . ($type->multi_enum_select() ? ' multiple' : '') . ($do_require ? ' required' : '') . '>' . PHP_EOL;458 foreach($enums as $enum)459 {460 $html .= '<option value="' . $enum . '"' . ($node->get_default_value() == $enum ? 'selected="selected"' : null) . '>' . $enum . '</option>';461 }462 $html .= '</select>';463 }464 else465 {466 if($type_restrict == 'INT' || $type_restrict == 'xs:decimal')467 {468 $html .= '<input type="number" name="' . $path . '" value="' . $node->get_default_value() . '" min="1" ' . ($do_require ? ' required' : '') . ' />';469 }470 else471 {472 $html .= '<input type="text" name="' . $path . '" value="' . $node->get_default_value() . '" ' . ($do_require ? ' required' : '') . ' />';473 }474 }475 $html .= '</p>';476 $html .= '</div>';477 }478 return $html;479 }480 public static function xsd_to_var_array_generate_xml($xsd_file, $types, &$array_to_check, &$writer)481 {482 foreach(self::generate_xsd_element_objects($xsd_file, null, $types) as $node)483 {484 $do_require = in_array('TEST_REQUIRES', $node->get_flags_array());485 $path = $node->get_path();486 $value = isset($array_to_check[$path]) ? $array_to_check[$path] : null;487 if(empty($value))488 {489 $value = $node->get_default_value();490 }491 if(empty($value))492 {493 continue;494 }495 if($do_require && empty($value))496 {497 //return 'The ' . $path . ' value cannot be empty.';498 }499 $writer->addXmlNodeWNE($path, $value);500 }501 return true;502 }503 public static function xsd_to_rebuilt_xml($xsd_file, $types, &$test_profile, &$writer)504 {505 $test_profile->no_fallbacks_on_null = true;506 foreach(self::generate_xsd_element_objects($xsd_file, $test_profile, $types) as $node)507 {508 $do_require = in_array('TEST_REQUIRES', $node->get_flags_array());509 $value = $node->get_value();510 $path = $node->get_path();511 if($value == $node->get_default_value() && in_array('UNCOMMON', $node->get_flags_array()))512 {513 continue;514 }515 //if(empty($value))516 //{517 // $value = $node->get_default_value();...
phoromatic_create_test.php
Source:phoromatic_create_test.php
...102 INTO:103 104 $tp's get_downloads() with new pts_test_file_download entries105 */106 $ret = pts_validation::xsd_to_rebuilt_xml(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/test-profile-downloads.xsd', $types, $tp, $tdw);107 $tdw->saveXMLFile(PTS_TEST_PROFILE_PATH . $tp->get_identifier(false) . '-' . $tp->get_test_profile_version() . '/downloads.xml');108 }109 }110 }111 if(isset($PATH[1]) && strpos($PATH[1], '&delete') !== false)112 {113 $identifier_item = isset($PATH[1]) ? $PATH[0] . '/' . str_replace('&delete', '', $PATH[1]) : false;114 if($identifier_item && pts_test_profile::is_test_profile($identifier_item))115 {116 $tp = new pts_test_profile($identifier_item);117 if($tp->get_identifier() != null)118 {119 pts_file_io::delete($tp->get_resource_dir(), null, true);120 header('Location: /?tests');...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with xsd_to_rebuilt_xml on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!