LibrariesWebTestBase.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Contains LibrariesWebTestBase.
  5. *
  6. * Simpletest automatically discovers test files using PSR-4. We cannot,
  7. * however, declare a namespace for this class, as that would require PHP 5.3.
  8. * To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
  9. * place the test files in the correct directory already, but for now register
  10. * them explicitly in libraries.info
  11. */
  12. /**
  13. * Base class for Libraries API web tests.
  14. */
  15. abstract class LibrariesWebTestBase extends DrupalWebTestCase {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected $profile = 'testing';
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function setUp() {
  24. parent::setUp('libraries', 'libraries_test_module');
  25. theme_enable(array('libraries_test_theme'));
  26. }
  27. /**
  28. * Retrieves a path making sure a set of permissions is required to access it.
  29. *
  30. * After calling this method, a user with the given permissions is logged in
  31. * and the retrieved page is loaded into the internal browser.
  32. *
  33. * @param array $permissions
  34. * An array of permission names to assign to user. Note that the user always
  35. * has the default permissions derived from the "authenticated users" role.
  36. * @param string $path
  37. * Drupal path or URL to load into the internal browser.
  38. * @param array $options
  39. * Options to be forwarded to url().
  40. * @param array $headers
  41. * An array containing additional HTTP request headers, each formatted as
  42. * "name: value".
  43. *
  44. * @return string
  45. * The retrieved HTML string, also available as $this->drupalGetContent().
  46. *
  47. * @see \DrupalWebTestCase::drupalGet()
  48. * @see \DrupalWebTestCase::drupalCreateUser()
  49. */
  50. protected function getWithPermissions(array $permissions, $path, array $options = array(), array $headers = array()) {
  51. $this->drupalGet($path, $options, $headers);
  52. $this->assertResponse(403);
  53. $this->drupalLogin($this->drupalCreateUser($permissions));
  54. $this->drupalGet($path, $options, $headers);
  55. $this->assertResponse(200);
  56. }
  57. }