metatag.with_profile2.test 4.3 KB

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