From 6d710bdf819f99e446742d4d3a0ce518a612faf3 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Wed, 4 Dec 2019 15:02:41 -0500 Subject: [PATCH] Use dataProvider in TemplateDataTest.php Change-Id: Ib19a012bc40b523bcd9837c1122539fca8aeec93 --- .../Parsoid/Html2Wt/TemplateDataTest.php | 112 +++++++++--------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/tests/phpunit/Parsoid/Html2Wt/TemplateDataTest.php b/tests/phpunit/Parsoid/Html2Wt/TemplateDataTest.php index f36f8ebc2..a79611d21 100644 --- a/tests/phpunit/Parsoid/Html2Wt/TemplateDataTest.php +++ b/tests/phpunit/Parsoid/Html2Wt/TemplateDataTest.php @@ -39,8 +39,8 @@ private function verifyTransformation( $newHTML, $origHTML, $origWT, $expectedWT $this->assertEquals( $expectedWT, $wt, $description ); } - private function defineTestData(): array { - $testData = [ + public function defineTestData(): array { + return [ // 1. Transclusions without template data [ 'name' => 'Transclusions without template data', @@ -59,6 +59,7 @@ private function defineTestData(): array { // 2. normal [ + 'name' => 'normal', 'html' => ' 'Inline Formatted template 1', 'html' => 'x 'Inline Formatted template 2', 'html' => 'x 'Inline Formatted template 3', 'html' => 'x 'Custom block formatting 1', 'html' => 'x 'Custom block formatting 2', 'html' => 'x 'Custom block formatting 3 - T199849', 'html' => "x\n" . ' 'Custom block formatting 4 - T199849', 'html' => "x\n" . ' 'Custom block formatting 5 - T199849', 'html' => "x\n" . ' 'Custom block formatting 6', 'html' => 'x $this->defaultContentVersion, 'html' => ' $test ) { - $html = $test['html']; - $name = 'Single Template Test ' . ( $key . 1 ); - if ( isset( $test['name'] ) ) { - $name .= ' (' . $test['name'] . ')'; - } - $name .= ': '; - - // Non-selser test - if ( isset( $test['wt']['no_selser'] ) ) { - $desc = $name . 'Default non-selser serialization should ignore templatedata'; - self::verifyTransformation( $html, null, null, $test['wt']['no_selser'], $desc ); - } - - // New content test - $desc = $name . 'Serialization of new content (no data-parsoid) should respect templatedata'; - // Remove data-parsoid making it look like new content - $newHTML = preg_replace( '/data-parsoid.*? data-mw/', ' data-mw', $html ); - self::verifyTransformation( $newHTML, '', '', $test['wt']['new_content'], $desc ); - - // Transclusion edit test - $desc = $name . 'Serialization of edited content should respect templatedata'; - // Replace only the first instance of 'foo' with 'BAR' - // to simulate an edit of a transclusion. - $newHTML = preg_replace( '/foo/', 'BAR', $html, 1 ); - self::verifyTransformation( $newHTML, $html, $test['wt']['no_selser'] ?? '', - $test['wt']['edited'], $desc ); - } - - $tests = self::defineVersionTestData(); - - // forEach(function(test) { - foreach ( $tests as $test ) { - $desc = 'Serialization should use correct arg space defaults for data-parsoid version ' . - $test['contentVersion']; - // Replace only the first instance of 'foo' with 'BAR' - // to simulate an edit of a transclusion. - $newHTML = preg_replace( '/foo/', 'BAR', $test['html'], 1 ); - self::verifyTransformation( $newHTML, $test['html'], $test['wt']['orig'], $test['wt']['edited'], - $desc, $test['contentVersion'] ); - } + public function testTemplateDataVersion( + string $contentVersion, string $html, array $wt + ): void { + $desc = "Serialization should use correct arg space defaults for " . + "data-parsoid version $contentVersion"; + // Replace only the first instance of 'foo' with 'BAR' + // to simulate an edit of a transclusion. + $newHTML = preg_replace( '/foo/', 'BAR', $html, 1 ); + self::verifyTransformation( + $newHTML, $html, $wt['orig'], $wt['edited'], $desc, $contentVersion + ); } }