/**
  * Test enhanced entity revision routes access.
  */
 public function testRevisionRouteAccess()
 {
     $entity = EnhancedEntity::create(['name' => 'rev 1', 'type' => 'default']);
     $entity->save();
     $revision = clone $entity;
     $revision->name->value = 'rev 2';
     $revision->setNewRevision(TRUE);
     $revision->isDefaultRevision(FALSE);
     $revision->save();
     $this->drupalGet('/entity_test_enhanced/1/revisions');
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->responseContains('Revisions');
     $collection_link = $this->getSession()->getPage()->findLink('Entity test with enhancements');
     $collection_link->click();
     $this->assertSession()->addressEquals('/entity_test_enhanced');
     $this->assertSession()->responseContains('Edit');
     $edit_link = $this->getSession()->getPage()->findLink('Edit');
     $edit_link->click();
     $this->assertSession()->addressEquals('/entity_test_enhanced/1/edit');
     // Check if we have revision tab link on edit page.
     $this->getSession()->getPage()->findLink('Revisions')->click();
     $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
     $this->drupalGet('/entity_test_enhanced/1/revisions/2/view');
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->responseContains('rev 2');
     $revisions_link = $this->getSession()->getPage()->findLink('Revisions');
     $revisions_link->click();
     $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
     $this->assertSession()->statusCodeEquals(200);
 }
Exemplo n.º 2
0
 public function testRevisionView()
 {
     $entity = EnhancedEntity::create(['name' => 'rev 1', 'type' => 'default']);
     $entity->save();
     $revision = clone $entity;
     $revision->name->value = 'rev 2';
     $revision->setNewRevision(TRUE);
     $revision->isDefaultRevision(FALSE);
     $revision->save();
     /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
     $http_kernel = \Drupal::service('http_kernel');
     $request = Request::create($revision->url('revision'));
     $response = $http_kernel->handle($request);
     $this->assertEquals(403, $response->getStatusCode());
     $role = Role::create(['id' => 'test_role']);
     $role->grantPermission('view all entity_test_enhanced revisions');
     $role->grantPermission('administer entity_test_enhanced');
     $role->save();
     $user = User::create(['name' => 'Test user']);
     $user->addRole($role->id());
     \Drupal::service('account_switcher')->switchTo($user);
     $request = Request::create($revision->url('revision'));
     $response = $http_kernel->handle($request);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertNotContains('rev 1', $response->getContent());
     $this->assertContains('rev 2', $response->getContent());
 }
 /**
  * Tests the add page.
  */
 public function testForm()
 {
     $entities = [];
     $selection = [];
     for ($i = 0; $i < 2; $i++) {
         $entity = EnhancedEntity::create(['type' => 'default']);
         $entity->save();
         $entities[$entity->id()] = $entity;
         $langcode = $entity->language()->getId();
         $selection[$entity->id()][$langcode] = $langcode;
     }
     // Add the selection to the tempstore just like DeleteAction would.
     $tempstore = \Drupal::service('user.private_tempstore')->get('entity_delete_multiple_confirm');
     $tempstore->set($this->account->id(), $selection);
     $this->drupalGet('/entity_test_enhanced/delete');
     $assert = $this->assertSession();
     $assert->statusCodeEquals(200);
     $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these items?');
     $delete_button = $this->getSession()->getPage()->findButton('Delete');
     $delete_button->click();
     $assert = $this->assertSession();
     $assert->addressEquals('/entity_test_enhanced');
     $assert->responseContains('Deleted 2 items.');
     \Drupal::entityTypeManager()->getStorage('entity_test_enhanced')->resetCache();
     $remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
     $this->assertEmpty($remaining_entities);
 }
Exemplo n.º 4
0
 public function testAction()
 {
     /** @var \Drupal\system\ActionConfigEntityInterface $action */
     $action = Action::create(['id' => 'enhanced_entity_delete_action', 'label' => 'Delete enhanced entity', 'plugin' => 'entity_delete_action:entity_test_enhanced']);
     $status = $action->save();
     $this->assertEquals(SAVED_NEW, $status);
     $this->assertInstanceOf(DeleteAction::class, $action->getPlugin());
     $entities = [];
     for ($i = 0; $i < 2; $i++) {
         $entity = EnhancedEntity::create(['type' => 'default']);
         $entity->save();
         $entities[$entity->id()] = $entity;
     }
     $action->execute($entities);
     // Confirm that the entity ids and langcodes are now in the tempstore.
     $tempstore = \Drupal::service('user.private_tempstore')->get('entity_delete_multiple_confirm');
     $selection = $tempstore->get($this->user->id());
     $this->assertEquals(array_keys($entities), array_keys($selection));
     $this->assertEquals([['en' => 'en'], ['en' => 'en']], array_values($selection));
 }
 public function testEntityRevisionLog()
 {
     $user = User::create(['name' => 'user']);
     $user->save();
     $user2 = User::create(['name' => 'user2']);
     $user2->save();
     /** @var \Drupal\entity\Revision\EntityRevisionLogInterface $entity */
     $entity = EnhancedEntity::create(['type' => 'default', 'revision_user' => $user->id(), 'revision_created' => 1447941735, 'revision_log_message' => 'Test message']);
     $this->assertEquals(1447941735, $entity->getRevisionCreationTime());
     $this->assertEquals($user->id(), $entity->getRevisionUser()->id());
     $this->assertEquals('Test message', $entity->getRevisionLogMessage());
     $entity->setRevisionCreationTime(1234567890);
     $this->assertEquals(1234567890, $entity->getRevisionCreationTime());
     $entity->setRevisionUser($user2);
     $this->assertEquals($user2->id(), $entity->getRevisionUser()->id());
     $this->assertEquals($user2->id(), $entity->getRevisionUserId());
     $entity->setRevisionUserId($user->id());
     $this->assertEquals($user->id(), $entity->getRevisionUserId());
     $entity->setRevisionLogMessage('Giraffe!');
     $this->assertEquals('Giraffe!', $entity->getRevisionLogMessage());
 }