field_group.ui.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Test file for fieldgroup UI.
  5. */
  6. /**
  7. * Group UI tests.
  8. */
  9. class GroupUITestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'UI tests',
  13. 'description' => 'Test the Field Group UI.',
  14. 'group' => 'Field Group',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('field_test', 'field_group', 'field_group_test');
  19. // Create test user.
  20. $admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'access administration pages', 'bypass node access', 'administer fields'));
  21. $this->drupalLogin($admin_user);
  22. }
  23. /**
  24. * Test the creation a group on the article content type.
  25. */
  26. function createGroup() {
  27. // Create random group name.
  28. $this->group_label = $this->randomName(8);
  29. $this->group_name_input = drupal_strtolower($this->randomName(8));
  30. $this->group_name = 'group_' . $this->group_name_input;
  31. // Setup new group.
  32. $group = array(
  33. 'fields[_add_new_group][label]' => $this->group_label,
  34. 'fields[_add_new_group][group_name]' => $this->group_name_input,
  35. );
  36. // Add new group on the 'Manage fields' page.
  37. $this->drupalPost('admin/structure/types/manage/article/fields', $group, t('Save'));
  38. $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
  39. // Test if group is in the $groups array.
  40. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  41. $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
  42. // Add new group on the 'Manage display' page.
  43. $this->drupalPost('admin/structure/types/manage/article/display', $group, t('Save'));
  44. $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
  45. // Test if group is in the $groups array.
  46. $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  47. $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
  48. }
  49. /**
  50. * Delete a group.
  51. */
  52. function deleteGroup() {
  53. $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/form', array(), t('Delete'));
  54. $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.'));
  55. // Test that group is not in the $groups array.
  56. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  57. $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
  58. $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/default', array(), t('Delete'));
  59. $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.'));
  60. // Test that group is not in the $groups array.
  61. $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  62. $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
  63. }
  64. /**
  65. * General CRUD.
  66. */
  67. function testCRUDGroup() {
  68. $this->createGroup();
  69. $this->deleteGroup();
  70. }
  71. /**
  72. * Nest a field underneath a group.
  73. */
  74. function testNestField() {
  75. $this->createGroup();
  76. $edit = array(
  77. 'fields[field_image][parent]' => $this->group_name,
  78. );
  79. $this->drupalPost('admin/structure/types/manage/article/fields', $edit, t('Save'));
  80. $this->assertRaw(t('Your settings have been saved.'), t('Settings saved'));
  81. $groups = field_group_info_groups('node', 'article', 'form', TRUE);
  82. $this->assertTrue(in_array('field_image', $groups[$this->group_name]->children), t('Image is a child of %group', array('%group' => $this->group_name)));
  83. }
  84. }