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;
12 * Test DiffEngine class.
14 * @coversDefaultClass \Drupal\Component\Diff\Engine\DiffEngine
18 class DiffEngineTest extends \PHPUnit_Framework_TestCase {
22 * - Expected output in terms of return class. A list of class names
23 * expected to be returned by DiffEngine::diff().
24 * - An array of strings to change from.
25 * - An array of strings to change to.
27 public function provideTestDiff() {
29 'empty' => [[], [], []],
30 'add' => [[DiffOpAdd::class], [], ['a']],
31 'copy' => [[DiffOpCopy::class], ['a'], ['a']],
32 'change' => [[DiffOpChange::class], ['a'], ['b']],
33 'copy-and-change' => [
41 'copy-change-copy' => [
50 'copy-change-copy-add' => [
72 * Tests whether op classes returned by DiffEngine::diff() match expectations.
75 * @dataProvider provideTestDiff
77 public function testDiff($expected, $from, $to) {
78 $diff_engine = new DiffEngine();
79 $diff = $diff_engine->diff($from, $to);
80 // Make sure we have the same number of results as expected.
81 $this->assertCount(count($expected), $diff);
82 // Make sure the diff objects match our expectations.
83 foreach ($expected as $index => $op_class) {
84 $this->assertEquals($op_class, get_class($diff[$index]));