3 namespace Drupal\Tests\Component\Diff\Engine;
5 use Drupal\Component\Diff\Engine\DiffEngine;
6 use Drupal\Component\Diff\Engine\DiffOpAdd;
7 use Drupal\Component\Diff\Engine\DiffOpCopy;
8 use Drupal\Component\Diff\Engine\DiffOpChange;
9 use Drupal\Component\Diff\Engine\DiffOpDelete;
10 use PHPUnit\Framework\TestCase;
13 * Test DiffEngine class.
15 * @coversDefaultClass \Drupal\Component\Diff\Engine\DiffEngine
19 class DiffEngineTest extends TestCase {
23 * - Expected output in terms of return class. A list of class names
24 * expected to be returned by DiffEngine::diff().
25 * - An array of strings to change from.
26 * - An array of strings to change to.
28 public function provideTestDiff() {
30 'empty' => [[], [], []],
31 'add' => [[DiffOpAdd::class], [], ['a']],
32 'copy' => [[DiffOpCopy::class], ['a'], ['a']],
33 'change' => [[DiffOpChange::class], ['a'], ['b']],
34 'copy-and-change' => [
42 'copy-change-copy' => [
51 'copy-change-copy-add' => [
73 * Tests whether op classes returned by DiffEngine::diff() match expectations.
76 * @dataProvider provideTestDiff
78 public function testDiff($expected, $from, $to) {
79 $diff_engine = new DiffEngine();
80 $diff = $diff_engine->diff($from, $to);
81 // Make sure we have the same number of results as expected.
82 $this->assertCount(count($expected), $diff);
83 // Make sure the diff objects match our expectations.
84 foreach ($expected as $index => $op_class) {
85 $this->assertEquals($op_class, get_class($diff[$index]));