Giter Site home page Giter Site logo

assertions's People

Contributors

mallorydxw avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

w10t

assertions's Issues

Use separate functions for whitespace modes

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.

Fix whitespace handling

Even outside of $ignoreWhitespace mode, IIRC in HTML all whitespace is equivalent. So " " and "\n" should be treated as equal.

Tab characters are being stripped

$h->assertHTMLEquals("<a href='aaa'>\nbbb <br>\t</a>", '<a href="aaa">bbb<br></a>');
$this->assertEquals([
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><a href=\"aaa\">\nbbb <br></a></body></html>\n",

Likely to be either a bug in my understanding of HTML, or PHP's understanding of HTML.

Implement \Dxw\Assertions\XML

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]
            )
        );
    }

Allow empty strings

DOMDocument::loadHTML(): Empty string supplied as input

An empty string is a valid HTML fragment. So it should be allowed by this library.

Fix ignoreWhitespace mode

assertions/src/HTML.php

Lines 16 to 19 in 18a9bef

if ($ignoreWhitespace) {
$out = preg_replace('/>\s+/m', '>', $out);
$out = preg_replace('/\s+</m', '<', $out);
}

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.

Make the output nicer

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>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.