View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekToolbarIntegrationTest extends LingotekTestBase {
protected $defaultTheme = 'classy';
public static $modules = [
'lingotek',
'lingotek_test',
'node',
'toolbar',
'block',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
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 testToolbarItems() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkExists('Translation');
$this
->clickLink('Configuration');
$result = $this
->xpath('//h3[text()="Regional and language"]/following-sibling::*//a[@href="' . $basepath . '/admin/lingotek"]/text()');
$this
->assertEqual(1, count($result), 'There is a link in Regional Language to the dashboard.');
$this
->clickLink('Lingotek Translation');
$result = $this
->xpath('//nav[contains(@class,"tabs")]/ul[contains(@class,"primary")]/li[contains(@class,"is-active")]/a[@href="' . $basepath . '/admin/lingotek"]/text()');
$this
->assertEqual(1, count($result), 'There is an active tab for the Dashboard.');
$result = $this
->xpath('//nav[contains(@class,"tabs")]/ul[contains(@class,"primary")]/li/a[@href="' . $basepath . '/admin/lingotek/manage"]/text()');
$this
->assertEqual(1, count($result), 'There is a tab for Content Bulk management.');
$result = $this
->xpath('//nav[contains(@class,"tabs")]/ul[contains(@class,"primary")]/li/a[@href="' . $basepath . '/admin/lingotek/config/manage"]/text()');
$this
->assertEqual(1, count($result), 'There is a tab for Config Bulk management.');
$result = $this
->xpath('//nav[contains(@class,"tabs")]/ul[contains(@class,"primary")]/li/a[@href="' . $basepath . '/admin/lingotek/settings"]/text()');
$this
->assertEqual(1, count($result), 'There is a tab for Settings.');
$settings = $this
->getDrupalSettings();
$response = $this
->drupalGet('/toolbar/subtrees/' . $settings['toolbar']['subtreesHash']);
$this
->assertSession()
->statusCodeEquals('200');
$response = json_decode($response, TRUE);
$this
->assertEqual($response[0]['command'], 'setToolbarSubtrees', 'Subtrees response uses the correct command.');
$this
->assertTrue(array_key_exists('lingotek-config-dashboard', $response[0]['subtrees']), 'There is a subtree for Lingotek config.');
$html = $response[0]['subtrees']['lingotek-config-dashboard'];
$this
->assertTrue(FALSE !== strpos($html, '<a href="' . $basepath . '/admin/lingotek/manage" title="Manage content translations using Lingotek cloud-based localization" id="toolbar-link-lingotek-manage" class="toolbar-icon toolbar-icon-lingotek-manage" data-drupal-link-system-path="admin/lingotek/manage">Content</a>'), 'There is an expanded item for the Content bulk management.');
$this
->assertTrue(FALSE !== strpos($html, '<a href="' . $basepath . '/admin/lingotek/manage/node" id="toolbar-link-lingotek-manage-node" class="toolbar-icon toolbar-icon-lingotek-manage-content:lingotek-manage-node" title="" data-drupal-link-system-path="admin/lingotek/manage/node">Content</a>'), 'There is an item for the Nodes in Content bulk management.');
$this
->assertTrue(FALSE !== strpos($html, '<a href="' . $basepath . '/admin/lingotek/config/manage" title="Manage config translations using Lingotek cloud-based localization" id="toolbar-link-lingotek-manage_config" class="toolbar-icon toolbar-icon-lingotek-manage-config" data-drupal-link-system-path="admin/lingotek/config/manage">Config</a>'), 'There is an item for Config bulk management.');
$this
->assertTrue(FALSE !== strpos($html, '<a href="' . $basepath . '/admin/lingotek/settings" title="Lingotek configuration" id="toolbar-link-lingotek-settings" class="toolbar-icon toolbar-icon-lingotek-settings" data-drupal-link-system-path="admin/lingotek/settings">Settings</a>'), 'There is an item for Lingotek Settings.');
$html = $response[0]['subtrees']['system-admin_config'];
$this
->assertTrue(FALSE !== strpos($html, '<a href="' . $basepath . '/admin/lingotek" title="Convenient cloud-based localization and translation by Lingotek" id="toolbar-link-lingotek-dashboard" class="toolbar-icon toolbar-icon-lingotek-config-dashboard" data-drupal-link-system-path="admin/lingotek">Lingotek Translation</a>'), 'There is an item for Lingotek in the config area.');
}
}