{"id":21835292,"url":"https://github.com/wmde/hamcrest-html-matchers","last_synced_at":"2025-04-14T08:52:10.971Z","repository":{"id":16485816,"uuid":"79907643","full_name":"wmde/hamcrest-html-matchers","owner":"wmde","description":"Set of Hamcrest matchers for HTML assertrions","archived":false,"fork":false,"pushed_at":"2025-01-28T22:27:50.000Z","size":123,"stargazers_count":1,"open_issues_count":6,"forks_count":1,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-27T22:22:54.690Z","etag":null,"topics":["assert","assertion-library","hamcrest","html","html-assertrions","matcher","testing"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wmde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-24T12:00:03.000Z","updated_at":"2024-12-16T11:59:57.000Z","dependencies_parsed_at":"2022-08-08T19:00:04.941Z","dependency_job_id":null,"html_url":"https://github.com/wmde/hamcrest-html-matchers","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmde%2Fhamcrest-html-matchers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmde%2Fhamcrest-html-matchers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmde%2Fhamcrest-html-matchers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmde%2Fhamcrest-html-matchers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wmde","download_url":"https://codeload.github.com/wmde/hamcrest-html-matchers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852085,"owners_count":21171837,"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":["assert","assertion-library","hamcrest","html","html-assertrions","matcher","testing"],"created_at":"2024-11-27T20:19:27.445Z","updated_at":"2025-04-14T08:52:10.965Z","avatar_url":"https://github.com/wmde.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is the set of Hamcrest matchers for HTML assertions\n========================================================\n[![Build Status](https://github.com/wmde/hamcrest-html-matchers/actions/workflows/php.yml/badge.svg)](https://github.com/wmde/hamcrest-html-matchers/actions/workflows/php.yml)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wmde/hamcrest-html-matchers/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/wmde/hamcrest-html-matchers/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/wmde/hamcrest-html-matchers/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/wmde/hamcrest-html-matchers/?branch=master)\n\nUsage examples\n--------------\nHamcrest allows you to create pretty complicated and flexible assertions. Just remember:\n\n*\"You can\" does not mean \"you should\".*\n\n\nThe following example shows how we can ensure that there is an HTML form and password entered in it is not weak: \n\n```php\n$html = '\u003cdiv\u003e\n            \u003cform\u003e\n                \u003cinput name=\"password\" value=\"strong password\"/\u003e\n            \u003c/form\u003e\n         \u003c/div\u003e';\n\nassertThat($html, is(htmlPiece(\n    havingChild(\n        both(withTagName('form'))\n        -\u003eandAlso(\n            havingDirectChild(\n                allOf(\n                    withTagName('input'),\n                    withAttribute('name')-\u003ehavingValue('password'),\n                    withAttribute('value')-\u003ehavingValue(not('weak password')))))))));\n```\nUsage limitations:\n  * Each HTML assertion starts with `htmlPiece()` call (`is()` can be used to improve readability)\n  * One of `havingRootElement()`, `havingDirectChild()` or `havingChild()` needed to be passed as an argument to `htmlPiece()`\n\nDocumentation\n-------------\nInformation about general Hamcrest usage can be found at [Hamcrest GitHub repository](https://github.com/hamcrest/hamcrest-php).\n\n\nAvailable Matchers\n------------------\n* `htmlPiece()` - checks that string is a valid HTML, parses it and passes control to given matcher if one present\n    ```php\n    assertThat('\u003cp\u003e\u003c/p\u003e', is(htmlPiece())); // Just checking that string is a valid piece of HTML\n    ```\n* `havingRootElement` - checks given constraint against root element of HTML. *NOTE: Can be passed only to `htmlPiece()`*\n    ```php\n    assertThat('\u003cp\u003e\u003c/p\u003e', htmlPiece(havingRootElement(withTagName('p'))));\n    ```\n\n* `havingDirectChild` - checks given constraint against direct children \n    ```php\n    assertThat('\u003cp\u003e\u003cb\u003e\u003c/b\u003e\u003c/p\u003e', htmlPiece(havingRootElement(havingDirectChild(withTagName('b')))));\n    ```\n\n* `havingChild` - checks given constraint against all children \n    ```php\n    assertThat('\u003cp\u003e\u003cb\u003e\u003c/b\u003e\u003c/p\u003e', htmlPiece(havingChild(withTagName('b'))));\n    ```\n\n* `withTagName` - checks given constraint against tag name\n    ```php\n    assertThat('\u003cp\u003e\u003cb\u003e\u003c/b\u003e\u003c/p\u003e', htmlPiece(havingChild(withTagName(\n        either(equalTo('i'))-\u003eorElse(equalTo('b'))\n    ))));\n    ```\n\n* `withAttribute` - checks given constraint against elements attributes comparing names and values\n    ```php\n    assertThat('\u003cp\u003e\u003cinput required\u003e\u003c/p\u003e', htmlPiece(havingChild(withAttribute('required'))));\n    ```\n    ```php\n    assertThat('\u003cp\u003e\u003cinput data-value=\"some data\"\u003e\u003c/p\u003e', htmlPiece(havingChild(\n        withAttribute(startsWith('data-'))-\u003ehavingValue('some data'))));\n    ```\n    \n* `withClass` - checks given constraint against element's class list\n  ```php\n  assertThat('\u003cp class=\"class1 class2 class3\"\u003e\u003c/p\u003e', htmlPiece(havingChild(\n        withClass('class2'))));\n  ```\n\n* `havingTextContents` - checks given constraint against elements text contents\n    ```php\n    assertThat('\u003cdiv\u003e\u003cp\u003ethis is Some Text\u003c/p\u003e\u003c/div\u003e', htmlPiece(havingChild(\n        havingTextContents(containsString('some text')-\u003eignoringCase()))));\n    ```\n\n* `tagMatchingOutline` - tolerantly checks that tag matches given *outline* (*outline* - tag representation in HTML format)\n\n  That means:\n    * Element's tag name is equal to outline's tag name\n    * Element has all the attributes that outline has with the same values. If element has more attributes than outline it still matches. \n      * **NOTE:** Attribute `class` is treated in a different manner (see further). \n      * **NOTE:** If attribute outlined is boolean, then its value in element won't be checked, just presence.\n    * Element has all html classes that outline has.\n    \n  This will pass:\n  ```php\n  assertThat('\u003cform\u003e\u003cinput id=\"id-pass\" name=\"password\" class=\"pretty green\" required=\"required\"\u003e\u003c/form\u003e', \n      htmlPiece(havingChild(\n          tagMatchingOutline('\u003cinput name=\"password\" class=\"green\" required\u003e')\n    )));\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmde%2Fhamcrest-html-matchers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwmde%2Fhamcrest-html-matchers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmde%2Fhamcrest-html-matchers/lists"}