View source
<?php
namespace Drupal\lingotek\Tests\Form;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\LingotekConfigurationServiceInterface;
use Drupal\lingotek\Tests\LingotekTestBase;
class LingotekNodeBulkFormTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected $node;
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'node[article][enabled]' => 1,
'node[article][profiles]' => 'automatic',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
}
public function testBulkPager() {
$this
->drupalLogin($this->rootUser);
$nodes = [];
for ($i = 1; $i < 15; $i++) {
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool ' . $i;
$edit['body[0][value]'] = 'Llamas are very cool ' . $i;
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
$this
->clickLink(t('Page 2'));
$this
->assertUrl('admin/lingotek/manage/node?page=1');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/11?destination=' . $basepath . '/admin/lingotek/manage/node');
$edit = [
'table[11]' => TRUE,
'table[12]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertUrl('admin/lingotek/manage/node?page=1');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool 11 is complete.');
$this
->assertUrl('admin/lingotek/manage/node?page=1');
}
public function testProfileFilter() {
$nodes = [];
for ($i = 1; $i < 15; $i++) {
$profile = 'automatic';
if ($i % 2 == 0) {
$profile = 'manual';
}
elseif ($i % 3 == 0) {
$profile = 'disabled';
}
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool ' . $i;
$edit['body[0][value]'] = 'Llamas are very cool ' . $i;
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = $profile;
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
$this
->assertLinkByHref('?page=1');
$edit = [
'filters[wrapper][profile]' => 'automatic',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
1,
5,
7,
11,
13,
] as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Llamas are cool 2');
$edit = [
'filters[wrapper][profile]' => 'manual',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
2,
4,
6,
8,
10,
12,
14,
] as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
$this
->assertNoLink('Page 2');
$this
->assertNoLink('Llamas are cool 1');
$edit = [
'filters[wrapper][profile]' => 'disabled',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
3,
9,
] as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Llamas are cool 5');
$this
->drupalPostForm(NULL, [], 'Reset');
foreach (range(1, 10) as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
$this
->assertLinkByHref('?page=1');
}
public function testLabelFilter() {
$nodes = [];
for ($i = 1; $i < 15; $i++) {
$animal = 'Llamas';
if ($i % 2 == 0) {
$animal = 'Dogs';
}
elseif ($i % 3 == 0) {
$animal = 'Cats';
}
$edit = array();
$edit['title[0][value]'] = $animal . ' are cool ' . $i;
$edit['body[0][value]'] = $animal . ' are very cool ' . $i;
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
$this
->assertLinkByHref('?page=1');
$edit = [
'filters[wrapper][label]' => 'Llamas',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
1,
5,
7,
11,
13,
] as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Dogs are cool 2');
$edit = [
'filters[wrapper][label]' => 'Dogs',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
2,
4,
6,
8,
10,
12,
14,
] as $j) {
$this
->assertLink('Dogs are cool ' . $j);
}
$this
->assertNoLink('Page 2');
$this
->assertNoLink('Llamas are cool 1');
$edit = [
'filters[wrapper][label]' => 'Cats',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
3,
9,
] as $j) {
$this
->assertLink('Cats are cool ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Dogs are cool 5');
$this
->drupalPostForm(NULL, [], 'Reset');
foreach ([
1,
5,
7,
] as $j) {
$this
->assertLink('Llamas are cool ' . $j);
}
foreach ([
2,
4,
6,
8,
10,
] as $j) {
$this
->assertLink('Dogs are cool ' . $j);
}
foreach ([
3,
9,
] as $j) {
$this
->assertLink('Cats are cool ' . $j);
}
$this
->assertLinkByHref('?page=1');
}
public function testLanguageFilter() {
ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT')
->save();
$nodes = [];
for ($i = 1; $i < 15; $i++) {
$langcode = 'es';
if ($i % 2 == 0) {
$langcode = 'it';
}
elseif ($i % 3 == 0) {
$langcode = 'en';
}
$edit = [];
$edit['title[0][value]'] = new FormattableMarkup('Llamas are cool @langcode @i', [
'@langcode' => strtoupper($langcode),
'@i' => $i,
]);
$edit['body[0][value]'] = $edit['title[0][value]'];
$edit['langcode[0][value]'] = $langcode;
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
$this
->assertLinkByHref('?page=1');
$edit = [
'filters[wrapper][source_language]' => 'es',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
1,
5,
7,
11,
13,
] as $j) {
$this
->assertLink('Llamas are cool ES ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Llamas are cool IT 2');
$edit = [
'filters[wrapper][source_language]' => 'it',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
2,
4,
6,
8,
10,
12,
14,
] as $j) {
$this
->assertLink('Llamas are cool IT ' . $j);
}
$this
->assertNoLink('Page 2');
$this
->assertNoLink('Llamas are cool ES 1');
$edit = [
'filters[wrapper][source_language]' => 'en',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
3,
9,
] as $j) {
$this
->assertLink('Llamas are cool EN ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Llamas are cool ES 5');
$this
->drupalPostForm(NULL, [], 'Reset');
foreach ([
1,
5,
7,
] as $j) {
$this
->assertLink('Llamas are cool ES ' . $j);
}
foreach ([
2,
4,
6,
8,
10,
] as $j) {
$this
->assertLink('Llamas are cool IT ' . $j);
}
foreach ([
3,
9,
] as $j) {
$this
->assertLink('Llamas are cool EN ' . $j);
}
$this
->assertLinkByHref('?page=1');
}
public function testBundleFilter() {
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'page', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'node[page][enabled]' => 1,
'node[page][profiles]' => 'automatic',
'node[page][fields][title]' => 1,
'node[page][fields][body]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
$nodes = [];
for ($i = 1; $i < 15; $i++) {
$bundle = 'page';
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_profile'] = 'manual';
$this
->drupalPostForm("node/add/{$bundle}", $edit, t('Save and publish'));
$nodes[$i] = $edit;
}
$this
->goToContentBulkManagementForm();
$this
->assertLinkByHref('?page=1');
$edit = [
'filters[wrapper][bundle]' => 'page',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
1,
2,
4,
5,
7,
8,
10,
11,
13,
14,
] as $j) {
$this
->assertLink('Llamas are cool page ' . $j);
}
$this
->assertNoLinkByHref('?page=1');
$this
->assertNoLink('Llamas are cool article 3');
$edit = [
'filters[wrapper][bundle]' => 'article',
];
$this
->drupalPostForm(NULL, $edit, 'Filter');
foreach ([
3,
6,
9,
12,
] as $j) {
$this
->assertLink('Llamas are cool article ' . $j);
}
$this
->assertNoLink('Page 2');
$this
->assertNoLink('Llamas are cool page 1');
$this
->drupalPostForm(NULL, [], 'Reset');
foreach ([
1,
2,
4,
5,
7,
8,
10,
] as $j) {
$this
->assertLink('Llamas are cool page ' . $j);
}
foreach ([
3,
6,
9,
] as $j) {
$this
->assertLink('Llamas are cool article ' . $j);
}
$this
->assertLinkByHref('?page=1');
}
public function testDisabledLanguage() {
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$request = $this
->curlExec(array(
CURLOPT_URL => \Drupal::url('lingotek.dashboard_endpoint', array(), array(
'absolute' => TRUE,
)),
CURLOPT_HTTPGET => FALSE,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_POSTFIELDS => $this
->serializePostValues([
'code' => 'es_MX',
]),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
));
$response = json_decode($request, TRUE);
$this
->verbose(var_export($response, TRUE));
$this
->goToContentBulkManagementForm();
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$lingotekConfig = \Drupal::service('lingotek.configuration');
$language = ConfigurableLanguage::load('es');
$lingotekConfig
->enableLanguage($language);
$this
->goToContentBulkManagementForm();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
}
}