ds.exportables.test 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @file
  4. * Base functions and tests for Display Suite.
  5. */
  6. class dsExportablesTests extends dsBaseTest {
  7. /**
  8. * Implements getInfo().
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => t('Exportables'),
  13. 'description' => t('Tests for exportables in Display Suite.'),
  14. 'group' => t('Display Suite'),
  15. );
  16. }
  17. /**
  18. * Enables the exportables module.
  19. */
  20. function dsExportablesSetup() {
  21. module_enable(array('ds_exportables_test'));
  22. drupal_flush_all_caches();
  23. }
  24. // Test view modes.
  25. function testDSExportablesViewmodes() {
  26. $this->dsExportablesSetup();
  27. // Find a default view mode on admin screen.
  28. $this->drupalGet('admin/structure/ds/view_modes');
  29. $this->assertText('Test exportables', t('Exportables view mode found on admin screen.'));
  30. // Find default view mode on layout screen.
  31. $this->drupalGet('admin/structure/types/manage/article/display');
  32. $this->assertText('Test exportables', t('Exportables view mode found on display screen.'));
  33. // Override default view mode.
  34. $edit = array(
  35. 'name' => 'Testing 2',
  36. );
  37. $this->drupalPost('admin/structure/ds/view_modes/manage/test_exportables', $edit, t('Save'));
  38. $this->assertText(t('The view mode Testing 2 has been saved'), t('Exportables label updated'));
  39. $this->assertText(t('Revert'), t('Revert button found.'));
  40. // Find default view mode on layout screen.
  41. $this->drupalGet('admin/structure/types/manage/article/display');
  42. $this->assertText('Testing 2', t('Updated exportables view mode found on display screen.'));
  43. // Revert the view mode.
  44. $this->drupalPost('admin/structure/ds/view_modes/revert/test_exportables', array(), t('Revert'));
  45. $this->assertText(t('The view mode Testing 2 has been reverted'), t('Testing view mode reverted'));
  46. $this->assertText('Test exportables', t('Exportables view mode found on admin screen.'));
  47. // Assert the view mode is gone at the manage display screen.
  48. $this->drupalGet('admin/structure/types/manage/article/display');
  49. $this->assertNoText('Testing 2', t('Overrided exportables view mode not found on display screen.'));
  50. $this->assertText('Test exportables', t('Default exportables view mode found on display screen.'));
  51. }
  52. // Test layout and field settings configuration.
  53. function testDSExportablesLayoutFieldsettings() {
  54. $this->dsExportablesSetup();
  55. $this->drupalGet('admin/structure/types/manage/article/display');
  56. $this->assertNoText(t('This layout is overridden. Click to revert to default settings.'));
  57. $settings = array(
  58. 'type' => 'article',
  59. 'title' => 'Exportable'
  60. );
  61. $node = $this->drupalCreateNode($settings);
  62. $this->drupalGet('node/' . $node->nid);
  63. $this->assertRaw('group-left', 'Left region found');
  64. $this->assertRaw('group-right', 'Right region found');
  65. $this->assertNoRaw('group-header', 'No header region found');
  66. $this->assertNoRaw('group-footer', 'No footer region found');
  67. $this->assertRaw('<h3><a href="'. url('node/1') . '" class="active">Exportable</a></h3>', t('Default title with h3 found'));
  68. $this->assertRaw('<a href="' . url('node/1') . '" class="active">Read more</a>', t('Default read more found'));
  69. // Override default layout.
  70. $layout = array(
  71. 'additional_settings[layout]' => 'ds_2col_stacked',
  72. );
  73. $assert = array(
  74. 'regions' => array(
  75. 'header' => '<td colspan="8">' . t('Header') . '</td>',
  76. 'left' => '<td colspan="8">' . t('Left') . '</td>',
  77. 'right' => '<td colspan="8">' . t('Right') . '</td>',
  78. 'footer' => '<td colspan="8">' . t('Footer') . '</td>',
  79. ),
  80. );
  81. $fields = array(
  82. 'fields[post_date][region]' => 'header',
  83. 'fields[author][region]' => 'left',
  84. 'fields[links][region]' => 'left',
  85. 'fields[body][region]' => 'right',
  86. 'fields[comments][region]' => 'footer',
  87. );
  88. $this->dsSelectLayout($layout, $assert);
  89. $this->assertText(t('This layout is overridden. Click to revert to default settings.'));
  90. $this->dsConfigureUI($fields);
  91. $this->drupalGet('node/' . $node->nid);
  92. $this->assertRaw('group-left', 'Left region found');
  93. $this->assertRaw('group-right', 'Left region found');
  94. $this->assertRaw('group-header', 'Left region found');
  95. $this->assertRaw('group-footer', 'Left region found');
  96. // Revert.
  97. $edit = array();
  98. $this->drupalPost('admin/structure/ds/revert-layout/node|article|default', $edit, t('Revert'), array('query' => array('destination' => 'admin/structure/types/manage/article/display')));
  99. $this->drupalGet('node/' . $node->nid);
  100. $this->assertRaw('group-left', 'Left region found');
  101. $this->assertRaw('group-right', 'Left region found');
  102. $this->assertNoRaw('group-header', 'Left region found');
  103. $this->assertNoRaw('group-footer', 'Left region found');
  104. $this->assertRaw('<h3><a href="'. url('node/1') . '" class="active">Exportable</a></h3>', t('Default title with h3 found'));
  105. $this->assertRaw('<a href="' . url('node/1') . '" class="active">Read more</a>', t('Default read more found'));
  106. }
  107. // Test custom field exportables.
  108. function testDSExportablesCustomFields() {
  109. $this->dsExportablesSetup();
  110. // Look for default custom field.
  111. $this->drupalGet('admin/structure/ds/fields');
  112. $this->assertText('Exportable field');
  113. $this->drupalGet('admin/structure/types/manage/article/display');
  114. $this->assertText('Exportable field');
  115. // Override custom field.
  116. // Update testing label
  117. $edit = array(
  118. 'name' => 'Overridden field',
  119. );
  120. $this->drupalPost('admin/structure/ds/fields/manage_custom/ds_exportable_field', $edit, t('Save'));
  121. $this->assertText(t('The field Overridden field has been saved'), t('Default exportable field label updated'));
  122. $this->assertText('Overridden field');
  123. $this->assertNoText('Exportable field');
  124. $this->drupalGet('admin/structure/types/manage/article/display');
  125. $this->assertText('Overridden field');
  126. $this->assertNoText('Exportable field');
  127. // Revert.
  128. $edit = array();
  129. $this->drupalPost('admin/structure/ds/fields/revert/ds_exportable_field', $edit, t('Revert'));
  130. $this->assertText('The field Overridden field has been reverted', t('Field reverted'));
  131. $this->assertText('Exportable field');
  132. $this->drupalGet('admin/structure/types/manage/article/display');
  133. $this->assertNoText('Overridden field');
  134. $this->assertText('Exportable field');
  135. }
  136. }