3 namespace Drupal\Tests\diff\Kernel;
6 use Drupal\entity_test\Entity\EntityTestRev;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\user\Entity\Role;
9 use Drupal\user\Entity\User;
10 use Symfony\Component\HttpFoundation\Request;
13 * Tests the diff controller.
17 class DiffControllerTest extends KernelTestBase {
22 public static $modules = [
33 protected function setUp() {
36 $this->installEntitySchema('entity_test_rev');
37 $this->installEntitySchema('user');
38 $this->installSchema('system', ['router', 'sequences']);
39 $this->installSchema('user', 'users_data');
40 \Drupal::service('router.builder')->rebuild();
42 $this->installConfig('diff');
43 $config = \Drupal::configFactory()->getEditable('diff.settings');
44 $config->set('entity.entity_test_rev.name', TRUE);
49 * Tests the Controller.
51 public function testController() {
52 $entity = EntityTestRev::create([
53 'name' => 'test entity 1',
54 'type' => 'entity_test_rev',
57 $vid1 = $entity->getRevisionId();
59 $entity->name->value = 'test entity 2';
60 $entity->setNewRevision(TRUE);
62 $vi2 = $entity->getRevisionId();
64 /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
65 $http_kernel = \Drupal::service('http_kernel');
66 $request = Request::create(Url::fromRoute('entity.entity_test_rev.revisions_diff', [
67 'node' => $entity->id(),
68 'entity_test_rev' => $entity->id(),
69 'left_revision' => $vid1,
70 'right_revision' => $vi2,
71 ])->toString(TRUE)->getGeneratedUrl());
73 $response = $http_kernel->handle($request);
74 $this->assertEquals(403, $response->getStatusCode());
76 $role = Role::create([
79 $role->grantPermission('administer entity_test content');
81 $account = User::create([
82 'name' => 'test user',
83 'roles' => $role->id(),
87 \Drupal::currentUser()->setAccount($account);
88 $response = $http_kernel->handle($request);
89 $this->assertEquals(200, $response->getStatusCode());
91 $output = $response->getContent();
92 $this->assertContains('<td class="diff-context diff-deletedline">test entity <span class="diffchange">1</span></td>', $output);
93 $this->assertContains('<td class="diff-context diff-addedline">test entity <span class="diffchange">2</span></td>', $output);