{"id":18815596,"url":"https://github.com/shulard/atoum-xml-extension","last_synced_at":"2025-04-13T21:51:30.151Z","repository":{"id":57050138,"uuid":"67404594","full_name":"shulard/atoum-xml-extension","owner":"shulard","description":"An atoum extension to perform tests on XML files ","archived":false,"fork":false,"pushed_at":"2018-02-14T12:36:34.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T12:11:48.550Z","etag":null,"topics":["atoum","atoum-extension","dtd","unit-testing","xml-document","xpath"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shulard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-05T08:54:31.000Z","updated_at":"2020-01-31T03:53:44.000Z","dependencies_parsed_at":"2022-08-24T03:40:45.183Z","dependency_job_id":null,"html_url":"https://github.com/shulard/atoum-xml-extension","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shulard%2Fatoum-xml-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shulard%2Fatoum-xml-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shulard%2Fatoum-xml-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shulard%2Fatoum-xml-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shulard","download_url":"https://codeload.github.com/shulard/atoum-xml-extension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788855,"owners_count":21161726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atoum","atoum-extension","dtd","unit-testing","xml-document","xpath"],"created_at":"2024-11-07T23:49:40.583Z","updated_at":"2025-04-13T21:51:30.132Z","avatar_url":"https://github.com/shulard.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shulard/atoum-xml-extension [![Build Status](https://travis-ci.org/shulard/atoum-xml-extension.svg?branch=master)](https://travis-ci.org/shulard/atoum-xml-extension) [![Latest Stable Version](https://img.shields.io/packagist/v/shulard/atoum-xml-extension.svg)](https://packagist.org/packages/shulard/atoum-xml-extension)\n\nThis atoum extension allows you to test XML document using [atoum](https://github.com/atoum/atoum). It's possible to execute\nxpath against the document or to validate it using DTD, XSD or RelaxNG schema. You can use it to validate HTML documents too.\n\n## Example\n\n```php\n\u003c?php\nnamespace shulard\\example\\xml;\n\nuse atoum;\n\nclass foo extends atoum\\test\n{\n    public function testXMLDocument()\n    {\n        $xml = \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\" ?\u003e\n\u003croot xmlns:atom=\"http://purl.org/atom/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\u003e\n    \u003catom:feed\u003e1\u003cdc:node\u003enamespaced content\u003c/dc:node\u003e2\u003c/atom:feed\u003e\n    \u003cnode attribute=\"value\" /\u003e\n    \u003cnode m:attribute=\"namespaced value\" /\u003e\n\u003c/root\u003e\nXML;\n\n        $this\n            -\u003ethen\n                -\u003exml($xml)\n                    -\u003eisValidAgainstSchema\n                        -\u003edtd('file://path/to.dtd', 'root')\n                -\u003enode\n                    -\u003ehasNamespace('atom', 'http://purl.org/atom/ns#')\n                    -\u003eisUsedNamespace('dc', 'http://purl.org/dc/elements/1.1/')\n                    -\u003ewithNamespace('m', 'http://purl.org/atom/ns#')\n                        -\u003expath('//m:feed')\n                            -\u003ehasSize(1)\n        ;\n    }\n}\n```\n\nWhen running this test, the XML document will be loaded and:\n\n* Validate the document using a DTD;\n* Check if `atom` namespace is present in document declaration;\n* Check that `dc` namespace is used inside the document;\n* Execute a xpath one namespaced node and check returning node collection.\n\n## Install it\n\nInstall extension using [composer](https://getcomposer.org):\n\n```bash\ncomposer require --dev shulard/atoum-xml-extension\n```\n\nEnable and configure the extension using atoum configuration file:\n\n```php\n\u003c?php\n\n// .atoum.php\n\nrequire_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';\n\nuse mageekguy\\atoum\\xml;\n\n$runner-\u003eaddExtension(new xml\\extension($script));\n```\n\n## Use it\n\n```php\n\u003c?php\nnamespace shulard\\example\\xml;\n\nuse atoum;\n\nclass foo extends atoum\\test\n{\n    /**\n     * Test attribute on nodes\n     */\n    public function testAttributes()\n    {\n        $xml = \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\" ?\u003e\n\u003croot\u003e\n    \u003cnode attribute=\"value\" /\u003e\n    \u003cnode m:attribute=\"namespaced value\" /\u003e\n\u003c/root\u003e\nXML;\n\n        $node = $this-\u003exml($xml)\n            -\u003echildren\n            -\u003eitem(0);\n        $node\n            -\u003eattributes()\n                -\u003ehasSize(1)\n                -\u003estring['attribute']-\u003eisEqualTo('value')\n        ;\n        $node\n            -\u003eattributes('m')\n                -\u003ehasSize(1)\n                -\u003estring['attribute']-\u003eisEqualTo('namespaced value')\n        ;\n    }\n\n    /**\n     * Test node content using phpString asserter\n     */\n    public function testXpathAndNodeContent()\n    {\n        $xml = \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\" ?\u003e\n\u003croot\u003e\n    \u003cnode attribute=\"value\"\u003econtent\u003c/node\u003e\n\u003c/root\u003e\nXML;\n\n        $this\n            -\u003ethen\n                -\u003exml($xml)\n                -\u003expath('//node')\n                    -\u003ehasSize(1)\n                    -\u003eitem(0)\n                        -\u003enodeValue-\u003eisEqualTo('content')\n        ;\n    }\n\n    /**\n     * Validate namespace on nodes\n     */\n    public function testNamespaces()\n    {\n        $xml = \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\" ?\u003e\n\u003croot xmlns:atom=\"http://purl.org/atom/ns#\" xmlns:toto=\"http://example.com\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\u003e\n    \u003catom:feed\u003e1\u003cdc:node\u003enamespaced content\u003c/dc:node\u003e2\u003c/atom:feed\u003e\n\u003c/root\u003e\nXML;\n\n        $this\n            -\u003ethen\n                -\u003exml($xml)\n                -\u003ehasNamespace('atom', 'http://purl.org/atom/ns#')\n                -\u003eisUsedNamespace('dc', 'http://purl.org/dc/elements/1.1/')\n                    -\u003ewithNamespace('m', 'http://purl.org/atom/ns#')\n                    -\u003expath('//m:feed')\n                        -\u003ehasSize(1)\n                        -\u003eitem(0)\n                            -\u003expath('./dc:node')\n                                -\u003ehasSize(1)\n                            -\u003eparent\n                                -\u003expath('//atom:feed')\n                                    -\u003ehasSize(1)\n                                    -\u003eitem(0)\n                                        -\u003enodeValue-\u003eisEqualTo(\"12\")\n        ;\n    }\n\n    /**\n     * Validate document through schema (DTD, XSD, RNG)\n     */\n    public function testSchemaValidation()\n    {\n        $xml = \u003c\u003c\u003cXML\n\u003c?xml version=\"1.0\" ?\u003e\n\u003croot\u003e\n    \u003catom:feed\u003e1\u003cdc:node\u003enamespaced content\u003c/dc:node\u003e2\u003c/atom:feed\u003e\n\u003c/root\u003e\nXML;\n\n        $this\n            -\u003ethen\n                -\u003exml($xml)\n                    -\u003eisValidAgainstSchema\n                        -\u003edtd('file://path/to.dtd', 'root')\n                -\u003enode\n                    -\u003eisValidAgainstSchema\n                        -\u003eschema('/path/to/schema.xsd')\n                -\u003enode\n                    -\u003eisValidAgainstSchema\n                        -\u003erelaxNg('/path/to/file.rng')\n        ;\n    }\n\n    /**\n     * You can also make tests on HTML Document\n     */\n    public function testOnHtmlDocument()\n    {\n        $this\n            -\u003ethen\n                -\u003ehtml(file_get_contents('http://example.com'))\n                -\u003expath('//title')\n                    -\u003eitem(0)\n                        -\u003enodevalue\n                            -\u003eisEqualTo('My awesome title')\n                -\u003expath('//body/script')\n                    -\u003elast()\n                        -\u003enodevalue\n                            -\u003econtains('GMTXXXXXX');\n        ;\n    }\n}\n```\n\n## Links\n\n* [atoum](http://atoum.org)\n* [atoum's documentation](http://docs.atoum.org)\n\n## Licence\n\natoum-xml-extension is released under the Apache2 License. See the bundled [LICENSE](https://github.com/shulard/atoum-xml-extension/blob/master/LICENSE) file for details.\n\n![atoum](http://atoum.org/images/logo/atoum.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshulard%2Fatoum-xml-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshulard%2Fatoum-xml-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshulard%2Fatoum-xml-extension/lists"}