Projet

Général

Profil

Paste
Télécharger (5,32 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panelizer / tests / panelizer.node_content_translation.test @ 651307cd

1
<?php
2
/**
3
 * @file
4
 * Test the content translation integration for Panelizer.
5
 */
6

    
7
/**
8
 *
9
 */
10
class PanelizerNodeContentTranslationTest extends PanelizerTestHelper {
11

    
12
  /**
13
   * {@inheritdoc}
14
   */
15
  public static function getInfo() {
16
    return array(
17
      'name' => 'Panelizer node translations',
18
      'description' => 'Test node translations using Content Translation.',
19
      'group' => 'Panelizer',
20
    );
21
  }
22

    
23
  /**
24
   * {@inheritdoc}
25
   */
26
  function setUp(array $modules = array()) {
27
    // Need the module that manages all languages.
28
    $modules[] = 'locale';
29

    
30
    // Enable the Content Translation module.
31
    $modules[] = 'translation';
32
    parent::setUp($modules);
33

    
34
    $perms = array(
35
      // Standard node permissions.
36
      'create page content',
37
      'administer content types',
38
      'administer nodes',
39
      'bypass node access',
40

    
41
      // Locale.
42
      'administer languages',
43

    
44
      // Content Translation.
45
      'translate content',
46

    
47
      // Panelizer.
48
      'administer panelizer',
49
    );
50
    $web_user = $this->drupalCreateUser($perms);
51
    $this->drupalLogin($web_user);
52

    
53
    // Enable extra locales.
54
    $this->setupLocales();
55

    
56
    // Enable content translation for the 'page' content type.
57
    variable_set('language_content_type_page', 2);
58
  }
59

    
60
  /**
61
   * Verify that when a node is translated the customized Panelizer display is
62
   * cloned to the new node.
63
   */
64
  function testContentTranslation() {
65
    $entity_type = 'node';
66
    // The content type that is being tested.
67
    $content_type = 'page';
68
    // The view mode that is being tested.
69
    $view_mode = 'page_manager';
70
    // The text that will be checked for on the page.
71
    $sample_text = 'Hello world';
72

    
73
    // @todo Enable a second language.
74
    // @todo Allow the content type to be translated.
75

    
76
    // Ensure node_view panel page is enabled for full page override to work.
77
    $this->simpleEnablePage($entity_type . '_view');
78

    
79
    // Enable Panelizer for this content type; receive an updated handler so
80
    // that it can be used later.
81
    $handler = $this->togglePanelizer($entity_type, $content_type, 'page_manager', 1, 1, 1);
82

    
83
    // Create a node with the English language; it will inherit the default
84
    // Panelizer display.
85
    $options = array(
86
      'title' => 'English test page',
87
      'type' => $content_type,
88
      'language' => 'en',
89
    );
90
    $node = $this->drupalCreateNode($options);
91
    $this->verbose(print_r($node, TRUE));
92

    
93
    // Check that the post can been panelized.
94
    $this->drupalGet('node/' . $node->nid);
95
    $this->assertResponse(200);
96
    $this->assertLink('Customize display', 0, 'The customize display link appears on the page');
97
    $this->assertLinkByHref('node/' . $node->nid . '/panelizer', 0, 'A link to customize the node appears on the page');
98

    
99
    // Check that the view mode can be panelized.
100
    $this->drupalGet('node/' . $node->nid . '/panelizer/' . $view_mode . '/content');
101
    $this->assertResponse(200);
102
    $this->assertLink(t('Full page override'), 0, 'The panelize link for the "Full page override" view mode appears on the page');
103

    
104
    // Load the default display for this node.
105
    $panelizer = new StdClass();
106
    $panelizer->name = NULL;
107
    $panelizer->entity_type = 'node';
108
    $panelizer->entity_id = $node->nid;
109
    $panelizer->view_mode = $view_mode;
110
    $panelizer->display_is_modified = TRUE;
111
    $panelizer->display = $handler->get_default_display($content_type, $view_mode);
112
    $panelizer->did = $panelizer->display->did;
113
    $node->panelizer[$view_mode] = $panelizer;
114
    $this->verbose('<pre>' . print_r($node, TRUE) . '</pre>');
115

    
116
    // Customize the page.
117
    $this->addTestPane($node->panelizer[$view_mode]->display, $sample_text);
118

    
119
    // Save the node to update the display. Use the handler directly otherwise
120
    // the in-memory handler object won't have the updated settings; see above.
121
    $handler->hook_entity_update($node);
122
    $this->verbose('<pre>' . print_r($node, TRUE) . '</pre>');
123
    $node = node_load($node->nid);
124
    $this->verbose('<pre>' . print_r($node, TRUE) . '</pre>');
125

    
126
    // Confirm the node view page shows the test string.
127
    $this->drupalGet('node/' . $node->nid);
128
    $this->assertResponse(200);
129
    $this->assertText($sample_text);
130

    
131
    // Confirm the node has a custom Panelizer config.
132
    $this->assertTrue(isset($node->panelizer[$view_mode]));
133
    $this->assertTrue(!empty($node->panelizer[$view_mode]->did));
134

    
135
    // Translate the node into French.
136
    $this->drupalGet('node/add/page', array('query' => array('translation' => $node->nid, 'target' => 'fr')));
137
    $args = array(
138
      'title' => 'French test page',
139
    );
140
    $this->drupalPost(NULL, $args, t('Save'));
141

    
142
    // Confirm that the page saved correctly.
143
    $t_args = array('@type' => t('Basic page'), '%title' => $args['title']);
144
    $this->assertText(strip_tags(t('@type %title has been created.', $t_args)));
145

    
146
    // Load the translated node.
147
    $node_fr = $this->drupalGetNodeByTitle($args['title']);
148
    $this->verbose('<pre>' . print_r($node_fr, TRUE) . '</pre>');
149

    
150
    // Load the node page.
151
    $this->drupalGet('node/' . $node_fr->nid);
152
    $this->assertResponse(200);
153
    $this->assertText($sample_text);
154

    
155
    // Confirm that the translated node has a copy of the display, i.e the
156
    // same contents but a different did.
157
    $this->assertTrue(isset($node_fr->panelizer[$view_mode]));
158
    $this->assertTrue(!empty($node_fr->panelizer[$view_mode]->did));
159
  }
160

    
161
}