diff options
Diffstat (limited to 'ext/dom')
46 files changed, 842 insertions, 61 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c index 276627372b..cca77ff9df 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -1973,14 +1973,15 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type xmlDoc *docp; dom_object *intern; char *source = NULL, *valid_file = NULL; - int source_len = 0; + int source_len = 0, valid_opts = 0; + long flags = 0; xmlSchemaParserCtxtPtr parser; xmlSchemaPtr sptr; xmlSchemaValidCtxtPtr vptr; int is_valid; char resolved_path[MAXPATHLEN + 1]; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op", &id, dom_document_class_entry, &source, &source_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Op|l", &id, dom_document_class_entry, &source, &source_len, &flags) == FAILURE) { return; } @@ -2029,6 +2030,13 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type RETURN_FALSE; } +#if LIBXML_VERSION >= 20614 + if (flags & XML_SCHEMA_VAL_VC_I_CREATE) { + valid_opts |= XML_SCHEMA_VAL_VC_I_CREATE; + } +#endif + + xmlSchemaSetValidOptions(vptr, valid_opts); xmlSchemaSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr); is_valid = xmlSchemaValidateDoc(vptr, docp); xmlSchemaFree(sptr); @@ -2042,14 +2050,14 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type } /* }}} */ -/* {{{ proto boolean dom_document_schema_validate_file(string filename); */ +/* {{{ proto boolean dom_document_schema_validate_file(string filename, int flags); */ PHP_FUNCTION(dom_document_schema_validate_file) { _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE); } /* }}} end dom_document_schema_validate_file */ -/* {{{ proto boolean dom_document_schema_validate(string source); */ +/* {{{ proto boolean dom_document_schema_validate(string source, int flags); */ PHP_FUNCTION(dom_document_schema_validate_xml) { _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING); diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c index f4183d2f9a..6c8cf84e9f 100644 --- a/ext/dom/dom_iterators.c +++ b/ext/dom/dom_iterators.c @@ -157,35 +157,22 @@ static void php_dom_iterator_current_data(zend_object_iterator *iter, zval ***da } /* }}} */ -static int php_dom_iterator_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) /* {{{ */ +static void php_dom_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */ { - zval *curobj; - xmlNodePtr curnode = NULL; - dom_object *intern; - zval *object; - int namelen; - php_dom_iterator *iterator = (php_dom_iterator *)iter; - - object = (zval *)iterator->intern.data; + zval *object = (zval *)iterator->intern.data; if (instanceof_function(Z_OBJCE_P(object), dom_nodelist_class_entry TSRMLS_CC)) { - *int_key = iter->index; - return HASH_KEY_IS_LONG; + ZVAL_LONG(key, iter->index); } else { - curobj = iterator->curobj; + dom_object *intern = (dom_object *)zend_object_store_get_object(iterator->curobj TSRMLS_CC); - intern = (dom_object *)zend_object_store_get_object(curobj TSRMLS_CC); if (intern != NULL && intern->ptr != NULL) { - curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node; + xmlNodePtr curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->ptr)->node; + ZVAL_STRINGL(key, (char *) curnode->name, xmlStrlen(curnode->name), 1); } else { - return HASH_KEY_NON_EXISTANT; + ZVAL_NULL(key); } - - namelen = xmlStrlen(curnode->name); - *str_key = estrndup(curnode->name, namelen); - *str_key_len = namelen + 1; - return HASH_KEY_IS_STRING; } } /* }}} */ diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index bd9c98756b..db8ec83a44 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -176,9 +176,9 @@ dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document) static void dom_copy_doc_props(php_libxml_ref_obj *source_doc, php_libxml_ref_obj *dest_doc) { dom_doc_propsptr source, dest; - + if (source_doc && dest_doc) { - + source = dom_get_doc_props(source_doc); dest = dom_get_doc_props(dest_doc); @@ -224,7 +224,7 @@ zend_class_entry *dom_get_doc_classmap(php_libxml_ref_obj *document, zend_class_ { dom_doc_propsptr doc_props; zend_class_entry **ce = NULL; - + if (document) { doc_props = dom_get_doc_props(document); if (doc_props->classmap) { @@ -296,14 +296,14 @@ static int dom_write_na(dom_object *obj, zval *newval TSRMLS_DC) static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_read_t read_func, dom_write_t write_func TSRMLS_DC) { dom_prop_handler hnd; - + hnd.read_func = read_func ? read_func : dom_read_na; hnd.write_func = write_func ? write_func : dom_write_na; zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(dom_prop_handler), NULL); } /* }}} */ -static zval **dom_get_property_ptr_ptr(zval *object, zval *member, const zend_literal *key TSRMLS_DC) /* {{{ */ +static zval **dom_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */ { dom_object *obj; zval tmp_member; @@ -326,7 +326,7 @@ static zval **dom_get_property_ptr_ptr(zval *object, zval *member, const zend_li } if (ret == FAILURE) { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->get_property_ptr_ptr(object, member, key TSRMLS_CC); + retval = std_hnd->get_property_ptr_ptr(object, member, type, key TSRMLS_CC); } if (member == &tmp_member) { @@ -557,7 +557,7 @@ void *php_dom_export_node(zval *object TSRMLS_DC) /* {{{ */ nodep = intern->node->node; } - return nodep; + return nodep; } /* }}} */ @@ -596,10 +596,10 @@ zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */ zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); obj = &EG(objects_store).object_buckets[handle].bucket.obj; - + if (obj->clone == NULL) { php_error(E_ERROR, "Trying to clone an uncloneable object of class %s", Z_OBJCE_P(zobject)->name); - } + } obj->clone(obj->object, &new_object TSRMLS_CC); @@ -607,7 +607,7 @@ zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */ intern = (dom_object *) new_object; intern->handle = retval.handle; retval.handlers = Z_OBJ_HT_P(zobject); - + old_object = (dom_object *) obj->object; zend_objects_clone_members(&intern->std, retval, &old_object->std, intern->handle TSRMLS_CC); @@ -676,19 +676,19 @@ PHP_MINIT_FUNCTION(dom) zend_declare_property_long(dom_domexception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC); REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry); - + zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", dom_domstringlist_length_read, NULL TSRMLS_CC); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry); - + zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_namelist_prop_handlers, "length", dom_namelist_length_read, NULL TSRMLS_CC); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry); - + zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", dom_domimplementationlist_length_read, NULL TSRMLS_CC); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers), NULL); @@ -697,7 +697,7 @@ PHP_MINIT_FUNCTION(dom) REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry); REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry); - + zend_hash_init(&dom_node_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_node_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC); @@ -732,7 +732,7 @@ PHP_MINIT_FUNCTION(dom) REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry); zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL); - + REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry); zend_hash_init(&dom_document_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_document_prop_handlers, "doctype", dom_document_doctype_read, NULL TSRMLS_CC); @@ -779,7 +779,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry); - + zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", dom_characterdata_data_read, dom_characterdata_data_write TSRMLS_CC); dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", dom_characterdata_length_read, NULL TSRMLS_CC); @@ -787,7 +787,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry); - + zend_hash_init(&dom_attr_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_attr_prop_handlers, "name", dom_attr_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_attr_prop_handlers, "specified", dom_attr_specified_read, NULL TSRMLS_CC); @@ -798,7 +798,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry); - + zend_hash_init(&dom_element_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_element_prop_handlers, "tagName", dom_element_tag_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", dom_element_schema_type_info_read, NULL TSRMLS_CC); @@ -806,7 +806,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry); - + zend_hash_init(&dom_text_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_text_prop_handlers, "wholeText", dom_text_whole_text_read, NULL TSRMLS_CC); zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); @@ -816,7 +816,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry); - + zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", dom_typeinfo_type_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", dom_typeinfo_type_namespace_read, NULL TSRMLS_CC); @@ -824,7 +824,7 @@ PHP_MINIT_FUNCTION(dom) REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry); REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry); - + zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", dom_domerror_severity_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domerror_prop_handlers, "message", dom_domerror_message_read, NULL TSRMLS_CC); @@ -836,7 +836,7 @@ PHP_MINIT_FUNCTION(dom) REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry); REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry); - + zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", dom_domlocator_line_number_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", dom_domlocator_column_number_read, NULL TSRMLS_CC); @@ -850,7 +850,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry); - + zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", dom_documenttype_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_documenttype_prop_handlers, "entities", dom_documenttype_entities_read, NULL TSRMLS_CC); @@ -862,7 +862,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMNotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry); - + zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC); @@ -870,7 +870,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry); - + zend_hash_init(&dom_entity_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", dom_entity_public_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", dom_entity_system_id_read, NULL TSRMLS_CC); @@ -886,7 +886,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_entity_prop_handlers), NULL); REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry); - + zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", dom_processinginstruction_target_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", dom_processinginstruction_data_read, dom_processinginstruction_data_write TSRMLS_CC); @@ -1011,7 +1011,7 @@ PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */ zend_hash_destroy(&dom_xpath_prop_handlers); #endif zend_hash_destroy(&classes); - + /* If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and uncomment the following line, this will tell you the amount of not freed memory and the total used memory into apaches error_log */ @@ -1074,7 +1074,7 @@ void dom_xpath_objects_free_storage(void *object TSRMLS_DC) zend_hash_destroy(intern->registered_phpfunctions); FREE_HASHTABLE(intern->registered_phpfunctions); } - + if (intern->node_list) { zend_hash_destroy(intern->node_list); FREE_HASHTABLE(intern->node_list); @@ -1204,7 +1204,7 @@ zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC) { zend_object_value retval; dom_object *intern; - + intern = dom_objects_set_class(class_type, 1 TSRMLS_CC); retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)dom_objects_free_storage, dom_objects_clone TSRMLS_CC); @@ -1284,7 +1284,7 @@ zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_D zend_object_value retval; dom_object *intern; dom_nnodemap_object *objmap; - + intern = dom_objects_set_class(class_type, 1 TSRMLS_CC); intern->ptr = emalloc(sizeof(dom_nnodemap_object)); objmap = (dom_nnodemap_object *)intern->ptr; @@ -1442,7 +1442,7 @@ void php_dom_create_implementation(zval **retval TSRMLS_DC) { } /* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */ -int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) +int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) { xmlNodePtr nodep; @@ -1509,7 +1509,7 @@ void dom_normalize (xmlNodePtr nodep TSRMLS_DC) { xmlNodePtr child, nextp, newnextp; xmlAttrPtr attr; - xmlChar *strContent; + xmlChar *strContent; child = nodep->children; while(child != NULL) { @@ -1564,8 +1564,8 @@ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) { } memset(doc->oldNs, 0, sizeof(xmlNs)); doc->oldNs->type = XML_LOCAL_NAMESPACE; - doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE); - doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml"); + doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE); + doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml"); } cur = doc->oldNs; @@ -1590,7 +1590,7 @@ int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, i if (name_len == 0) { return NAMESPACE_ERR; } - + *localname = (char *)xmlSplitQName2((xmlChar *)qname, (xmlChar **) prefix); if (*localname == NULL) { *localname = (char *)xmlStrdup((xmlChar *)qname); diff --git a/ext/dom/tests/DOMDocument_loadXML_basic.phpt b/ext/dom/tests/DOMDocument_loadXML_basic.phpt new file mode 100644 index 0000000000..569593c007 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test DOMDocument::loadXML() basic behavior +--DESCRIPTION-- +This test verifies the basic behaviour of the method +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_loadXML_error1.phpt b/ext/dom/tests/DOMDocument_loadXML_error1.phpt new file mode 100644 index 0000000000..52d44ea291 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_error1.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test DOMDocument::loadXML() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects an opening and ending tag mismatch +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): expected '>' %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Premature end of data in tag books %s diff --git a/ext/dom/tests/DOMDocument_loadXML_error2.phpt b/ext/dom/tests/DOMDocument_loadXML_error2.phpt new file mode 100644 index 0000000000..6ac4193daf --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_error2.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test DOMDocument::loadXML() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects attributes values not closed between " or ' +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed2.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): AttValue: " or ' expected %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): attributes construct error %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Couldn't find end of Start Tag book %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: books %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Extra content at the end of the document %s diff --git a/ext/dom/tests/DOMDocument_loadXML_error3.phpt b/ext/dom/tests/DOMDocument_loadXML_error3.phpt new file mode 100644 index 0000000000..07f7ca7738 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_error3.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::loadXML() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects a typo in tag names +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed3.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: boOk line 8 and book %s diff --git a/ext/dom/tests/DOMDocument_loadXML_error4.phpt b/ext/dom/tests/DOMDocument_loadXML_error4.phpt new file mode 100644 index 0000000000..e35d3dcea5 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_error4.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::loadXML() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects an unsupported xml version +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed4.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Unsupported version '3.1' %s diff --git a/ext/dom/tests/DOMDocument_loadXML_error5.phpt b/ext/dom/tests/DOMDocument_loadXML_error5.phpt new file mode 100644 index 0000000000..a4aa1858f5 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_error5.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::loadXML() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects extra content at the end of the document +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed5.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Extra content at the end of the document %s diff --git a/ext/dom/tests/DOMDocument_loadXML_variation1.phpt b/ext/dom/tests/DOMDocument_loadXML_variation1.phpt new file mode 100644 index 0000000000..558137526f --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_variation1.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test DOMDocument::loadXML() with LIBXML_DTDLOAD option +--DESCRIPTION-- +This test verifies the right behaviour of the LIBXML_DTDLOAD constant +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book_with_dtd2.xml +LOAD_OPTIONS=LIBXML_DTDLOAD +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_loadXML_variation2.phpt b/ext/dom/tests/DOMDocument_loadXML_variation2.phpt new file mode 100644 index 0000000000..71f638efc1 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_variation2.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::loadXML() with LIBXML_DTDVALID option +--DESCRIPTION-- +This test verifies the right behaviour of the LIBXML_DTDVALID constant +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/wrong_book_with_dtd2.xml +LOAD_OPTIONS=LIBXML_DTDVALID +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Element book content does not follow the DTD, expecting (title , author), got (title author author ) %s diff --git a/ext/dom/tests/DOMDocument_loadXML_variation3.phpt b/ext/dom/tests/DOMDocument_loadXML_variation3.phpt new file mode 100644 index 0000000000..8e61ec4dbc --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_variation3.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::loadXML() with LIBXML_DTDVALID and LIBXML_NOERROR options +--DESCRIPTION-- +This test vrifies the right behaviour of the LIBXML_NOERROR constant +which avoids the display of the warning message +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/wrong_book_with_dtd.xml +LOAD_OPTIONS=LIBXML_DTDVALID | LIBXML_NOERROR +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_loadXML_variation4.phpt b/ext/dom/tests/DOMDocument_loadXML_variation4.phpt new file mode 100644 index 0000000000..4f1ea37c19 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadXML_variation4.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test DOMDocument::loadXML() with LIBXML_DTDATTR, LIBXML_NOCDATA, LIBXML_NOENT, LIBXML_NOBLANKS +--DESCRIPTION-- +This test verifies the right behaviour of the following constants: +LIBXML_DTDATTR, LIBXML_NOCDATA, LIBXML_NOENT and LIBXML_NOBLANKS +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book_with_dtd2.xml +LOAD_OPTIONS=LIBXML_DTDATTR|LIBXML_NOCDATA|LIBXML_NOENT|LIBXML_NOBLANKS +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentloadxml_test_method_savexml.php +--EXPECT-- +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE books [ +<!ENTITY entitest "entity is only for test purposes"> +<!ATTLIST title default CDATA "default title"> +<!ELEMENT books (book)*> +<!ELEMENT book (title , author)> +<!ELEMENT title (#PCDATA)> +<!ELEMENT author (#PCDATA)> +]> +<books><book><title default="default title">The Grapes of Wrath</title><author>John Steinbeck</author></book><book><title default="default title">The Pearl</title><author>John Steinbeck</author></book><book><title default="default title">entity is only for test purposes</title><author>data for test</author></book></books> diff --git a/ext/dom/tests/DOMDocument_load_basic.phpt b/ext/dom/tests/DOMDocument_load_basic.phpt new file mode 100644 index 0000000000..6d70ed4522 --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test DOMDocument::load() basic behavior +--DESCRIPTION-- +This test verifies the basic behaviour of the method +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_load_error1.phpt b/ext/dom/tests/DOMDocument_load_error1.phpt new file mode 100644 index 0000000000..2ac3f50979 --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_error1.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test DOMDocument::load() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects an opening and ending tag mismatch +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): expected '>' %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Premature end of data in tag books %s diff --git a/ext/dom/tests/DOMDocument_load_error2.phpt b/ext/dom/tests/DOMDocument_load_error2.phpt new file mode 100644 index 0000000000..23a5e4827d --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_error2.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test DOMDocument::load() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects attributes values not closed between " or ' +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed2.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): AttValue: " or ' expected %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): attributes construct error %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Couldn't find end of Start Tag book %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: books %s + +Warning: DOMDocument::load%r(XML){0,1}%r(): Extra content at the end of the document %s diff --git a/ext/dom/tests/DOMDocument_load_error3.phpt b/ext/dom/tests/DOMDocument_load_error3.phpt new file mode 100644 index 0000000000..b9ac49c466 --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_error3.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::load() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects and opening and ending tag mismatch +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed3.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: boOk line 8 and book %s diff --git a/ext/dom/tests/DOMDocument_load_error4.phpt b/ext/dom/tests/DOMDocument_load_error4.phpt new file mode 100644 index 0000000000..ca9ed79a3e --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_error4.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::load() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects an unsupported xml version +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed4.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Unsupported version '3.1' %s diff --git a/ext/dom/tests/DOMDocument_load_error5.phpt b/ext/dom/tests/DOMDocument_load_error5.phpt new file mode 100644 index 0000000000..a374f9474d --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_error5.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::load() detects not-well formed XML +--DESCRIPTION-- +This test verifies the method detects extra content at the end of the document +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/not_well_formed5.xml +LOAD_OPTIONS=0 +EXPECTED_RESULT=0 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Extra content at the end of the document %s diff --git a/ext/dom/tests/DOMDocument_load_variation1.phpt b/ext/dom/tests/DOMDocument_load_variation1.phpt new file mode 100644 index 0000000000..b2b99e74c7 --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_variation1.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test DOMDocument::load() with LIBXML_DTDLOAD option +--DESCRIPTION-- +This test verifies the right behaviour of the LIBXML_DTDLOAD constant +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book_with_dtd.xml +LOAD_OPTIONS=LIBXML_DTDLOAD +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_load_variation2.phpt b/ext/dom/tests/DOMDocument_load_variation2.phpt new file mode 100644 index 0000000000..c8460e55eb --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_variation2.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::load() with LIBXML_DTDVALID option +--DESCRIPTION-- +This test verifies the right behaviour of the LIBXML_DTDVALID constant +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/wrong_book_with_dtd.xml +LOAD_OPTIONS=LIBXML_DTDVALID +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECTF-- +Warning: DOMDocument::load%r(XML){0,1}%r(): Element book content does not follow the DTD, expecting (title , author), got (title author author ) %s diff --git a/ext/dom/tests/DOMDocument_load_variation3.phpt b/ext/dom/tests/DOMDocument_load_variation3.phpt new file mode 100644 index 0000000000..77801d475e --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_variation3.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test DOMDocument::load() with LIBXML_DTDVALID and LIBXML_NOERROR options +--DESCRIPTION-- +This test vrifies the right behaviour of the LIBXML_NOERROR constant +which avoids the display of the warning message +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/wrong_book_with_dtd.xml +LOAD_OPTIONS=LIBXML_DTDVALID | LIBXML_NOERROR +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentload_test_method.php +--EXPECT-- diff --git a/ext/dom/tests/DOMDocument_load_variation4.phpt b/ext/dom/tests/DOMDocument_load_variation4.phpt new file mode 100644 index 0000000000..3bf7ccc04d --- /dev/null +++ b/ext/dom/tests/DOMDocument_load_variation4.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test DOMDocument::load() with LIBXML_DTDATTR, LIBXML_NOCDATA, LIBXML_NOENT, LIBXML_NOBLANKS +--DESCRIPTION-- +This test verifies the right behaviour of the following constants: +LIBXML_DTDATTR, LIBXML_NOCDATA, LIBXML_NOENT and LIBXML_NOBLANKS +Environment variables used in the test: +- XML_FILE: the xml file to load +- LOAD_OPTIONS: the second parameter to pass to the method +- EXPECTED_RESULT: the expected result +--CREDITS-- +Antonio Diaz Ruiz <dejalatele@gmail.com> +--INI-- +assert.bail=true +--SKIPIF-- +<?php include('skipif.inc'); ?> +--ENV-- +XML_FILE=/book_with_dtd.xml +LOAD_OPTIONS=LIBXML_DTDATTR|LIBXML_NOCDATA|LIBXML_NOENT|LIBXML_NOBLANKS +EXPECTED_RESULT=1 +--FILE_EXTERNAL-- +domdocumentload_test_method_savexml.php +--EXPECT-- +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE books SYSTEM "books.dtd"> +<books><book><title default="default title">The Grapes of Wrath</title><author>John Steinbeck</author></book><book><title default="default title">The Pearl</title><author>John Steinbeck</author></book><book><title default="default title">entity is only for test purposes</title><author>data for test</author></book></books> diff --git a/ext/dom/tests/DOMDocument_schemaValidateSource_addAttrs.phpt b/ext/dom/tests/DOMDocument_schemaValidateSource_addAttrs.phpt new file mode 100644 index 0000000000..994b94d0c8 --- /dev/null +++ b/ext/dom/tests/DOMDocument_schemaValidateSource_addAttrs.phpt @@ -0,0 +1,25 @@ +--TEST-- +DomDocument::schemaValidateSource() - Add missing attribute default values from schema +--CREDITS-- +Chris Wright <info@daverandom.com> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$doc = new DOMDocument; + +$doc->load(dirname(__FILE__)."/book-attr.xml"); + +$xsd = file_get_contents(dirname(__FILE__)."/book.xsd"); + +$doc->schemaValidateSource($xsd, LIBXML_SCHEMA_CREATE); + +foreach ($doc->getElementsByTagName('book') as $book) { + var_dump($book->getAttribute('is-hardback')); +} + +?> +--EXPECT-- +string(5) "false" +string(4) "true" diff --git a/ext/dom/tests/DOMDocument_schemaValidateSource_error4.phpt b/ext/dom/tests/DOMDocument_schemaValidateSource_error4.phpt index 65c8d8678f..f841b87428 100644 --- a/ext/dom/tests/DOMDocument_schemaValidateSource_error4.phpt +++ b/ext/dom/tests/DOMDocument_schemaValidateSource_error4.phpt @@ -17,5 +17,5 @@ var_dump($result); ?> --EXPECTF-- -Warning: DOMDocument::schemaValidateSource() expects exactly 1 parameter, 0 given in %s.php on line %d +Warning: DOMDocument::schemaValidateSource() expects at least 1 parameter, 0 given in %s.php on line %d NULL diff --git a/ext/dom/tests/DOMDocument_schemaValidateSource_missingAttrs.phpt b/ext/dom/tests/DOMDocument_schemaValidateSource_missingAttrs.phpt new file mode 100644 index 0000000000..7c98a74b1d --- /dev/null +++ b/ext/dom/tests/DOMDocument_schemaValidateSource_missingAttrs.phpt @@ -0,0 +1,25 @@ +--TEST-- +DomDocument::schemaValidateSource() - Don't add missing attribute default values from schema +--CREDITS-- +Chris Wright <info@daverandom.com> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$doc = new DOMDocument; + +$doc->load(dirname(__FILE__)."/book-attr.xml"); + +$xsd = file_get_contents(dirname(__FILE__)."/book.xsd"); + +$doc->schemaValidateSource($xsd); + +foreach ($doc->getElementsByTagName('book') as $book) { + var_dump($book->getAttribute('is-hardback')); +} + +?> +--EXPECT-- +string(0) "" +string(4) "true" diff --git a/ext/dom/tests/DOMDocument_schemaValidate_addAttrs.phpt b/ext/dom/tests/DOMDocument_schemaValidate_addAttrs.phpt new file mode 100644 index 0000000000..e0b5251b23 --- /dev/null +++ b/ext/dom/tests/DOMDocument_schemaValidate_addAttrs.phpt @@ -0,0 +1,23 @@ +--TEST-- +DomDocument::schemaValidate() - Add missing attribute default values from schema +--CREDITS-- +Chris Wright <info@daverandom.com> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$doc = new DOMDocument; + +$doc->load(dirname(__FILE__)."/book-attr.xml"); + +$doc->schemaValidate(dirname(__FILE__)."/book.xsd", LIBXML_SCHEMA_CREATE); + +foreach ($doc->getElementsByTagName('book') as $book) { + var_dump($book->getAttribute('is-hardback')); +} + +?> +--EXPECT-- +string(5) "false" +string(4) "true" diff --git a/ext/dom/tests/DOMDocument_schemaValidate_error4.phpt b/ext/dom/tests/DOMDocument_schemaValidate_error4.phpt index d4817deca0..9e4b6c4b7c 100644 --- a/ext/dom/tests/DOMDocument_schemaValidate_error4.phpt +++ b/ext/dom/tests/DOMDocument_schemaValidate_error4.phpt @@ -17,5 +17,5 @@ var_dump($result); ?> --EXPECTF-- -Warning: DOMDocument::schemaValidate() expects exactly 1 parameter, 0 given in %s.php on line %d +Warning: DOMDocument::schemaValidate() expects at least 1 parameter, 0 given in %s.php on line %d NULL diff --git a/ext/dom/tests/DOMDocument_schemaValidate_missingAttrs.phpt b/ext/dom/tests/DOMDocument_schemaValidate_missingAttrs.phpt new file mode 100644 index 0000000000..d253ad9690 --- /dev/null +++ b/ext/dom/tests/DOMDocument_schemaValidate_missingAttrs.phpt @@ -0,0 +1,23 @@ +--TEST-- +DomDocument::schemaValidate() - Don't add missing attribute default values from schema +--CREDITS-- +Chris Wright <info@daverandom.com> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$doc = new DOMDocument; + +$doc->load(dirname(__FILE__)."/book-attr.xml"); + +$doc->schemaValidate(dirname(__FILE__)."/book.xsd"); + +foreach ($doc->getElementsByTagName('book') as $book) { + var_dump($book->getAttribute('is-hardback')); +} + +?> +--EXPECT-- +string(0) "" +string(4) "true" diff --git a/ext/dom/tests/book-attr.xml b/ext/dom/tests/book-attr.xml new file mode 100644 index 0000000000..ba4298d098 --- /dev/null +++ b/ext/dom/tests/book-attr.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" ?> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book is-hardback="true"> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/book.xsd b/ext/dom/tests/book.xsd index 45986fc4b3..6b4a8ea545 100755 --- a/ext/dom/tests/book.xsd +++ b/ext/dom/tests/book.xsd @@ -9,6 +9,7 @@ <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"/> </xs:sequence> + <xs:attribute name="is-hardback" type="xs:boolean" default="false" use="optional" /> </xs:complexType> </xs:element> </xs:sequence> diff --git a/ext/dom/tests/book_with_dtd.xml b/ext/dom/tests/book_with_dtd.xml new file mode 100644 index 0000000000..de12e92102 --- /dev/null +++ b/ext/dom/tests/book_with_dtd.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE books SYSTEM "books.dtd"> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> + <book> + <title>&entitest;</title> + <author><![CDATA[data for test]]></author> + </book> +</books> diff --git a/ext/dom/tests/book_with_dtd2.xml b/ext/dom/tests/book_with_dtd2.xml new file mode 100644 index 0000000000..aeb4f0b800 --- /dev/null +++ b/ext/dom/tests/book_with_dtd2.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE books [ +<!ENTITY entitest "entity is only for test purposes"> +<!ATTLIST title default CDATA "default title"> +<!ELEMENT books (book*)> +<!ELEMENT book (title, author)> +<!ELEMENT title (#PCDATA)> +<!ELEMENT author (#PCDATA)> +]> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> + <book> + <title>&entitest;</title> + <author><![CDATA[data for test]]></author> + </book> +</books> diff --git a/ext/dom/tests/books.dtd b/ext/dom/tests/books.dtd new file mode 100644 index 0000000000..b3f03c1c16 --- /dev/null +++ b/ext/dom/tests/books.dtd @@ -0,0 +1,7 @@ +<!ENTITY entitest "entity is only for test purposes"> +<!ATTLIST title + default CDATA "default title"> + <!ELEMENT books (book*)> + <!ELEMENT book (title, author)> + <!ELEMENT title (#PCDATA)> + <!ELEMENT author (#PCDATA)> diff --git a/ext/dom/tests/domdocumentload_test_method.php b/ext/dom/tests/domdocumentload_test_method.php new file mode 100644 index 0000000000..7afce15c3a --- /dev/null +++ b/ext/dom/tests/domdocumentload_test_method.php @@ -0,0 +1,12 @@ +<?php +include(dirname(__FILE__) . '/domdocumentload_utilities.php'); + +$doc = new DOMDocument(); + +$libxml_options = libxml_options_to_int(getenv('LOAD_OPTIONS')); + +$result = $doc->load(dirname(__FILE__) . getenv('XML_FILE'), $libxml_options); + +$expectedResult = (bool) getenv('EXPECTED_RESULT'); +assert('$result === $expectedResult'); +?> diff --git a/ext/dom/tests/domdocumentload_test_method_savexml.php b/ext/dom/tests/domdocumentload_test_method_savexml.php new file mode 100644 index 0000000000..8ffd944524 --- /dev/null +++ b/ext/dom/tests/domdocumentload_test_method_savexml.php @@ -0,0 +1,14 @@ +<?php +include(dirname(__FILE__) . '/domdocumentload_utilities.php'); + +$doc = new DOMDocument(); + +$libxml_options = libxml_options_to_int(getenv('LOAD_OPTIONS')); + +$result = $doc->load(dirname(__FILE__) . getenv('XML_FILE'), $libxml_options); + +$expectedResult = (bool) getenv('EXPECTED_RESULT'); +assert('$result === $expectedResult'); + +echo $doc->saveXML(); +?> diff --git a/ext/dom/tests/domdocumentload_utilities.php b/ext/dom/tests/domdocumentload_utilities.php new file mode 100644 index 0000000000..efd1e5a1a5 --- /dev/null +++ b/ext/dom/tests/domdocumentload_utilities.php @@ -0,0 +1,16 @@ +<?php + +function libxml_options_to_int($libxmlOptions) { + + $defined_constants = get_defined_constants(true); + $env_array = explode('|', $libxmlOptions); + $libxml_constants = array_intersect_key($defined_constants['libxml'], array_flip($env_array)); + + $sum = 0; + foreach($libxml_constants as $value) { + $sum = $sum|$value; + } + + return $sum; +} +?> diff --git a/ext/dom/tests/domdocumentloadxml_test_method.php b/ext/dom/tests/domdocumentloadxml_test_method.php new file mode 100644 index 0000000000..7c4be85cf1 --- /dev/null +++ b/ext/dom/tests/domdocumentloadxml_test_method.php @@ -0,0 +1,12 @@ +<?php +include(dirname(__FILE__) . '/domdocumentload_utilities.php'); + +$doc = new DOMDocument(); + +$libxml_options = libxml_options_to_int(getenv('LOAD_OPTIONS')); +$result = $doc->loadXML(file_get_contents(dirname(__FILE__) . getenv('XML_FILE')), + $libxml_options); + +$expectedResult = (bool) getenv('EXPECTED_RESULT'); +assert('$result === $expectedResult'); +?> diff --git a/ext/dom/tests/domdocumentloadxml_test_method_savexml.php b/ext/dom/tests/domdocumentloadxml_test_method_savexml.php new file mode 100644 index 0000000000..550219fb78 --- /dev/null +++ b/ext/dom/tests/domdocumentloadxml_test_method_savexml.php @@ -0,0 +1,14 @@ +<?php +include(dirname(__FILE__) . '/domdocumentload_utilities.php'); + +$doc = new DOMDocument(); + +$libxml_options = libxml_options_to_int(getenv('LOAD_OPTIONS')); +$result = $doc->loadXML(file_get_contents(dirname(__FILE__) . getenv('XML_FILE')), + $libxml_options); + +$expectedResult = (bool) getenv('EXPECTED_RESULT'); +assert('$result === $expectedResult'); + +echo $doc->saveXML(); +?> diff --git a/ext/dom/tests/not_well_formed.xml b/ext/dom/tests/not_well_formed.xml new file mode 100644 index 0000000000..d362e0c4b9 --- /dev/null +++ b/ext/dom/tests/not_well_formed.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<!-- Opening and ending tag mismatch --> +<books> + <book> + <title>The Grapes of Wrath + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/not_well_formed2.xml b/ext/dom/tests/not_well_formed2.xml new file mode 100644 index 0000000000..da6b3bccba --- /dev/null +++ b/ext/dom/tests/not_well_formed2.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<!-- AttValue: " or ' expected --> +<books> + <book number=nine> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/not_well_formed3.xml b/ext/dom/tests/not_well_formed3.xml new file mode 100644 index 0000000000..99b2189074 --- /dev/null +++ b/ext/dom/tests/not_well_formed3.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<!-- Opening and ending tag mismatch --> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <boOk> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/not_well_formed4.xml b/ext/dom/tests/not_well_formed4.xml new file mode 100644 index 0000000000..581b8bd962 --- /dev/null +++ b/ext/dom/tests/not_well_formed4.xml @@ -0,0 +1,12 @@ +<?xml version="3.1" ?> +<!-- Unsupported version '3.1' --> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/not_well_formed5.xml b/ext/dom/tests/not_well_formed5.xml new file mode 100644 index 0000000000..f42ead83ab --- /dev/null +++ b/ext/dom/tests/not_well_formed5.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<!-- Extra content at the end of the document --> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> diff --git a/ext/dom/tests/wrong_book_with_dtd.xml b/ext/dom/tests/wrong_book_with_dtd.xml new file mode 100644 index 0000000000..3a2d48e355 --- /dev/null +++ b/ext/dom/tests/wrong_book_with_dtd.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE books SYSTEM "books.dtd"> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/dom/tests/wrong_book_with_dtd2.xml b/ext/dom/tests/wrong_book_with_dtd2.xml new file mode 100644 index 0000000000..6c49deb1f5 --- /dev/null +++ b/ext/dom/tests/wrong_book_with_dtd2.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE books [ +<!ENTITY entitest "entity is only for test purposes"> +<!ATTLIST title default CDATA "default title"> +<!ELEMENT books (book)*> +<!ELEMENT book (title , author)> +<!ELEMENT title (#PCDATA)> +<!ELEMENT author (#PCDATA)> +]> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> |