Project

General

Profile

Paste
Download (10 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / tests / views_translatable.test @ 6de61b86

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsTranslatableTest.
6
 */
7

    
8
/**
9
 * Tests Views pluggable translations.
10
 */
11
class ViewsTranslatableTest extends ViewsSqlTest {
12
  var $strings;
13

    
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Views Translatable Test',
17
      'description' => 'Tests the pluggable translations',
18
      'group' => 'Views',
19
    );
20
  }
21

    
22
  /**
23
   * The views plugin definition. Override it if you test provides a plugin.
24
   */
25
  public function viewsPlugins() {
26
    return array(
27
      'localization' => array(
28
        'test' => array(
29
          'no ui' => TRUE,
30
          'title' => t('Test'),
31
          'help' => t('This is a test description.'),
32
          'handler' => 'views_plugin_localization_test',
33
          'parent' => 'parent',
34
          'path' => drupal_get_path('module', 'views') . '/tests',
35
        ),
36
      ),
37
    );
38
  }
39

    
40
  public function setUp() {
41
    parent::setUp();
42

    
43
    variable_set('views_localization_plugin', 'test');
44
    // Reset the plugin data.
45
    views_fetch_plugin_data(NULL, NULL, TRUE);
46
    $this->strings = array('Master1', 'Apply1', 'Sort By1', 'Asc1', 'Desc1', 'more1', 'Reset1', 'Offset1', 'Master1', 'title1', 'Items per page1', 'fieldlabel1', 'filterlabel1');
47
    $this->enableViewsUi();
48
  }
49

    
50
  /**
51
   * Tests the unpack translation funtionality.
52
   */
53
  public function testUnpackTranslatable() {
54
    $view = $this->view_unpack_translatable();
55
    $view->init_localization();
56

    
57
    $this->assertEqual('views_plugin_localization_test', get_class($view->localization_plugin), 'Make sure that init_localization initializes the right translation plugin');
58

    
59
    $view->export_locale_strings();
60

    
61
    $expected_strings = $this->strings;
62
    $result_strings = $view->localization_plugin->get_export_strings();
63
    $this->assertEqual(sort($expected_strings), sort($result_strings), 'Make sure that the localization plugin got every translatable string.');
64
  }
65

    
66
  public function testUi() {
67
    // Make sure that the string is not translated in the UI.
68
    $view = $this->view_unpack_translatable();
69
    $view->save();
70
    views_invalidate_cache();
71

    
72
    $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
73
    $this->drupalLogin($admin_user);
74

    
75
    $this->drupalGet("admin/structure/views/view/$view->name/edit");
76
    $this->assertNoText('-translated', 'Make sure that no strings get translated in the UI.');
77
  }
78

    
79
  /**
80
   * Make sure that the translations get into the loaded view.
81
   */
82
  public function testTranslation() {
83
    $view = $this->view_unpack_translatable();
84
    $view->set_display('default');
85
    $this->executeView($view);
86

    
87
    $expected_strings = array();
88
    foreach ($this->strings as $string) {
89
      $expected_strings[] = $string .= '-translated';
90
    }
91
    $this->assertEqual(sort($expected_strings), sort($view->localization_plugin->translated_strings), 'Make sure that every string got loaded translated');
92
  }
93

    
94
  /**
95
   * Make sure that the different things have the right translation keys.
96
   */
97
  public function testTranslationKey() {
98
    $view = $this->view_unpack_translatable();
99
    $view->editing = TRUE;
100
    $view->init_display();
101

    
102
    // Don't run translation. We just want to get the right keys.
103
    foreach ($view->display as $display_id => $display) {
104
      $translatables = array();
105
      $display->handler->unpack_translatables($translatables);
106

    
107
      $this->string_keys = array(
108
        'Master1' => array('title'),
109
        'Apply1' => array('exposed_form', 'submit_button'),
110
        'Sort By1' => array('exposed_form', 'exposed_sorts_label'),
111
        'Asc1' => array('exposed_form', 'sort_asc_label'),
112
        'Desc1' => array('exposed_form', 'sort_desc_label'),
113
        'more1' => array('use_more_text'),
114
        'Reset1' => array('exposed_form', 'reset_button_label'),
115
        'Offset1' => array('pager', 'expose', 'offset_label'),
116
        'title1' => array('title'),
117
        'Tag first1' => array('pager', 'tags', 'first'),
118
        'Tag prev1' => array('pager', 'tags', 'previous'),
119
        'Tag next1' => array('pager', 'tags', 'next'),
120
        'Tag last1' => array('pager', 'tags', 'last'),
121
        'Items per page1' => array('pager', 'expose', 'items_per_page_label'),
122
        'fieldlabel1' => array('field', 'node', 'nid', 'label'),
123
        'filterlabel1' => array('filter', 'node', 'nid', 'expose', 'label'),
124
        '- All -' => array('pager', 'expose', 'items_per_page_options_all_label'),
125
        'Header1' => array('header', 'views', 'area', 'content'),
126
      );
127

    
128
      $formats = array(
129
        'Header1' => 'filtered_html',
130
      );
131

    
132
      foreach ($translatables as $translatable) {
133
        $this->assertEqual($translatable['keys'], $this->string_keys[$translatable['value']]);
134

    
135
        // Make sure the format is correct.
136
        if (isset($formats[$translatable['value']])) {
137
          $this->assertEqual($translatable['format'], $formats[$translatable['value']]);
138
        }
139
        else {
140
          $this->assertNull($translatable['format'], 'No format defined');
141
        }
142
      }
143
    }
144
  }
