View source
<?php
namespace Drupal\lingotek\Tests\Form;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\LingotekConfigurationServiceInterface;
use Drupal\lingotek\Tests\LingotekTestBase;
class LingotekConfigBulkFormTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'field_ui',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
\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[article][enabled]' => 1,
'node[article][profiles]' => 'automatic',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
'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');
}
public function testConfigFilter() {
$this
->goToConfigBulkManagementForm();
$second_header = (string) $this
->xpath('//*[@id="edit-table"]/thead/tr/th[2]')[0];
$this
->assertEqual($second_header, 'Entity', 'There is a Entity header.');
}
public function testFieldConfigFilter() {
$this
->goToConfigBulkManagementForm();
$edit = [
'filters[wrapper][bundle]' => 'node_fields',
];
$this
->drupalPostForm(NULL, $edit, t('Filter'));
$second_header = (string) $this
->xpath('//*[@id="edit-table"]/thead/tr/th[2]')[0];
$this
->assertEqual($second_header, 'Bundle', 'There is a Bundle header.');
$third_header = (string) $this
->xpath('//*[@id="edit-table"]/thead/tr/th[3]')[0];
$this
->assertEqual($third_header, 'Entity', 'There is a Entity header.');
$this
->assertUniqueText('Article');
$this
->assertUniqueText('Page');
$this
->assertText('Body');
$this
->assertNoUniqueText('Body');
}
public function testDisabledLanguage() {
$this
->goToConfigBulkManagementForm('node_type');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$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/config/check_upload/node_type/article?destination=' . $basepath . '/admin/lingotek/config/manage');
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$lingotekConfig = \Drupal::service('lingotek.configuration');
$language = ConfigurableLanguage::load('es');
$lingotekConfig
->disableLanguage($language);
$this
->goToConfigBulkManagementForm();
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
$lingotekConfig
->enableLanguage($language);
$this
->goToConfigBulkManagementForm();
$this
->assertLinkByHref($basepath . '/admin/lingotek/config/request/node_type/article/es_MX?destination=' . $basepath . '/admin/lingotek/config/manage');
}
}