field_group.test 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * @file
  4. * Unit test file for groups.
  5. *
  6. * @todo - fill along if we know more.
  7. *
  8. * - nest a group under another group and see if parent_name is first group
  9. * - nest a group under second group and see if parent_name is second group
  10. * - settings: open f and verify on front-end (classes)
  11. * - settings: collapsible f and verify on front-end (classes)
  12. * - settings: collapsed f and verify on front-end (classes)
  13. * - settings: vertical tabs and verify on front-end (classes)
  14. * - settings: horizontal item and verify on front-end (classes)
  15. * - settings: vertical item and verify on front-end (classes)
  16. * - settings: hidden (simple div) and verify on front-end (classes)
  17. * - settings: label and verify on front-end
  18. * - delete a fieldgroup - make sure we have a couple with the same name
  19. * and make sure the right one is deleted!
  20. */
  21. /**
  22. * Group UI tests.
  23. */
  24. class GroupUITestCase extends DrupalWebTestCase {
  25. public static function getInfo() {
  26. return array(
  27. 'name' => 'Field group tests',
  28. 'description' => 'Test the field group functionality.',
  29. 'group' => 'Field group',
  30. );
  31. }
  32. function setUp() {
  33. parent::setUp('field_test', 'field_group');
  34. // Create test user.
  35. $admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'access administration pages', 'bypass node access'));
  36. $this->drupalLogin($admin_user);
  37. // Create random group name.
  38. $this->group_label = $this->randomName(8);
  39. $this->group_name_input = drupal_strtolower($this->randomName(8));
  40. $this->group_name = 'group_' . $this->group_name_input;
  41. // Create a fieldgroup.
  42. $field_group = new stdClass;
  43. $field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
  44. $field_group->api_version = 1;
  45. $field_group->identifier = 'wrapper|node|article|form';
  46. $field_group->group_name = 'wrapper';
  47. $field_group->entity_type = 'node';
  48. $field_group->bundle = 'article';
  49. $field_group->mode = 'form';
  50. $field_group->parent_name = '';
  51. $field_group->data = array(
  52. 'label' => 'Wrapper',
  53. 'weight' => '1',
  54. 'children' => array(
  55. 0 => 'field_image',
  56. ),
  57. 'format_type' => 'div',
  58. 'format_settings' => array(
  59. 'label' => 'Link',
  60. 'instance_settings' => array(
  61. 'required_fields' => 0,
  62. 'id' => 'wrapper-id',
  63. 'classes' => '',
  64. 'description' => '',
  65. 'show_label' => '0',
  66. 'label_element' => 'h3',
  67. 'effect' => 'none',
  68. 'speed' => 'fast',
  69. ),
  70. 'formatter' => 'open',
  71. ),
  72. );
  73. drupal_write_record('field_group', $field_group);
  74. ctools_export_crud_enable('field_group', $field_group->identifier);
  75. }
  76. /**
  77. * Creates a group on the article content type.
  78. */
  79. function createGroup() {
  80. // Setup new group.
  81. $group = array(
  82. 'fields[_add_new_group][label]' => $this->group_label,
  83. 'fields[_add_new_group][group_name]' => $this->group_name_input,
  84. );
  85. // Add new group on the 'Manage fields' page.
  86. $this->drupalPost('admin/structure/types/manage/article/fields', $group, t('Save'));
  87. $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
  88. // Test if group is in the $groups array.
  89. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  90. $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
  91. // Add new group on the 'Manage display' page.
  92. $this->drupalPost('admin/structure/types/manage/article/display', $group, t('Save'));
  93. $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
  94. // Test if group is in the $groups array.
  95. $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  96. $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
  97. }
  98. /**
  99. * Delete a group.
  100. */
  101. function deleteGroup() {
  102. $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/form', array(), t('Delete'));
  103. $this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
  104. // Test that group is not in the $groups array.
  105. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  106. $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
  107. $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/default', array(), t('Delete'));
  108. $this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
  109. // Test that group is not in the $groups array.
  110. $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  111. $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
  112. }
  113. /**
  114. * General CRUD.
  115. */
  116. function testCRUDGroup() {
  117. $this->createGroup();
  118. $this->deleteGroup();
  119. }
  120. /**
  121. * Nest a field underneath a group.
  122. */
  123. function testNestField() {
  124. // Test on the wrapper field.
  125. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  126. $this->assertTrue(in_array('field_image', $groups['wrapper']->children), t('Image is a child of %group', array('%group' => 'Wrapper')));
  127. $this->drupalGet('node/add/article');
  128. $this->assertRaw('id="wrapper-id"', t('Wrapper id set on wrapper div'));
  129. }
  130. }