TitleAdminSettingsTestCase.test 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Tests for legacy field replacement.
  4. */
  5. class TitleAdminSettingsTestCase extends DrupalWebTestCase {
  6. /**
  7. *
  8. */
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'Admin settings',
  12. 'description' => 'Test the administration settings.',
  13. 'group' => 'Title',
  14. );
  15. }
  16. /**
  17. * Use the barebones "testing" installation profile.
  18. */
  19. protected $profile = 'testing';
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function setUp(array $modules = array()) {
  24. // Core.
  25. $modules[] = 'field_test';
  26. $modules[] = 'taxonomy';
  27. // This module.
  28. $modules[] = 'title';
  29. $modules[] = 'title_test';
  30. parent::setUp($modules);
  31. /**
  32. * Reset the permissions cache prior to calling drupalCreateUser.
  33. * @see https://api.drupal.org/comment/28739#comment-28739
  34. */
  35. $this->checkPermissions(array(), TRUE);
  36. $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'administer fields'));
  37. $this->drupalLogin($admin_user);
  38. }
  39. /**
  40. * Check for automated title_field attachment.
  41. */
  42. public function testAutomatedFieldAttachment() {
  43. $this->doTestAutomatedFieldAttachment(TRUE);
  44. $this->doTestAutomatedFieldAttachment(FALSE);
  45. }
  46. /**
  47. * Check that the fields are replaced or skipped depending on the given value.
  48. *
  49. * @param bool $enabled
  50. * Whether replacement is enabled or not.
  51. */
  52. public function doTestAutomatedFieldAttachment($enabled) {
  53. $edit = array(
  54. 'title_taxonomy_term[auto_attach][name]' => $enabled,
  55. 'title_taxonomy_term[auto_attach][description]' => $enabled,
  56. );
  57. $this->drupalPost('admin/config/content/title', $edit, t('Save configuration'));
  58. $edit = array(
  59. 'name' => $this->randomName(),
  60. 'machine_name' => drupal_strtolower($this->randomName()),
  61. 'description' => $this->randomString(16),
  62. );
  63. $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
  64. $entity_type = 'taxonomy_term';
  65. $bundle = $edit['machine_name'];
  66. field_info_cache_clear();
  67. $this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'name') == $enabled, 'Name field correctly processed.');
  68. $this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'description') == $enabled, 'Description field correctly processed.');
  69. }
  70. }