i18n_select.test 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @file
  4. * Test language selection modes
  5. */
  6. class i18nSelectTestCase extends Drupali18nTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Content Selection',
  10. 'group' => 'Internationalization',
  11. 'description' => 'Internationalization Content Selection'
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('translation', 'i18n_variable', 'i18n_select');
  16. parent::setUpLanguages();
  17. parent::setUpContentTranslation();
  18. }
  19. function testIi18nSelect() {
  20. drupal_static_reset('language_list');
  21. $language_list = language_list();
  22. $language_count = count($language_list);
  23. // Set site name for each language and check pages later
  24. variable_set('i18n_variable_list', array('site_name'));
  25. foreach (i18n_language_list() as $langcode => $name) {
  26. i18n_variable_set('site_name', "Drupal-$name", $langcode);
  27. }
  28. // Enable tags field for page content type.
  29. $edit = array(
  30. 'fields[_add_existing_field][label]' => t('Tags'),
  31. 'fields[_add_existing_field][field_name]' => 'field_tags',
  32. 'fields[_add_existing_field][widget_type]' => 'taxonomy_autocomplete',
  33. );
  34. $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  35. $this->drupalPost(NULL, array(), t('Save settings'));
  36. // Create some content and check selection modes
  37. $this->drupalLogin($this->content_editor);
  38. // variable_set('language_content_type_story', 1);
  39. $neutral = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
  40. $source = $this->createNode('page', $this->randomName(), $this->randomString(20), language_default('language'), array('field_tags[und]' => $tag_name = $this->randomName()));
  41. $translations = $this->createNodeTranslationSet($source);
  42. drupal_static_reset('translation_node_get_translations');
  43. $this->assertEqual(count(translation_node_get_translations($source->tnid)), $language_count, "Created $language_count $source->type translations.");
  44. // Log in user with access content permission
  45. $user = $this->drupalCreateUser(array('access comments', 'access content'));
  46. $this->drupalLogin($user);
  47. // Default selection mode, only language neutral and current
  48. variable_set('i18n_select_nodes', TRUE);
  49. foreach (i18n_language_list() as $langcode => $name) {
  50. $this->i18nGet($langcode);
  51. $this->assertText("Drupal-$name", 'Checked translated site name: Drupal-' . $name);
  52. $display = array($translations[$langcode], $neutral);
  53. $hide = $translations;
  54. unset($hide[$langcode]);
  55. $this->assertContent($display, $hide);
  56. // Visit the taxonomy page of that node and try again. Only the translated
  57. // pages are tagged.
  58. unset($display[1]);
  59. $this->i18nGet($langcode, 'taxonomy/term/' . $source->field_tags[LANGUAGE_NONE][0]['tid']);
  60. $this->assertContent($display, $hide);
  61. }
  62. }
  63. /**
  64. * Check some nodes are displayed, some are not
  65. */
  66. function assertContent($display, $hide = array()) {
  67. $languages = language_list();
  68. foreach ($display as $node) {
  69. $this->assertText($node->title, 'Content displayed for ' . i18n_language_name($node->language));
  70. }
  71. foreach ($hide as $node) {
  72. $this->assertNoText($node->title, 'Content not displayed for ' . i18n_language_name($node->language));
  73. }
  74. }
  75. }
  76. /**
  77. * Test case for AJAX queries on "views/ajax" when view on admin page.
  78. */
  79. class I18NSelectAdminViewsAjax extends Drupali18nTestCase {
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public static function getInfo() {
  84. return array(
  85. 'name' => t('I18N select Admin Views (AJAX)'),
  86. 'group' => 'Internationalization',
  87. 'description' => t('Test AJAX requests to the "views/ajax" when view located on "admin/*" and list of skipping tags is empty.'),
  88. // Skip this test when "admin_views" module does not exists.
  89. 'dependencies' => array('admin_views'),
  90. );
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. protected function setUp() {
  96. parent::setUp('translation', 'i18n_variable', 'i18n_select', 'admin_views');
  97. parent::setUpLanguages(array('access content overview'));
  98. parent::setUpContentTranslation();
  99. }
  100. /**
  101. * Test AJAX of a view without skipping tags for selection.
  102. *
  103. * @see i18n_select_page()
  104. */
  105. public function testViewsAjaxWithoutSkippingTags() {
  106. // If this variable will have the "views" value then this test will not
  107. // have sense. For instance, we want apply language selection filter
  108. // for views and remove "views" from "i18n_select_skip_tags" variable.
  109. // In this case all AJAX for views, on administration part of the site,
  110. // will be broken because the "i18n_select_page()" function will work
  111. // with "views/ajax" path instead of, for example, "admin/content".
  112. variable_set('i18n_select_skip_tags', '');
  113. // Create one hundred of nodes.
  114. for ($i = 1; $i <= 100; $i++) {
  115. // Create every second node on Spanish language and
  116. // every first - on English.
  117. $node = $this->createNode('page', "Node $i", '', $i % 2 ? $this->default_language : $this->secondary_language);
  118. // Update "changed" in order to sort the content by updating date. In
  119. // other case all nodes will be with the same date and not arranged in
  120. // order.
  121. db_update('node')
  122. ->fields(array('changed' => strtotime("+ $i minute")))
  123. ->condition('nid', $node->nid)
  124. ->execute();
  125. }
  126. $this->drupalGet('admin/content');
  127. // Check that latest node exists at the top.
  128. $this->assertText('Node 100');
  129. // Check that our page contains fifty nodes (the latest must be 51).
  130. $this->assertNoText('Node 50');
  131. // Test $_REQUEST['view_path']. There's no form to submit to, so
  132. // drupalPost() won't work here. This just tests a direct $_POST
  133. // request instead.
  134. $this->curlExec(array(
  135. CURLOPT_URL => $this->getAbsoluteUrl('views/ajax'),
  136. CURLOPT_POST => TRUE,
  137. CURLOPT_POSTFIELDS => http_build_query(array(
  138. 'page' => 1,
  139. 'view_path' => 'admin/content',
  140. 'view_name' => 'admin_views_node',
  141. 'view_display_id' => 'system_1',
  142. )),
  143. ));
  144. // Check that we are successfully switched to a new page of content.
  145. $this->assertText('Node 50');
  146. $this->assertNoText('Node 100');
  147. }
  148. }