function DeleteMultipleFormTest::testTranslatableEntities
Same name in other branches
- 8.9.x core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php \Drupal\FunctionalTests\Entity\DeleteMultipleFormTest::testTranslatableEntities()
- 10 core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php \Drupal\FunctionalTests\Entity\DeleteMultipleFormTest::testTranslatableEntities()
- 11.x core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php \Drupal\FunctionalTests\Entity\DeleteMultipleFormTest::testTranslatableEntities()
Tests the delete form for translatable entities.
File
-
core/
tests/ Drupal/ FunctionalTests/ Entity/ DeleteMultipleFormTest.php, line 58
Class
- DeleteMultipleFormTest
- Tests the delete multiple confirmation form.
Namespace
Drupal\FunctionalTests\EntityCode
public function testTranslatableEntities() {
ConfigurableLanguage::create([
'id' => 'es',
])->save();
ConfigurableLanguage::create([
'id' => 'fr',
])->save();
$selection = [];
$entity1 = EntityTestMulRevPub::create([
'type' => 'default',
'name' => 'entity1',
]);
$entity1->addTranslation('es', [
'name' => 'entity1 spanish',
]);
$entity1->addTranslation('fr', [
'name' => 'entity1 french',
]);
$entity1->save();
$selection[$entity1->id()]['en'] = 'en';
$entity2 = EntityTestMulRevPub::create([
'type' => 'default',
'name' => 'entity2',
]);
$entity2->addTranslation('es', [
'name' => 'entity2 spanish',
]);
$entity2->addTranslation('fr', [
'name' => 'entity2 french',
]);
$entity2->save();
$selection[$entity2->id()]['es'] = 'es';
$selection[$entity2->id()]['fr'] = 'fr';
$entity3 = EntityTestMulRevPub::create([
'type' => 'default',
'name' => 'entity3',
]);
$entity3->addTranslation('es', [
'name' => 'entity3 spanish',
]);
$entity3->addTranslation('fr', [
'name' => 'entity3 french',
]);
$entity3->save();
$selection[$entity3->id()]['fr'] = 'fr';
// This entity will be inaccessible because of
// Drupal\entity_test\EntityTestAccessControlHandler.
$entity4 = EntityTestMulRevPub::create([
'type' => 'default',
'name' => 'forbid_access',
]);
$entity4->save();
$selection[$entity4->id()]['en'] = 'en';
// Add the selection to the tempstore just like DeleteAction would.
$tempstore = \Drupal::service('tempstore.private')->get('entity_delete_multiple_confirm');
$tempstore->set($this->account
->id() . ':entity_test_mulrevpub', $selection);
$this->drupalGet('/entity_test/delete');
$assert = $this->assertSession();
$assert->statusCodeEquals(200);
$assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these test entity - revisions, data table, and published interface entities?');
$list_selector = '#entity-test-mulrevpub-delete-multiple-confirm-form > div.item-list > ul';
$assert->elementTextContains('css', $list_selector, 'entity1 (Original translation) - The following test entity - revisions, data table, and published interface translations will be deleted:');
$assert->elementTextContains('css', $list_selector, 'entity2 spanish');
$assert->elementTextContains('css', $list_selector, 'entity2 french');
$assert->elementTextNotContains('css', $list_selector, 'entity3 spanish');
$assert->elementTextContains('css', $list_selector, 'entity3 french');
$delete_button = $this->getSession()
->getPage()
->findButton('Delete');
$delete_button->click();
$assert = $this->assertSession();
$assert->addressEquals('/user/' . $this->account
->id());
$assert->responseContains('Deleted 6 items.');
$assert->responseContains('1 item has not been deleted because you do not have the necessary permissions.');
\Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')
->resetCache();
$remaining_entities = EntityTestMulRevPub::loadMultiple([
$entity1->id(),
$entity2->id(),
$entity3->id(),
$entity4->id(),
]);
$this->assertCount(3, $remaining_entities);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.