dxw / assertions Goto Github PK
View Code? Open in Web Editor NEWExtra assertions for PHPUnit
License: MIT License
Extra assertions for PHPUnit
License: MIT License
Currently it's not immediately obvious what the difference between these two function calls is:
$this->assertHTMLEquals($expected, $actual, true);
$this->assertHTMLEquals($expected, $actual, false);
So let's use two separate functions:
$this->assertHTMLEquals($expected, $actual);
$this->assertHTMLEqualsIgnoringWhitespace($expected, $actual);
To follow PHPUnit conventions, we could use assertHTMLEquals/assertHTMLSame.
Even outside of $ignoreWhitespace mode, IIRC in HTML all whitespace is equivalent. So " " and "\n" should be treated as equal.
DOMDocument::loadHTML(): Tag article invalid in Entity, line: 3
assertions/tests/html_test.php
Lines 40 to 43 in 18a9bef
Likely to be either a bug in my understanding of HTML, or PHP's understanding of HTML.
API should be identical to \Dxw\Assertions\HTML.
Ideally we should convert both documents to Canonical XML.
Here's a bit of code we used on another project:
protected function assertXMLEquals($expected, $actual)
{
call_user_func_array(
[$this, 'assertEquals'],
array_map(
function ($x) {
$d = new DOMDocument;
$d->loadXML($x);
$t = $d->C14N();
$t = preg_replace('/^\s+/m', '', $t);
$t = preg_replace('/\n/', '', $t);
$t = preg_replace('/></', ">\n<", $t);
return $t;
},
[$expected, $actual]
)
);
}
DOMDocument::loadHTML(): Empty string supplied as input
An empty string is a valid HTML fragment. So it should be allowed by this library.
This would probably fix several open issues.
This one may be a viable option: https://github.com/Masterminds/html5-php
Lines 16 to 19 in 18a9bef
This is just wrong. We should be able to iterate through the DOM and when we encounter a text node we should remove all leading/trailing whitespace.
i.e. There's a $this->assertRegExp()
but no $this->assertNotRegExp()
.
The HTML should be pretty-printed before handing over to assertEquals() (and we could strip the DTD and other boilerplate HTML).
We should perhaps also directly call assertThat(), so that we can have it print "Failed asserting that two HTML fragments are equal."
Bad output:
2) CategoryWidgetTest::testGetOutput2
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><body><div class="category-widget"><div class="current-cat"><ul><li><a href="/category/meow/">Meowz</a><ul><li><a href="/category/mew/">meW</a></li><li><a href="/category/mew2/">mew2</a></li></ul></li></ul></div><div class="other-cats"><ul><li>Other contents<ul><li><a href="/category/meowth/">Meowthhhh</a></li><li><a href="/category/marth/">Marth</a></li></ul></li></ul></div></div></body></html>'
+'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><body><div class="category-widget"><div class="current-cat"><ul><li><a href="/category/cat/">Cat</a><ul><li><a href="/category/oof/">Oof</a></li><li><a href="/category/woo/">Woo</a></li></ul></li></ul></div><div class="other-cats"><ul><li>Other contents<ul><li><a href="/category/cat/">Cat</a></li><li><a href="/category/cog/">Cog</a></li></ul></li></ul></div></div></body></html>'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.