CommentTranslationUITest.php 4.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Definition of Drupal\comment\Tests\CommentTranslationUITest.
 */

namespace Drupal\comment\Tests;

10
use Drupal\content_translation\Tests\ContentTranslationUITest;
11
12
13
14

/**
 * Tests the Comment Translation UI.
 */
15
class CommentTranslationUITest extends ContentTranslationUITest {
16
17
18
19
20
21
22
23
24
25
26

  /**
   * The subject of the test comment.
   */
  protected $subject;

  /**
   * Modules to enable.
   *
   * @var array
   */
27
  public static $modules = array('language', 'content_translation', 'node', 'comment');
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

  public static function getInfo() {
    return array(
      'name' => 'Comment translation UI',
      'description' => 'Tests the basic comment translation UI.',
      'group' => 'Comment',
    );
  }

  function setUp() {
    $this->entityType = 'comment';
    $this->nodeBundle = 'article';
    $this->bundle = 'comment_node_' . $this->nodeBundle;
    $this->testLanguageSelector = FALSE;
    $this->subject = $this->randomName();
    parent::setUp();
  }

  /**
47
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::setupBundle().
48
49
50
51
52
53
54
   */
  function setupBundle() {
    parent::setupBundle();
    $this->drupalCreateContentType(array('type' => $this->nodeBundle, 'name' => $this->nodeBundle));
  }

  /**
55
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getTranslatorPermission().
56
   */
57
  protected function getTranslatorPermissions() {
58
    return array_merge(parent::getTranslatorPermissions(), array('post comments', 'administer comments'));
59
60
61
  }

  /**
62
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::setupTestFields().
63
64
65
   */
  function setupTestFields() {
    parent::setupTestFields();
66
    $field = field_info_field('comment', 'comment_body');
67
    $field['translatable'] = TRUE;
68
    $field->save();
69
70
71
  }

  /**
72
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::createEntity().
73
   */
74
75
76
77
78
  protected function createEntity($values, $langcode, $node_bundle = NULL) {
    if (!isset($node_bundle)) {
      $node_bundle = $this->nodeBundle;
    }
    $node = $this->drupalCreateNode(array('type' => $node_bundle));
79
    $values['nid'] = $node->id();
80
    $values['uid'] = $node->getAuthorId();
81
82
83
84
    return parent::createEntity($values, $langcode);
  }

  /**
85
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getNewEntityValues().
86
87
88
89
90
   */
  protected function getNewEntityValues($langcode) {
    // Comment subject is not translatable hence we use a fixed value.
    return array(
      'subject' => $this->subject,
91
      'comment_body' => array(array('value' => $this->randomName(16))),
92
93
94
    ) + parent::getNewEntityValues($langcode);
  }

95
  /**
96
   * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::assertPublishedStatus().
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
   */
  protected function assertPublishedStatus() {
    parent::assertPublishedStatus();
    $entity = entity_load($this->entityType, $this->entityId);
    $user = $this->drupalCreateUser(array('access comments'));
    $this->drupalLogin($user);
    $languages = language_list();

    // Check that simple users cannot see unpublished field translations.
    $path = $this->controller->getViewPath($entity);
    foreach ($this->langcodes as $index => $langcode) {
      $translation = $this->getTranslation($entity, $langcode);
      $value = $this->getValue($translation, 'comment_body', $langcode);
      $this->drupalGet($path, array('language' => $languages[$langcode]));
      if ($index > 0) {
        $this->assertNoRaw($value, 'Unpublished field translation is not shown.');
      }
      else {
        $this->assertRaw($value, 'Published field translation is shown.');
      }
    }

    // Login as translator again to ensure subsequent tests do not break.
    $this->drupalLogin($this->translator);
  }

123
124
125
126
  /**
   * Tests translate link on comment content admin page.
   */
  function testTranslateLinkCommentAdminPage() {
127
    $this->drupalCreateContentType(array('type' => 'page', 'name' => 'page'));
128
    $this->admin_user = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), array('access administration pages', 'administer comments')));
129
130
131
132
133
134
135
136
137
138
139
140
    $this->drupalLogin($this->admin_user);

    $cid_translatable = $this->createEntity(array(), $this->langcodes[0], $this->nodeBundle);
    $cid_untranslatable = $this->createEntity(array(), $this->langcodes[0], 'page');

    // Verify translation links.
    $this->drupalGet('admin/content/comment');
    $this->assertResponse(200);
    $this->assertLinkByHref('comment/' . $cid_translatable . '/translations');
    $this->assertNoLinkByHref('comment/' . $cid_untranslatable . '/translations');
  }

141
}