summaryrefslogtreecommitdiff
path: root/sites/all/modules/ds/tests/ds.exportables.test
blob: 95b95d6af015f0ef7e48f5ceaf767b13b03ea30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php

/**
 * @file
 * Base functions and tests for Display Suite.
 */

class dsExportablesTests extends dsBaseTest {

  /**
   * Implements getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Exportables'),
      'description' => t('Tests for exportables in Display Suite.'),
      'group' => t('Display Suite'),
    );
  }

  /**
   * Enables the exportables module.
   */
  function dsExportablesSetup() {
    module_enable(array('ds_exportables_test'));
    drupal_flush_all_caches();
  }

  // Test view modes.
  function testDSExportablesViewmodes() {
    $this->dsExportablesSetup();

    // Find a default view mode on admin screen.
    $this->drupalGet('admin/structure/ds/view_modes');
    $this->assertText('Test exportables', t('Exportables view mode found on admin screen.'));

    // Find default view mode on layout screen.
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertText('Test exportables', t('Exportables view mode found on display screen.'));

    // Override default view mode.
    $edit = array(
      'name' => 'Testing 2',
    );
    $this->drupalPost('admin/structure/ds/view_modes/manage/test_exportables', $edit, t('Save'));
    $this->assertText(t('The view mode Testing 2 has been saved'), t('Exportables label updated'));
    $this->assertText(t('Revert'), t('Revert button found.'));

    // Find default view mode on layout screen.
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertText('Testing 2', t('Updated exportables view mode found on display screen.'));

    // Revert the view mode.
    $this->drupalPost('admin/structure/ds/view_modes/revert/test_exportables', array(), t('Revert'));
    $this->assertText(t('The view mode Testing 2 has been reverted'), t('Testing view mode reverted'));
    $this->assertText('Test exportables', t('Exportables view mode found on admin screen.'));

    // Assert the view mode is gone at the manage display screen.
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertNoText('Testing 2', t('Overrided exportables view mode not found on display screen.'));
    $this->assertText('Test exportables', t('Default exportables view mode found on display screen.'));
  }

  // Test layout and field settings configuration.
  function testDSExportablesLayoutFieldsettings() {
    $this->dsExportablesSetup();

    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertNoText(t('This layout is overridden. Click to revert to default settings.'));

    $settings = array(
      'type' => 'article',
      'title' => 'Exportable'
    );
    $node = $this->drupalCreateNode($settings);
    $this->drupalGet('node/' . $node->nid);
    $this->assertRaw('group-left', 'Left region found');
    $this->assertRaw('group-right', 'Right region found');
    $this->assertNoRaw('group-header', 'No header region found');
    $this->assertNoRaw('group-footer', 'No footer region found');
    $this->assertRaw('<h3><a href="'. url('node/1') . '" class="active">Exportable</a></h3>', t('Default title with h3 found'));
    $this->assertRaw('<a href="' . url('node/1') . '" class="active">Read more</a>', t('Default read more found'));

    // Override default layout.
    $layout = array(
      'additional_settings[layout]' => 'ds_2col_stacked',
    );

    $assert = array(
      'regions' => array(
        'header' => '<td colspan="8">' . t('Header') . '</td>',
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
        'footer' => '<td colspan="8">' . t('Footer') . '</td>',
      ),
    );

    $fields = array(
      'fields[post_date][region]' => 'header',
      'fields[author][region]' => 'left',
      'fields[links][region]' => 'left',
      'fields[body][region]' => 'right',
      'fields[comments][region]' => 'footer',
    );

    $this->dsSelectLayout($layout, $assert);
    $this->assertText(t('This layout is overridden. Click to revert to default settings.'));
    $this->dsConfigureUI($fields);

    $this->drupalGet('node/' . $node->nid);
    $this->assertRaw('group-left', 'Left region found');
    $this->assertRaw('group-right', 'Left region found');
    $this->assertRaw('group-header', 'Left region found');
    $this->assertRaw('group-footer', 'Left region found');

    // Revert.
    $edit = array();
    $this->drupalPost('admin/structure/ds/revert-layout/node|article|default', $edit, t('Revert'), array('query' => array('destination' => 'admin/structure/types/manage/article/display')));
    $this->drupalGet('node/' . $node->nid);
    $this->assertRaw('group-left', 'Left region found');
    $this->assertRaw('group-right', 'Left region found');
    $this->assertNoRaw('group-header', 'Left region found');
    $this->assertNoRaw('group-footer', 'Left region found');
    $this->assertRaw('<h3><a href="'. url('node/1') . '" class="active">Exportable</a></h3>', t('Default title with h3 found'));
    $this->assertRaw('<a href="' . url('node/1') . '" class="active">Read more</a>', t('Default read more found'));
  }

  // Test custom field exportables.
  function testDSExportablesCustomFields() {
    $this->dsExportablesSetup();

    // Look for default custom field.
    $this->drupalGet('admin/structure/ds/fields');
    $this->assertText('Exportable field');
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertText('Exportable field');

    // Override custom field.
    // Update testing label
    $edit = array(
      'name' => 'Overridden field',
    );
    $this->drupalPost('admin/structure/ds/fields/manage_custom/ds_exportable_field', $edit, t('Save'));
    $this->assertText(t('The field Overridden field has been saved'), t('Default exportable field label updated'));
    $this->assertText('Overridden field');
    $this->assertNoText('Exportable field');
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertText('Overridden field');
    $this->assertNoText('Exportable field');

    // Revert.
    $edit = array();
    $this->drupalPost('admin/structure/ds/fields/revert/ds_exportable_field', $edit, t('Revert'));
    $this->assertText('The field Overridden field has been reverted', t('Field reverted'));
    $this->assertText('Exportable field');
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertNoText('Overridden field');
    $this->assertText('Exportable field');
  }
}