public function LingotekNodeBulkFormTest::testBundleFilter in Lingotek Translation 3.3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 4.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.0.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.1.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.2.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.4.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.5.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.6.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.7.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
- 3.8.x tests/src/Functional/Form/LingotekNodeBulkFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekNodeBulkFormTest::testBundleFilter()
Tests that the bulk management bundle filtering works correctly.
File
- tests/
src/ Functional/ Form/ LingotekNodeBulkFormTest.php, line 501
Class
- LingotekNodeBulkFormTest
- Tests the bulk management form.
Namespace
Drupal\Tests\lingotek\Functional\FormCode
public function testBundleFilter() {
$assert_session = $this
->assertSession();
// Create Page node types.
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
// Enable translation for the current entity type and ensure the change is
// picked up.
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'page', TRUE);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'custom_type')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'custom_type', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'page',
]);
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'custom_type',
]);
$nodes = [];
// Create a node.
for ($i = 1; $i < 15; $i++) {
$bundle = 'page';
if ($i % 2 == 0) {
$bundle = 'custom_type';
}
if ($i % 3 == 0) {
$bundle = 'article';
}
$edit = [];
$edit['title[0][value]'] = new FormattableMarkup('Llamas are cool @bundle @i', [
'@bundle' => $bundle,
'@i' => $i,
]);
$edit['body[0][value]'] = $edit['title[0][value]'];
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit, $bundle);
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
// Assert there is a pager.
$assert_session
->linkByHrefExists('?page=1');
// After we filter by article, there is no pager and the rows selected are
// the ones expected.
$edit = [
'filters[wrapper][bundle][]' => 'page',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
1,
5,
7,
11,
13,
] as $j) {
$assert_session
->linkExists('Llamas are cool page ' . $j);
}
$assert_session
->linkByHrefNotExists('?page=1');
$assert_session
->linkNotExists('Llamas are cool article 3');
$this
->assertFieldByName('filters[wrapper][bundle][]', 'page', 'The value is retained in the filter.');
// After we filter by custom_type, there is no pager and the rows selected are
// the ones expected.
$edit = [
'filters[wrapper][bundle][]' => 'custom_type',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
2,
4,
8,
10,
14,
] as $j) {
$assert_session
->linkExists('Llamas are cool custom_type ' . $j);
}
$assert_session
->linkByHrefNotExists('?page=1');
$assert_session
->linkNotExists('Llamas are cool article 3');
$assert_session
->linkNotExists('Llamas are cool page 1');
$this
->assertFieldByName('filters[wrapper][bundle][]', 'custom_type', 'The value is retained in the filter.');
// After we filter by article, there is no pager and the rows selected are the
// ones expected.
$edit = [
'filters[wrapper][bundle][]' => 'article',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
3,
6,
9,
12,
] as $j) {
$assert_session
->linkExists('Llamas are cool article ' . $j);
}
$assert_session
->linkNotExists('Page 2');
$assert_session
->linkNotExists('Llamas are cool page 1');
$this
->assertFieldByName('filters[wrapper][bundle][]', 'article', 'The value is retained in the filter.');
// After we filter by both page and article, there is no pager and the rows
// selected are the ones expected.
$edit = [];
$edit['filters[wrapper][bundle][]'] = [
'page',
'article',
];
$this
->drupalPostForm(NULL, $edit, 'edit-filters-actions-submit');
foreach ([
1,
5,
7,
] as $j) {
$assert_session
->linkExists('Llamas are cool page ' . $j);
}
foreach ([
3,
9,
] as $j) {
$assert_session
->linkExists('Llamas are cool article ' . $j);
}
// After we reset, we get back to having a pager and all the content.
$this
->drupalPostForm(NULL, [], 'Reset');
foreach ([
1,
5,
7,
] as $j) {
$assert_session
->linkExists('Llamas are cool page ' . $j);
}
foreach ([
2,
4,
8,
10,
] as $j) {
$assert_session
->linkExists('Llamas are cool custom_type ' . $j);
}
foreach ([
3,
6,
9,
] as $j) {
$assert_session
->linkExists('Llamas are cool article ' . $j);
}
$assert_session
->linkByHrefExists('?page=1');
}