View source
<?php
namespace Drupal\config_translation\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
class ConfigTranslationListUiTest extends WebTestBase {
public static $modules = array(
'block',
'config_translation',
'contact',
'block_content',
'field',
'field_ui',
'menu_ui',
'node',
'shortcut',
'taxonomy',
'image',
'responsive_image',
'toolbar',
);
protected $adminUser;
protected function setUp() {
parent::setUp();
$permissions = array(
'access site-wide contact form',
'administer blocks',
'administer contact forms',
'administer content types',
'administer block_content fields',
'administer filters',
'administer menu',
'administer node fields',
'administer permissions',
'administer shortcuts',
'administer site configuration',
'administer taxonomy',
'administer account settings',
'administer languages',
'administer image styles',
'administer responsive images',
'translate configuration',
);
$this->adminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
$this
->config('locale.settings')
->set('translation.import_enabled', TRUE)
->save();
$this
->drupalPlaceBlock('local_tasks_block');
}
protected function doBlockListTest() {
$id = Unicode::strtolower($this
->randomMachineName(16));
$this
->drupalPlaceBlock('system_powered_by_block', array(
'id' => $id,
));
$this
->drupalGet('admin/structure/block');
$translate_link = 'admin/structure/block/manage/' . $id . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
protected function doMenuListTest() {
$this
->drupalGet('admin/structure/menu/add');
$menu_name = Unicode::strtolower($this
->randomMachineName(16));
$label = $this
->randomMachineName(16);
$edit = array(
'id' => $menu_name,
'description' => '',
'label' => $label,
);
$this
->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
$this
->drupalGet('admin/structure/menu');
$translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
$this
->assertLinkByHref($translate_link);
$permissions = array(
'administer menu',
);
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$this
->drupalGet('admin/structure/menu');
$translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
$this
->assertNoLinkByHref($translate_link);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
protected function doVocabularyListTest() {
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'vid' => Unicode::strtolower($this
->randomMachineName()),
));
$vocabulary
->save();
$this
->drupalGet('admin/structure/taxonomy');
$translate_link = 'admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doCustomContentTypeListTest() {
$block_content_type = entity_create('block_content_type', array(
'id' => Unicode::strtolower($this
->randomMachineName(16)),
'label' => $this
->randomMachineName(),
'revision' => FALSE,
));
$block_content_type
->save();
$this
->drupalGet('admin/structure/block/block-content/types');
$translate_link = 'admin/structure/block/block-content/manage/' . $block_content_type
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doContactFormsListTest() {
$contact_form = entity_create('contact_form', array(
'id' => Unicode::strtolower($this
->randomMachineName(16)),
'label' => $this
->randomMachineName(),
));
$contact_form
->save();
$this
->drupalGet('admin/structure/contact');
$translate_link = 'admin/structure/contact/manage/' . $contact_form
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doContentTypeListTest() {
$content_type = $this
->drupalCreateContentType(array(
'type' => Unicode::strtolower($this
->randomMachineName(16)),
'name' => $this
->randomMachineName(),
));
$this
->drupalGet('admin/structure/types');
$translate_link = 'admin/structure/types/manage/' . $content_type
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doFormatsListTest() {
$filter_format = entity_create('filter_format', array(
'format' => Unicode::strtolower($this
->randomMachineName(16)),
'name' => $this
->randomMachineName(),
));
$filter_format
->save();
$this
->drupalGet('admin/config/content/formats');
$translate_link = 'admin/config/content/formats/manage/' . $filter_format
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doShortcutListTest() {
$shortcut = entity_create('shortcut_set', array(
'id' => Unicode::strtolower($this
->randomMachineName(16)),
'label' => $this
->randomString(),
));
$shortcut
->save();
$this
->drupalGet('admin/config/user-interface/shortcut');
$translate_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut
->id() . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doUserRoleListTest() {
$role_id = Unicode::strtolower($this
->randomMachineName(16));
$this
->drupalCreateRole(array(), $role_id);
$this
->drupalGet('admin/people/roles');
$translate_link = 'admin/people/roles/manage/' . $role_id . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doLanguageListTest() {
ConfigurableLanguage::createFromLangcode('ga')
->save();
$this
->drupalGet('admin/config/regional/language');
$translate_link = 'admin/config/regional/language/edit/ga/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doImageStyleListTest() {
$this
->drupalGet('admin/config/media/image-styles');
$translate_link = 'admin/config/media/image-styles/manage/medium/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doResponsiveImageListTest() {
$edit = array();
$edit['label'] = $this
->randomMachineName();
$edit['id'] = strtolower($edit['label']);
$edit['fallback_image_style'] = 'thumbnail';
$this
->drupalPostForm('admin/config/media/responsive-image-style/add', $edit, t('Save'));
$this
->assertRaw(t('Responsive image style %label saved.', array(
'%label' => $edit['label'],
)));
$this
->drupalGet('admin/config/media/responsive-image-style');
$translate_link = 'admin/config/media/responsive-image-style/' . $edit['id'] . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doFieldListTest() {
$content_type = $this
->drupalCreateContentType(array(
'type' => Unicode::strtolower($this
->randomMachineName(16)),
'name' => $this
->randomMachineName(),
));
$block_content_type = entity_create('block_content_type', array(
'id' => 'basic',
'label' => 'Basic',
'revision' => FALSE,
));
$block_content_type
->save();
$field = entity_create('field_config', array(
'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
'bundle' => $block_content_type
->id(),
'label' => 'Body',
'settings' => array(
'display_summary' => FALSE,
),
));
$field
->save();
$pages = array(
array(
'list' => 'admin/structure/types/manage/' . $content_type
->id() . '/fields',
'field' => 'node.' . $content_type
->id() . '.body',
),
array(
'list' => 'admin/structure/block/block-content/manage/basic/fields',
'field' => 'block_content.basic.body',
),
);
foreach ($pages as $values) {
$this
->drupalGet($values['list']);
$translate_link = $values['list'] . '/' . $values['field'] . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
}
public function doDateFormatListTest() {
$this
->drupalGet('admin/config/regional/date-time');
$translate_link = 'admin/config/regional/date-time/formats/manage/long/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function doSettingsPageTest($link) {
$this
->drupalGet($link);
$translate_link = $link . '/translate';
$this
->assertLinkByHref($translate_link);
$this
->drupalGet($translate_link);
$this
->assertRaw('<th>' . t('Language') . '</th>');
}
public function testTranslateOperationInListUi() {
$this
->doBlockListTest();
$this
->doMenuListTest();
$this
->doVocabularyListTest();
$this
->doCustomContentTypeListTest();
$this
->doContactFormsListTest();
$this
->doContentTypeListTest();
$this
->doFormatsListTest();
$this
->doShortcutListTest();
$this
->doUserRoleListTest();
$this
->doLanguageListTest();
$this
->doImageStyleListTest();
$this
->doResponsiveImageListTest();
$this
->doDateFormatListTest();
$this
->doFieldListTest();
$this
->doSettingsPageTest('admin/config/development/maintenance');
$this
->doSettingsPageTest('admin/config/system/site-information');
$this
->doSettingsPageTest('admin/config/people/accounts');
$this
->doSettingsPageTest('admin/config/services/rss-publishing');
}
}