View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekBulkDeleteTest extends LingotekTestBase {
use TaxonomyTestTrait;
public static $modules = [
'taxonomy',
'block',
'node',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'header',
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
}
public function testNodeBulkDelete() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$edit['title[0][value]'] = 'Llamas are cool 2';
$edit['body[0][value]'] = 'Llamas are very cool 2';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$edit['title[0][value]'] = 'Llamas should stay';
$edit['body[0][value]'] = 'Llamas should stay';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$delete_option = $this
->xpath('//*[@id="edit-operation"]/option[text()="Delete content"]');
$this
->assertIdentical(1, count($delete_option), 'Delete operation must be available');
$assert_session
->linkExists('Llamas are cool 2');
$assert_session
->linkExists('Llamas are cool');
$assert_session
->linkExists('Llamas should stay');
$edit = [
'table[1]' => TRUE,
'table[2]' => TRUE,
'table[3]' => FALSE,
$this
->getBulkOperationFormName() => 'delete_nodes',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText(t('Are you sure you want to delete these content items?'));
$this
->assertText('Llamas are cool');
$this
->assertText('Llamas are cool 2');
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertText('Deleted 2 content items.');
$assert_session
->linkNotExists('Llamas are cool 2');
$assert_session
->linkNotExists('Llamas are cool');
$assert_session
->linkExists('Llamas should stay');
$this
->assertUrl('admin/lingotek/manage/node');
}
public function testTaxonomyTermBulkDelete() {
$assert_session = $this
->assertSession();
$vocabulary = $this
->createVocabulary();
ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary
->id())
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('taxonomy_term', $vocabulary
->id(), TRUE);
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$bundle = $vocabulary
->id();
$edit = [
"taxonomy_term[{$bundle}][enabled]" => 1,
"taxonomy_term[{$bundle}][profiles]" => 'automatic',
"taxonomy_term[{$bundle}][fields][name]" => 1,
"taxonomy_term[{$bundle}][fields][description]" => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], 'lingoteksettings-tab-content-form');
$this
->goToContentBulkManagementForm('taxonomy_term');
$delete_option = $this
->xpath('//*[@id="edit-operation"]/option[text()="Delete content"]');
$this
->assertIdentical(0, count($delete_option), 'Delete operation should not be available');
}
}