metatag.with_profile2.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Metatag module for Profile2 integration.
  5. */
  6. /**
  7. * Tests for the Metatag module for Profile2 integration.
  8. *
  9. * Inherit from the User test so that its tests can be confirmed to still work
  10. * when the Profile2 module is enabled.
  11. */
  12. class MetatagCoreWithProfile2Test extends MetatagCoreUserTest {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Metatag core tests with Profile2',
  19. 'description' => 'Test Metatag integration with the Profile2 module.',
  20. 'group' => 'Metatag',
  21. 'dependencies' => array('ctools', 'token', 'profile2'),
  22. );
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. function setUp(array $modules = array()) {
  28. $modules[] = 'profile2';
  29. parent::setUp($modules);
  30. // Add extra permissions for the admin user, this way it can be ready for
  31. // use by the other user tests.
  32. $perms = array(
  33. // Let the user edit & view their own profile.
  34. 'edit own main profile',
  35. 'view own main profile',
  36. // Manage profile entity definitions.
  37. 'administer profile types',
  38. // Need this permission to access the Field UI pages for Profile2.
  39. 'administer site configuration',
  40. 'administer fields',
  41. 'administer profiles',
  42. );
  43. $this->adminUser = $this->createAdminUser($perms);
  44. // Log in the admin user.
  45. $this->drupalLogin($this->adminUser);
  46. }
  47. /**
  48. * Make sure that the Profile2 entity doesn't interfere with the user entity.
  49. */
  50. public function testUserProfilePage() {
  51. // Add a custom meta tag to the user's profile.
  52. $this->drupalGet('user/' . $this->adminUser->uid . '/edit');
  53. $this->assertResponse(200);
  54. // Verify that it's possible to submit values to the form.
  55. $this->drupalPost(NULL, array(
  56. 'metatags[und][abstract][value]' => '[user:name] ponies',
  57. ), t('Save'));
  58. $this->assertResponse(200);
  59. // Verify that the user object saved correctly.
  60. $this->assertText(strip_tags(t('The changes have been saved.')));
  61. // Confirm the user profile tags work correctly.
  62. $this->assertUserEntityTags($this->adminUser);
  63. // Load the 'main' Profile2 fields admin page.
  64. $this->drupalGet('admin/structure/profiles');
  65. $this->assertResponse(200);
  66. // Load the 'main' Profile2 fields admin page.
  67. $this->drupalGet('admin/structure/profiles/manage/main');
  68. $this->assertResponse(200);
  69. // Load the 'main' Profile2 fields admin page.
  70. $this->drupalGet('admin/structure/profiles/manage/main/fields');
  71. $this->assertResponse(200);
  72. // Verify that the page loaded correctly.
  73. $this->assertFieldByName('fields[_add_new_field][label]');
  74. $this->assertFieldByName('fields[_add_new_field][field_name]');
  75. $this->assertFieldByName('fields[_add_new_field][type]');
  76. $this->assertFieldByName('fields[_add_new_field][widget_type]');
  77. // Add a text field to the Main profile.
  78. $edit = array(
  79. 'fields[_add_new_field][label]' => 'Test field',
  80. 'fields[_add_new_field][field_name]' => 'test',
  81. 'fields[_add_new_field][type]' => 'text',
  82. 'fields[_add_new_field][widget_type]' => 'text_textfield',
  83. );
  84. $this->drupalPost(NULL, $edit, t('Save'));
  85. $this->drupalPost(NULL, array(), t('Save field settings'));
  86. $this->drupalPost(NULL, array(), t('Save settings'));
  87. $this->assertText(strip_tags(t('Saved %label configuration.', array('%label' => 'Test field'))));
  88. // Edit the user's Profile2 entity.
  89. $this->drupalGet('user/' . $this->adminUser->uid . '/edit/main');
  90. $this->assertResponse(200);
  91. $this->assertFieldByName('profile_main[field_test][und][0][value]');
  92. $edit = array(
  93. 'profile_main[field_test][und][0][value]' => 'test string',
  94. );
  95. $this->drupalPost(NULL, $edit, t('Save'));
  96. // Add a custom meta tag to the user's profile.
  97. $this->drupalGet('user/' . $this->adminUser->uid . '/edit');
  98. $this->assertResponse(200);
  99. // Verify that it's possible to submit values to the form.
  100. $edit = array(
  101. 'metatags[und][abstract][value]' => '[user:name] ponies',
  102. );
  103. $this->drupalPost(NULL, $edit, t('Save'));
  104. $this->assertResponse(200);
  105. // Verify that the user object saved correctly.
  106. $this->assertText(strip_tags(t('The changes have been saved.')));
  107. // Clear all caches.
  108. drupal_flush_all_caches();
  109. // Confirm the user profile tags still work correctly.
  110. $this->assertUserEntityTags($this->adminUser);
  111. }
  112. }