1. 8.2.x core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php
  2. 8.0.x core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php
  3. 8.1.x core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php
  4. 8.3.x core/modules/config_translation/tests/src/Functional/ConfigTranslationListUiTest.php

Namespace

Drupal\config_translation\Tests

File

core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php
View source
  1. <?php
  2. namespace Drupal\config_translation\Tests;
  3. use Drupal\block_content\Entity\BlockContentType;
  4. use Drupal\Component\Utility\Unicode;
  5. use Drupal\field\Entity\FieldConfig;
  6. use Drupal\field\Entity\FieldStorageConfig;
  7. use Drupal\language\Entity\ConfigurableLanguage;
  8. use Drupal\simpletest\WebTestBase;
  9. use Drupal\shortcut\Entity\ShortcutSet;
  10. use Drupal\contact\Entity\ContactForm;
  11. use Drupal\filter\Entity\FilterFormat;
  12. use Drupal\taxonomy\Entity\Vocabulary;
  13. /**
  14. * Visit all lists.
  15. *
  16. * @group config_translation
  17. * @see \Drupal\config_translation\Tests\ConfigTranslationViewListUiTest
  18. */
  19. class ConfigTranslationListUiTest extends WebTestBase {
  20. /**
  21. * Modules to enable.
  22. *
  23. * @var array
  24. */
  25. public static $modules = array(
  26. 'block',
  27. 'config_translation',
  28. 'contact',
  29. 'block_content',
  30. 'field',
  31. 'field_ui',
  32. 'menu_ui',
  33. 'node',
  34. 'shortcut',
  35. 'taxonomy',
  36. 'image',
  37. 'responsive_image',
  38. 'toolbar',
  39. );
  40. /**
  41. * Admin user with all needed permissions.
  42. *
  43. * @var \Drupal\user\Entity\User
  44. */
  45. protected $adminUser;
  46. protected function setUp() {
  47. parent::setUp();
  48. $permissions = array(
  49. 'access site-wide contact form',
  50. 'administer blocks',
  51. 'administer contact forms',
  52. 'administer content types',
  53. 'administer block_content fields',
  54. 'administer filters',
  55. 'administer menu',
  56. 'administer node fields',
  57. 'administer permissions',
  58. 'administer shortcuts',
  59. 'administer site configuration',
  60. 'administer taxonomy',
  61. 'administer account settings',
  62. 'administer languages',
  63. 'administer image styles',
  64. 'administer responsive images',
  65. 'translate configuration',
  66. );
  67. // Create and log in user.
  68. $this->adminUser = $this->drupalCreateUser($permissions);
  69. $this->drupalLogin($this->adminUser);
  70. // Enable import of translations. By default this is disabled for automated
  71. // tests.
  72. $this->config('locale.settings')
  73. ->set('translation.import_enabled', TRUE)
  74. ->save();
  75. $this->drupalPlaceBlock('local_tasks_block');
  76. }
  77. /**
  78. * Tests the block listing for the translate operation.
  79. *
  80. * There are no blocks placed in the testing profile. Add one, then check
  81. * for Translate operation.
  82. */
  83. protected function doBlockListTest() {
  84. // Add a test block, any block will do.
  85. // Set the machine name so the translate link can be built later.
  86. $id = Unicode::strtolower($this->randomMachineName(16));
  87. $this->drupalPlaceBlock('system_powered_by_block', array('id' => $id));
  88. // Get the Block listing.
  89. $this->drupalGet('admin/structure/block');
  90. $translate_link = 'admin/structure/block/manage/' . $id . '/translate';
  91. // Test if the link to translate the block is on the page.
  92. $this->assertLinkByHref($translate_link);
  93. // Test if the link to translate actually goes to the translate page.
  94. $this->drupalGet($translate_link);
  95. $this->assertRaw('<th>' . t('Language') . '</th>');
  96. }
  97. /**
  98. * Tests the menu listing for the translate operation.
  99. */
  100. protected function doMenuListTest() {
  101. // Create a test menu to decouple looking for translate operations link so
  102. // this does not test more than necessary.
  103. $this->drupalGet('admin/structure/menu/add');
  104. // Lowercase the machine name.
  105. $menu_name = Unicode::strtolower($this->randomMachineName(16));
  106. $label = $this->randomMachineName(16);
  107. $edit = array(
  108. 'id' => $menu_name,
  109. 'description' => '',
  110. 'label' => $label,
  111. );
  112. // Create the menu by posting the form.
  113. $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
  114. // Get the Menu listing.
  115. $this->drupalGet('admin/structure/menu');
  116. $translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
  117. // Test if the link to translate the menu is on the page.
  118. $this->assertLinkByHref($translate_link);
  119. // Check if the Link is not added if you are missing 'translate
  120. // configuration' permission.
  121. $permissions = array(
  122. 'administer menu',
  123. );
  124. $this->drupalLogin($this->drupalCreateUser($permissions));
  125. // Get the Menu listing.
  126. $this->drupalGet('admin/structure/menu');
  127. $translate_link = 'admin/structure/menu/manage/' . $menu_name . '/translate';
  128. // Test if the link to translate the menu is NOT on the page.
  129. $this->assertNoLinkByHref($translate_link);
  130. // Log in as Admin again otherwise the rest will fail.
  131. $this->drupalLogin($this->adminUser);
  132. // Test if the link to translate actually goes to the translate page.
  133. $this->drupalGet($translate_link);
  134. $this->assertRaw('<th>' . t('Language') . '</th>');
  135. }
  136. /**
  137. * Tests the vocabulary listing for the translate operation.
  138. */
  139. protected function doVocabularyListTest() {
  140. // Create a test vocabulary to decouple looking for translate operations
  141. // link so this does not test more than necessary.
  142. $vocabulary = Vocabulary::create([
  143. 'name' => $this->randomMachineName(),
  144. 'description' => $this->randomMachineName(),
  145. 'vid' => Unicode::strtolower($this->randomMachineName()),
  146. ]);
  147. $vocabulary->save();
  148. // Get the Taxonomy listing.
  149. $this->drupalGet('admin/structure/taxonomy');
  150. $translate_link = 'admin/structure/taxonomy/manage/' . $vocabulary->id() . '/translate';
  151. // Test if the link to translate the vocabulary is on the page.
  152. $this->assertLinkByHref($translate_link);
  153. // Test if the link to translate actually goes to the translate page.
  154. $this->drupalGet($translate_link);
  155. $this->assertRaw('<th>' . t('Language') . '</th>');
  156. }
  157. /**
  158. * Tests the custom block listing for the translate operation.
  159. */
  160. public function doCustomContentTypeListTest() {
  161. // Create a test custom block type to decouple looking for translate
  162. // operations link so this does not test more than necessary.
  163. $block_content_type = BlockContentType::create(array(
  164. 'id' => Unicode::strtolower($this->randomMachineName(16)),
  165. 'label' => $this->randomMachineName(),
  166. 'revision' => FALSE
  167. ));
  168. $block_content_type->save();
  169. // Get the custom block type listing.
  170. $this->drupalGet('admin/structure/block/block-content/types');
  171. $translate_link = 'admin/structure/block/block-content/manage/' . $block_content_type->id() . '/translate';
  172. // Test if the link to translate the custom block type is on the page.
  173. $this->assertLinkByHref($translate_link);
  174. // Test if the link to translate actually goes to the translate page.
  175. $this->drupalGet($translate_link);
  176. $this->assertRaw('<th>' . t('Language') . '</th>');
  177. }
  178. /**
  179. * Tests the contact forms listing for the translate operation.
  180. */
  181. public function doContactFormsListTest() {
  182. // Create a test contact form to decouple looking for translate operations
  183. // link so this does not test more than necessary.
  184. $contact_form = ContactForm::create([
  185. 'id' => Unicode::strtolower($this->randomMachineName(16)),
  186. 'label' => $this->randomMachineName(),
  187. ]);
  188. $contact_form->save();
  189. // Get the contact form listing.
  190. $this->drupalGet('admin/structure/contact');
  191. $translate_link = 'admin/structure/contact/manage/' . $contact_form->id() . '/translate';
  192. // Test if the link to translate the contact form is on the page.
  193. $this->assertLinkByHref($translate_link);
  194. // Test if the link to translate actually goes to the translate page.
  195. $this->drupalGet($translate_link);
  196. $this->assertRaw('<th>' . t('Language') . '</th>');
  197. }
  198. /**
  199. * Tests the content type listing for the translate operation.
  200. */
  201. public function doContentTypeListTest() {
  202. // Create a test content type to decouple looking for translate operations
  203. // link so this does not test more than necessary.
  204. $content_type = $this->drupalCreateContentType(array(
  205. 'type' => Unicode::strtolower($this->randomMachineName(16)),
  206. 'name' => $this->randomMachineName(),
  207. ));
  208. // Get the content type listing.
  209. $this->drupalGet('admin/structure/types');
  210. $translate_link = 'admin/structure/types/manage/' . $content_type->id() . '/translate';
  211. // Test if the link to translate the content type is on the page.
  212. $this->assertLinkByHref($translate_link);
  213. // Test if the link to translate actually goes to the translate page.
  214. $this->drupalGet($translate_link);
  215. $this->assertRaw('<th>' . t('Language') . '</th>');
  216. }
  217. /**
  218. * Tests the formats listing for the translate operation.
  219. */
  220. public function doFormatsListTest() {
  221. // Create a test format to decouple looking for translate operations
  222. // link so this does not test more than necessary.
  223. $filter_format = FilterFormat::create(array(
  224. 'format' => Unicode::strtolower($this->randomMachineName(16)),
  225. 'name' => $this->randomMachineName(),
  226. ));
  227. $filter_format->save();
  228. // Get the format listing.
  229. $this->drupalGet('admin/config/content/formats');
  230. $translate_link = 'admin/config/content/formats/manage/' . $filter_format->id() . '/translate';
  231. // Test if the link to translate the format is on the page.
  232. $this->assertLinkByHref($translate_link);
  233. // Test if the link to translate actually goes to the translate page.
  234. $this->drupalGet($translate_link);
  235. $this->assertRaw('<th>' . t('Language') . '</th>');
  236. }
  237. /**
  238. * Tests the shortcut listing for the translate operation.
  239. */
  240. public function doShortcutListTest() {
  241. // Create a test shortcut to decouple looking for translate operations
  242. // link so this does not test more than necessary.
  243. $shortcut = ShortcutSet::create(array(
  244. 'id' => Unicode::strtolower($this->randomMachineName(16)),
  245. 'label' => $this->randomString(),
  246. ));
  247. $shortcut->save();
  248. // Get the shortcut listing.
  249. $this->drupalGet('admin/config/user-interface/shortcut');
  250. $translate_link = 'admin/config/user-interface/shortcut/manage/' . $shortcut->id() . '/translate';
  251. // Test if the link to translate the shortcut is on the page.
  252. $this->assertLinkByHref($translate_link);
  253. // Test if the link to translate actually goes to the translate page.
  254. $this->drupalGet($translate_link);
  255. $this->assertRaw('<th>' . t('Language') . '</th>');
  256. }
  257. /**
  258. * Tests the role listing for the translate operation.
  259. */
  260. public function doUserRoleListTest() {
  261. // Create a test role to decouple looking for translate operations
  262. // link so this does not test more than necessary.
  263. $role_id = Unicode::strtolower($this->randomMachineName(16));
  264. $this->drupalCreateRole(array(), $role_id);
  265. // Get the role listing.
  266. $this->drupalGet('admin/people/roles');
  267. $translate_link = 'admin/people/roles/manage/' . $role_id . '/translate';
  268. // Test if the link to translate the role is on the page.
  269. $this->assertLinkByHref($translate_link);
  270. // Test if the link to translate actually goes to the translate page.
  271. $this->drupalGet($translate_link);
  272. $this->assertRaw('<th>' . t('Language') . '</th>');
  273. }
  274. /**
  275. * Tests the language listing for the translate operation.
  276. */
  277. public function doLanguageListTest() {
  278. // Create a test language to decouple looking for translate operations
  279. // link so this does not test more than necessary.
  280. ConfigurableLanguage::createFromLangcode('ga')->save();
  281. // Get the language listing.
  282. $this->drupalGet('admin/config/regional/language');
  283. $translate_link = 'admin/config/regional/language/edit/ga/translate';
  284. // Test if the link to translate the language is on the page.
  285. $this->assertLinkByHref($translate_link);
  286. // Test if the link to translate actually goes to the translate page.
  287. $this->drupalGet($translate_link);
  288. $this->assertRaw('<th>' . t('Language') . '</th>');
  289. }
  290. /**
  291. * Tests the image style listing for the translate operation.
  292. */
  293. public function doImageStyleListTest() {
  294. // Get the image style listing.
  295. $this->drupalGet('admin/config/media/image-styles');
  296. $translate_link = 'admin/config/media/image-styles/manage/medium/translate';
  297. // Test if the link to translate the style is on the page.
  298. $this->assertLinkByHref($translate_link);
  299. // Test if the link to translate actually goes to the translate page.
  300. $this->drupalGet($translate_link);
  301. $this->assertRaw('<th>' . t('Language') . '</th>');
  302. }
  303. /**
  304. * Tests the responsive image mapping listing for the translate operation.
  305. */
  306. public function doResponsiveImageListTest() {
  307. $edit = array();
  308. $edit['label'] = $this->randomMachineName();
  309. $edit['id'] = strtolower($edit['label']);
  310. $edit['fallback_image_style'] = 'thumbnail';
  311. $this->drupalPostForm('admin/config/media/responsive-image-style/add', $edit, t('Save'));
  312. $this->assertRaw(t('Responsive image style %label saved.', array('%label' => $edit['label'])));
  313. // Get the responsive image style listing.
  314. $this->drupalGet('admin/config/media/responsive-image-style');
  315. $translate_link = 'admin/config/media/responsive-image-style/' . $edit['id'] . '/translate';
  316. // Test if the link to translate the style is on the page.
  317. $this->assertLinkByHref($translate_link);
  318. // Test if the link to translate actually goes to the translate page.
  319. $this->drupalGet($translate_link);
  320. $this->assertRaw('<th>' . t('Language') . '</th>');
  321. }
  322. /**
  323. * Tests the field listing for the translate operation.
  324. */
  325. public function doFieldListTest() {
  326. // Create a base content type.
  327. $content_type = $this->drupalCreateContentType(array(
  328. 'type' => Unicode::strtolower($this->randomMachineName(16)),
  329. 'name' => $this->randomMachineName(),
  330. ));
  331. // Create a block content type.
  332. $block_content_type = BlockContentType::create(array(
  333. 'id' => 'basic',
  334. 'label' => 'Basic',
  335. 'revision' => FALSE
  336. ));
  337. $block_content_type->save();
  338. $field = FieldConfig::create([
  339. // The field storage is guaranteed to exist because it is supplied by the
  340. // block_content module.
  341. 'field_storage' => FieldStorageConfig::loadByName('block_content', 'body'),
  342. 'bundle' => $block_content_type->id(),
  343. 'label' => 'Body',
  344. 'settings' => array('display_summary' => FALSE),
  345. ]);
  346. $field->save();
  347. // Look at a few fields on a few entity types.
  348. $pages = array(
  349. array(
  350. 'list' => 'admin/structure/types/manage/' . $content_type->id() . '/fields',
  351. 'field' => 'node.' . $content_type->id() . '.body',
  352. ),
  353. array(
  354. 'list' => 'admin/structure/block/block-content/manage/basic/fields',
  355. 'field' => 'block_content.basic.body',
  356. ),
  357. );
  358. foreach ($pages as $values) {
  359. // Get fields listing.
  360. $this->drupalGet($values['list']);
  361. $translate_link = $values['list'] . '/' . $values['field'] . '/translate';
  362. // Test if the link to translate the field is on the page.
  363. $this->assertLinkByHref($translate_link);
  364. // Test if the link to translate actually goes to the translate page.
  365. $this->drupalGet($translate_link);
  366. $this->assertRaw('<th>' . t('Language') . '</th>');
  367. }
  368. }
  369. /**
  370. * Tests the date format listing for the translate operation.
  371. */
  372. public function doDateFormatListTest() {
  373. // Get the date format listing.
  374. $this->drupalGet('admin/config/regional/date-time');
  375. $translate_link = 'admin/config/regional/date-time/formats/manage/long/translate';
  376. // Test if the link to translate the format is on the page.
  377. $this->assertLinkByHref($translate_link);
  378. // Test if the link to translate actually goes to the translate page.
  379. $this->drupalGet($translate_link);
  380. $this->assertRaw('<th>' . t('Language') . '</th>');
  381. }
  382. /**
  383. * Tests a given settings page for the translate operation.
  384. *
  385. * @param string $link
  386. * URL of the settings page to test.
  387. */
  388. public function doSettingsPageTest($link) {
  389. // Get the settings page.
  390. $this->drupalGet($link);
  391. $translate_link = $link . '/translate';
  392. // Test if the link to translate the settings page is present.
  393. $this->assertLinkByHref($translate_link);
  394. // Test if the link to translate actually goes to the translate page.
  395. $this->drupalGet($translate_link);
  396. $this->assertRaw('<th>' . t('Language') . '</th>');
  397. }
  398. /**
  399. * Tests if translate link is added to operations in all configuration lists.
  400. */
  401. public function testTranslateOperationInListUi() {
  402. // All lists based on paths provided by the module.
  403. $this->doBlockListTest();
  404. $this->doMenuListTest();
  405. $this->doVocabularyListTest();
  406. $this->doCustomContentTypeListTest();
  407. $this->doContactFormsListTest();
  408. $this->doContentTypeListTest();
  409. $this->doFormatsListTest();
  410. $this->doShortcutListTest();
  411. $this->doUserRoleListTest();
  412. $this->doLanguageListTest();
  413. $this->doImageStyleListTest();
  414. $this->doResponsiveImageListTest();
  415. $this->doDateFormatListTest();
  416. $this->doFieldListTest();
  417. // Views is tested in Drupal\config_translation\Tests\ConfigTranslationViewListUiTest
  418. // Test the maintenance settings page.
  419. $this->doSettingsPageTest('admin/config/development/maintenance');
  420. // Test the site information settings page.
  421. $this->doSettingsPageTest('admin/config/system/site-information');
  422. // Test the account settings page.
  423. $this->doSettingsPageTest('admin/config/people/accounts');
  424. // Test the RSS settings page.
  425. $this->doSettingsPageTest('admin/config/services/rss-publishing');
  426. }
  427. }

Classes

Namesort descending Description
ConfigTranslationListUiTest Visit all lists.