diff --git a/tests/cases/README.txt b/tests/cases/README.txt index 29514b24d..8cd917784 100644 --- a/tests/cases/README.txt +++ b/tests/cases/README.txt @@ -1,4 +1,10 @@ -The HTML files were saved from: +To update the expected outputs, run the PHP tests with the environment variable +"DISCUSSIONTOOLS_OVERWRITE_TESTS" set to any value, e.g.: + + DISCUSSIONTOOLS_OVERWRITE_TESTS=1 php tests/phpunit/phpunit.php extensions/DiscussionTools/tests/phpunit/ + + +The input HTML files were saved from: pl-big: https://pl.wikipedia.org/w/index.php?action=render&title=Wikipedia:Kawiarenka/Artyku%C5%82y_dyskusja/Archiwum/2018-pa%C5%BAdziernik&oldid=55171451 diff --git a/tests/phpunit/CommentModifierTest.php b/tests/phpunit/CommentModifierTest.php index 99f50d519..b15521a8c 100644 --- a/tests/phpunit/CommentModifierTest.php +++ b/tests/phpunit/CommentModifierTest.php @@ -43,8 +43,10 @@ class CommentModifierTest extends CommentTestCase { $expectedDoc = self::createDocument( $expected ); - // Uncomment this to write updated content to the "modified HTML" files: - // self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + // Optionally write updated content to the "modified HTML" files + if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { + self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + } // saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name ); @@ -87,8 +89,10 @@ class CommentModifierTest extends CommentTestCase { $expectedDoc = self::createDocument( $expected ); - // Uncomment this to write updated content to the "reply HTML" files: - // self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + // Optionally write updated content to the "reply HTML" files + if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { + self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + } // saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name ); diff --git a/tests/phpunit/CommentParserTest.php b/tests/phpunit/CommentParserTest.php index 836ed7557..8ad4a6af1 100644 --- a/tests/phpunit/CommentParserTest.php +++ b/tests/phpunit/CommentParserTest.php @@ -203,8 +203,10 @@ class CommentParserTest extends CommentTestCase { $processedThreads[] = $thread; } - // Uncomment this to write updated content to the JSON files: - // self::overwriteJsonFile( $expectedPath, $processedThreads ); + // Optionally write updated content to the JSON files + if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { + self::overwriteJsonFile( $expectedPath, $processedThreads ); + } foreach ( $threads as $i => $thread ) { self::assertEquals( $expected[$i], $processedThreads[$i], $name . ' section ' . $i ); diff --git a/tests/phpunit/DataTest.php b/tests/phpunit/DataTest.php index 5af2a6508..eadda0f93 100644 --- a/tests/phpunit/DataTest.php +++ b/tests/phpunit/DataTest.php @@ -24,8 +24,10 @@ class DataTest extends CommentTestCase { $data = Data::getLocalData( null, $conf, $langCode ); - // Uncomment this to write updated content to the JSON files: - // self::overwriteJsonFile( $expectedPath, $data ); + // Optionally write updated content to the JSON files + if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { + self::overwriteJsonFile( $expectedPath, $data ); + } self::assertEquals( $expectedData, $data ); } diff --git a/tests/phpunit/ThreadItemTest.php b/tests/phpunit/ThreadItemTest.php index db4bcdfe7..c2d53f0c2 100644 --- a/tests/phpunit/ThreadItemTest.php +++ b/tests/phpunit/ThreadItemTest.php @@ -74,8 +74,10 @@ class ThreadItemTest extends CommentTestCase { $transcludedFrom[ $comment->getId() ] = $comment->getTranscludedFrom(); } - // Uncomment this to write updated content to the JSON files: - // self::overwriteJsonFile( $expectedPath, $transcludedFrom ); + // Optionally write updated content to the JSON files + if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { + self::overwriteJsonFile( $expectedPath, $transcludedFrom ); + } self::assertEquals( $expected,