70fb0dcf155a4266f502dac84234f1e2aca4bdcc
[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
8 /**
9  * Test DiffFormatter classes.
10  *
11  * @coversDefaultClass \Drupal\Component\Diff\DiffFormatter
12  *
13  * @group Diff
14  */
15 class DiffFormatterTest extends \PHPUnit_Framework_TestCase {
16
17   /**
18    * @return array
19    *   - Expected formatted diff output.
20    *   - First array of text to diff.
21    *   - Second array of text to diff.
22    */
23   public function provideTestDiff() {
24     return [
25       'empty' => ['', [], []],
26       'add' => [
27         "3a3\n> line2a\n",
28         ['line1', 'line2', 'line3'],
29         ['line1', 'line2', 'line2a', 'line3'],
30       ],
31       'delete' => [
32         "3d3\n< line2a\n",
33         ['line1', 'line2', 'line2a', 'line3'],
34         ['line1', 'line2', 'line3'],
35       ],
36       'change' => [
37         "3c3\n< line2a\n---\n> line2b\n",
38         ['line1', 'line2', 'line2a', 'line3'],
39         ['line1', 'line2', 'line2b', 'line3'],
40       ],
41     ];
42   }
43
44   /**
45    * Tests whether op classes returned by DiffEngine::diff() match expectations.
46    *
47    * @covers ::format
48    * @dataProvider provideTestDiff
49    */
50   public function testDiff($expected, $from, $to) {
51     $diff = new Diff($from, $to);
52     $formatter = new DiffFormatter();
53     $output = $formatter->format($diff);
54     $this->assertEquals($expected, $output);
55   }
56
57 }