View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
class LingotekNodeBulkProfileTest 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 testChangeTranslationProfileBulk() {
$this
->drupalLogin($this->rootUser);
$nodes = [];
for ($i = 1; $i < 4; $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();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/2?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/3?destination=' . $basepath . '/admin/lingotek/manage/node');
$edit = [
'table[1]' => TRUE,
'table[2]' => TRUE,
'table[3]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$edit = [
'table[1]' => TRUE,
'table[2]' => TRUE,
'table[3]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$manual_profile = $this
->xpath("//td[contains(text(), 'Manual')]");
$this
->assertEqual(count($manual_profile), 3, 'There are three nodes with the Manual Profile set.');
$edit = [
'table[1]' => TRUE,
'table[2]' => TRUE,
'table[3]' => TRUE,
'operation' => 'change_profile:automatic',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$automatic_profile = $this
->xpath("//td[contains(text(), 'Automatic')]");
$this
->assertEqual(count($automatic_profile), 3, 'There are three nodes with the Automatic Profile set.');
$edit = [
'table[2]' => TRUE,
'operation' => 'change_profile:manual',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$manual_profile = $this
->xpath("//td[contains(text(), 'Manual')]");
$this
->assertEqual(count($manual_profile), 1, 'There is one node with the Manual Profile set.');
$automatic_profile = $this
->xpath("//td[contains(text(), 'Automatic')]");
$this
->assertEqual(count($automatic_profile), 2, 'There are two nodes with the Automatic Profile set.');
$edit = [
'table[1]' => TRUE,
'table[2]' => TRUE,
'table[3]' => TRUE,
'operation' => 'change_profile:disabled',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$disabled_profile = $this
->xpath("//td[contains(text(), 'Disabled')]");
$this
->assertEqual(count($disabled_profile), 3, 'There are three nodes with the Disabled Profile set.');
}
}