145

    
146
  public function view_unpack_translatable() {
147
    $view = new view();
148
    $view->name = 'view_unpack_translatable';
149
    $view->description = '';
150
    $view->tag = '';
151
    $view->base_table = 'node';
152
    $view->api_version = '3.0-alpha1';
153
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
154

    
155
    /* Display: Master */
156
    $handler = $view->new_display('default', 'Master1', 'default');
157
    $handler->display->display_options['title'] = 'title1';
158
    $handler->display->display_options['use_more_text'] = 'more1';
159
    $handler->display->display_options['access']['type'] = 'none';
160
    $handler->display->display_options['cache']['type'] = 'none';
161
    $handler->display->display_options['query']['type'] = 'views_query';
162
    $handler->display->display_options['exposed_form']['type'] = 'basic';
163
    $handler->display->display_options['exposed_form']['options']['submit_button'] = 'Apply1';
164
    $handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
165
    $handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Reset1';
166
    $handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sort By1';
167
    $handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Asc1';
168
    $handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Desc1';
169
    $handler->display->display_options['pager']['type'] = 'full';
170
    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
171
    $handler->display->display_options['pager']['options']['offset'] = '0';
172
    $handler->display->display_options['pager']['options']['id'] = '0';
173
    $handler->display->display_options['pager']['options']['quantity'] = '9';
174
    $handler->display->display_options['pager']['options']['tags']['first'] = 'Tag first1';
175
    $handler->display->display_options['pager']['options']['tags']['previous'] = 'Tag prev1';
176
    $handler->display->display_options['pager']['options']['tags']['next'] = 'Tag next1';
177
    $handler->display->display_options['pager']['options']['tags']['last'] = 'Tag last1';
178
    $handler->display->display_options['pager']['options']['expose']['items_per_page'] = TRUE;
179
    $handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Items per page1';
180
    $handler->display->display_options['pager']['options']['expose']['offset'] = TRUE;
181
    $handler->display->display_options['pager']['options']['expose']['offset_label'] = 'Offset1';
182
    $handler->display->display_options['style_plugin'] = 'default';
183
    $handler->display->display_options['row_plugin'] = 'fields';
184
    /* Global: Header */
185
    $handler->display->display_options['header']['area']['id'] = 'area';
186
    $handler->display->display_options['header']['area']['table'] = 'views';
187
    $handler->display->display_options['header']['area']['field'] = 'area';
188
    $handler->display->display_options['header']['area']['empty'] = FALSE;
189
    $handler->display->display_options['header']['area']['content'] = 'Header1';
190
    $handler->display->display_options['header']['area']['format'] = 'filtered_html';
191
    $handler->display->display_options['header']['area']['tokenize'] = 0;
192
    /* Field: Content: Nid */
193
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
194
    $handler->display->display_options['fields']['nid']['table'] = 'node';
195
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
196
    $handler->display->display_options['fields']['nid']['label'] = 'fieldlabel1';
197
    $handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
198
    $handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
199
    $handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
200
    $handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
201
    $handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
202
    $handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
203
    $handler->display->display_options['fields']['nid']['alter']['html'] = 0;
204
    $handler->display->display_options['fields']['nid']['hide_empty'] = 0;
205
    $handler->display->display_options['fields']['nid']['empty_zero'] = 0;
206
    $handler->display->display_options['fields']['nid']['link_to_node'] = 0;
207
    /* Filter: Content: Nid */
208
    $handler->display->display_options['filters']['nid']['id'] = 'nid';
209
    $handler->display->display_options['filters']['nid']['table'] = 'node';
210
    $handler->display->display_options['filters']['nid']['field'] = 'nid';
211
    $handler->display->display_options['filters']['nid']['exposed'] = TRUE;
212
    $handler->display->display_options['filters']['nid']['expose']['operator_id'] = 'nid_op';
213
    $handler->display->display_options['filters']['nid']['expose']['label'] = 'filterlabel1';
214
    $handler->display->display_options['filters']['nid']['expose']['identifier'] = 'nid';
215
    $handler->display->display_options['filters']['nid']['expose']['multiple'] = 1;
216
    $handler->display->display_options['filters']['nid']['expose']['reduce'] = 0;
217

    
218
    return $view;
219
  }
220

    
221
}