metatag.user.test 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Tests for the Metatag module of user entities.
  4. */
  5. class MetatagCoreUserTest extends MetatagTestHelper {
  6. /**
  7. * {@inheritdoc}
  8. */
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'Metatag core tests for users',
  12. 'description' => 'Test Metatag edit functionality for users.',
  13. 'group' => 'Metatag',
  14. 'dependencies' => array('ctools', 'token'),
  15. );
  16. }
  17. /**
  18. * Tests creation of a standard entity.
  19. */
  20. public function testEntityCreationWorkflow() {
  21. // Create an admin user and log them in.
  22. if (!isset($this->adminUser)) {
  23. $this->adminUser = $this->createAdminUser();
  24. }
  25. $this->drupalLogin($this->adminUser);
  26. // Assign default values for the new vocabulary.
  27. // Load the page for overriding the User configuration.
  28. $this->drupalGet('admin/config/search/metatags/config/user');
  29. $this->assertResponse(200);
  30. // Verify the page loaded correct.
  31. // @todo Update this to extract the H1 tag.
  32. $this->assertText(strip_tags('User'));
  33. // Submit the form with some values.
  34. $this->drupalPost(NULL, array(
  35. 'metatags[und][abstract][value]' => '[user:name]',
  36. ), t('Save'));
  37. $this->assertResponse(200);
  38. // Verify the page loaded correct.
  39. $this->assertText(strip_tags(t('The meta tag defaults for @label have been saved.', array('@label' => 'User'))));
  40. // Verify that the user was redirected to the settings page again.
  41. $this->assertEqual($this->getUrl(), url('admin/config/search/metatags', array('absolute' => TRUE)));
  42. // Load the user's edit form.
  43. $this->drupalGet('user/' . $this->adminUser->uid . '/edit');
  44. $this->assertResponse(200);
  45. // Verify the page loaded correctly.
  46. // @todo Update this to extract the H1 tag.
  47. // $this->assertText(strip_tags(t('Create @name', array('@name' => $vocabulary->name))));
  48. // Verify that it's possible to submit values to the form.
  49. $this->drupalPost(NULL, array(
  50. 'metatags[und][abstract][value]' => '[user:name] ponies',
  51. ), t('Save'));
  52. $this->assertResponse(200);
  53. // Verify that the user object saved correctly.
  54. // $t_args = array('%name' => $this->adminUser->name);
  55. // This doesn't work for some reason, it seems the HTML is stripped off
  56. // during output so the %name's standard Drupal wrappers don't match.
  57. // $this->assertText(t('The changes have been saved.'));
  58. // .. so this has to be done instead.
  59. $this->assertText(strip_tags(t('The changes have been saved.')));
  60. // Manually load the admin account.
  61. $account = user_load($this->adminUser->uid);
  62. // Only the non-default values are stored.
  63. $expected = array(
  64. 'und' => array(
  65. 'abstract' => array(
  66. 'value' => '[user:name] ponies',
  67. ),
  68. ),
  69. );
  70. $this->assertEqual($expected, $account->metatags);
  71. // Confirm the user profile tags work correctly.
  72. $this->assertUserEntityTags($this->adminUser);
  73. }
  74. }