test: new assertHTMLEquals()
authorAntoine Musso <hashar@free.fr>
Mon, 3 Sep 2012 08:46:07 +0000 (10:46 +0200)
committerAntoine Musso <hashar@free.fr>
Mon, 3 Sep 2012 08:47:36 +0000 (10:47 +0200)
Very trivial helper to compare HTML content. The method just add a
newline after each closing angle and then call assertEquals().

Change-Id: I5e6daa916a4fb452824616fa3c8a87bdb8038e8c

tests/phpunit/MediaWikiTestCase.php

index 49c2a70..bfad334 100644 (file)
@@ -441,6 +441,25 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                );
        }
 
+       /**
+        * Put each HTML element on its own line and then equals() the results
+        *
+        * Use for nicely formatting of PHPUnit diff output when comparing very
+        * simple HTML
+        *
+        * @since 1.20
+        *
+        * @param String $expected HTML on oneline
+        * @param String $actual HTML on oneline
+        * @param String $msg Optional message
+        */
+       protected function assertHTMLEquals( $expected, $actual, $msg='' ) {
+               $expected = str_replace( '>', ">\n", $expected );
+               $actual   = str_replace( '>', ">\n", $actual   );
+
+               $this->assertEquals( $expected, $actual, $msg );
+       }
+
        /**
         * Does an associative sort that works for objects.
         *