metatag.user.test 3.0 KB

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