i18n_select.test 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }