More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Diff / DiffFormatterTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Diff;
4
5 use Drupal\Component\Diff\Diff;
6 use Drupal\Component\Diff\DiffFormatter;
7 use PHPUnit\Framework\TestCase;
8
9 /**
10  * Test DiffFormatter classes.
11  *
12  * @coversDefaultClass \Drupal\Component\Diff\DiffFormatter
13  *
14  * @group Diff
15  */
16 class DiffFormatterTest extends TestCase {
17
18   /**
19    * @return array
20    *   - Expected formatted diff output.
21    *   - First array of text to diff.
22    *   - Second array of text to diff.
23    */
24   public function provideTestDiff() {
25     return [
26       'empty' => ['', [], []],
27       'add' => [
28         "3a3\n> line2a\n",
29         ['line1', 'line2', 'line3'],
30         ['line1', 'line2', 'line2a', 'line3'],
31       ],
32       'delete' => [
33         "3d3\n< line2a\n",
34         ['line1', 'line2', 'line2a', 'line3'],
35         ['line1', 'line2', 'line3'],
36       ],
37       'change' => [
38         "3c3\n< line2a\n---\n> line2b\n",
39         ['line1', 'line2', 'line2a', 'line3'],
40         ['line1', 'line2', 'line2b', 'line3'],
41       ],
42     ];
43   }
44
45   /**
46    * Tests whether op classes returned by DiffEngine::diff() match expectations.
47    *
48    * @covers ::format
49    * @dataProvider provideTestDiff
50    */
51   public function testDiff($expected, $from, $to) {
52     $diff = new Diff($from, $to);
53     $formatter = new DiffFormatter();
54     $output = $formatter->format($diff);
55     $this->assertEquals($expected, $output);
56   }
57
58 }