extlink.test 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Base class for External Link tests.
  4. *
  5. * Provides common setup stuff and various helper functions
  6. */
  7. class ExtlinkBaseWebTestCase extends DrupalWebTestCase {
  8. /**
  9. * User with various administrative permissions.
  10. * @var Drupal user
  11. */
  12. protected $admin_user;
  13. /**
  14. * Normal visitor with limited permissions
  15. * @var Drupal user;
  16. */
  17. protected $normal_user;
  18. /**
  19. * Drupal path of the (general) External Links admin page
  20. */
  21. const EXTLINK_ADMIN_PATH = 'admin/config/user-interface/extlink';
  22. function setUp() {
  23. // Enable any module that you will need in your tests.
  24. parent::setUp('extlink');
  25. // Create a normal user.
  26. $permissions = array(
  27. 'access comments', 'post comments', 'skip comment approval',
  28. 'access content', 'create page content', 'edit own page content',
  29. );
  30. $this->normal_user = $this->drupalCreateUser($permissions);
  31. // Create an admin user.
  32. $permissions[] = 'administer site configuration';
  33. $permissions[] = 'administer permissions';
  34. $permissions[] = 'administer content types';
  35. $this->admin_user = $this->drupalCreateUser($permissions);
  36. }
  37. protected function getNodeFormValues() {
  38. $edit = array(
  39. 'title' => 'node_title ' . $this->randomName(32),
  40. 'body[' . LANGUAGE_NONE . '][0][value]' => 'node_body ' . $this->randomName(256) . ' <a href="http://google.com">Google!</a>',
  41. );
  42. return $edit;
  43. }
  44. /**
  45. * Test if External Link is present
  46. */
  47. protected function assertExternalLinkPresence() {
  48. $elements = $this->xpath('//span[@class="ext"]');
  49. if (count($elements) > 0)
  50. $this->pass('There should be an External Link on the form.', 'External Links');
  51. else
  52. $this->fail('There should be an External Link on the form.', 'External Links');
  53. }
  54. }
  55. class ExtlinkTestCase extends ExtlinkBaseWebTestCase {
  56. public static function getInfo() {
  57. return array(
  58. 'name' => t('General External Links functionality'),
  59. 'description' => t('Testing the basic functionality of External Links'),
  60. 'group' => t('External Links'),
  61. );
  62. }
  63. }
  64. class ExtlinkAdminTestCase extends ExtlinkBaseWebTestCase {
  65. public static function getInfo() {
  66. return array(
  67. 'name' => t('External Links administration functionality'),
  68. 'description' => t('Testing of the External Links administration interface and functionality.'),
  69. 'group' => t('External Links'),
  70. );
  71. }
  72. /**
  73. * Test access to the admin pages.
  74. */
  75. function testAdminAccess() {
  76. $this->drupalLogin($this->normal_user);
  77. $this->drupalGet(self::EXTLINK_ADMIN_PATH);
  78. file_put_contents('tmp.simpletest.html', $this->drupalGetContent());
  79. $this->assertText(t('Access denied'), 'Normal users should not be able to access the External Links admin pages', 'External Links');
  80. $this->drupalLogin($this->admin_user);
  81. $this->drupalGet(self::EXTLINK_ADMIN_PATH);
  82. file_put_contents('tmp.simpletest.html', $this->drupalGetContent());
  83. $this->assertNoText(t('Access denied'), 'Admin users should be able to access the External Links admin pages', 'External Links');
  84. }
  85. }
  86. ?>