print_basic.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @file
  4. * Print module simpletest tests.
  5. *
  6. * This file includes the defined tests for the print module.
  7. *
  8. * @ingroup print
  9. */
  10. /**
  11. * Class PrintBasicTest.
  12. */
  13. class PrintBasicTest extends DrupalWebTestCase {
  14. protected $webUser;
  15. protected $getq;
  16. /**
  17. * Implementation of getInfo().
  18. */
  19. public function getInfo() {
  20. return array(
  21. 'name' => t('Printer, email and PDF versions tests'),
  22. 'description' => t('Unit tests for the print, print_mail and print_pdf modules.'),
  23. 'group' => t('Printer, email and PDF versions'),
  24. );
  25. }
  26. /**
  27. * Implementation of setUp().
  28. */
  29. public function setUp() {
  30. parent::setUp();
  31. // User to set up print.
  32. /*
  33. $this->webUser = $this->drupalCreateUserRolePerm(array('administer print'));
  34. $this->drupalGet('logout');
  35. $this->drupalLoginUser($this->webUser);
  36. */
  37. $this->getq = $_GET['q'];
  38. $_GET['q'] = 'print/' . $_GET['q'];
  39. }
  40. /**
  41. * Implementation of tearDown().
  42. */
  43. public function tearDown() {
  44. $_GET['q'] = $this->getq;
  45. parent::tearDown();
  46. }
  47. /**
  48. * Test rewrite of URLs.
  49. */
  50. public function testPrintRewriteUrls() {
  51. global $base_url, $base_root, $_print_urls;
  52. // Must require it, since this function gets called via Drupal's dynamic
  53. // loading.
  54. module_load_include('inc', 'print', 'print.pages');
  55. variable_set('print_urls_anchors', 1);
  56. $_print_urls = TRUE;
  57. $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
  58. $footnote = ' <span class="print-footnote">[1]</span>';
  59. $part1 = '<a class=\'class1 class2\' target=_blank hreflang="en" id="some complicated \"href=lala.com\" text" href="';
  60. $part2 = '">Example</a>';
  61. $url[0] = 'http://www.example.com';
  62. $url[1] = '#here';
  63. $url[2] = '/relative/to/host';
  64. $url[3] = 'relative/to/base';
  65. $url[4] = 'index.php?q=sample/path';
  66. $rel_url[0] = $url[0];
  67. $rel_url[1] = base_path() . $_GET['q'] . $url[1];
  68. $rel_url[2] = $base_root . $url[2];
  69. $rel_url[3] = $base_url . '/' . $url[3];
  70. $rel_url[4] = $base_url . '/' . $url[4];
  71. $abs_url[0] = $url[0];
  72. $abs_url[1] = $base_url . '/' . $this->getq . $url[1];
  73. $abs_url[2] = $base_root . $url[2];
  74. $abs_url[3] = $base_url . '/' . $url[3];
  75. $abs_url[4] = $base_url . '/' . $url[4];
  76. $url[5] = '#here with spaces';
  77. $url[6] = '/relative/to/host with spaces';
  78. $url[7] = 'relative/to/base with spaces';
  79. $url[8] = 'index.php?q=sample/path with spaces';
  80. $rel_url[5] = base_path() . $_GET['q'] . $url[5];
  81. $rel_url[6] = $base_root . $url[6];
  82. $rel_url[7] = $base_url . '/' . $url[7];
  83. $rel_url[8] = $base_url . '/' . $url[8];
  84. $abs_url[5] = $base_url . '/' . $this->getq . $url[5];
  85. $abs_url[6] = $base_root . $url[6];
  86. $abs_url[7] = $base_url . '/' . $url[7];
  87. $abs_url[8] = $base_url . '/' . $url[8];
  88. $url[9] = '&#109;&#97;&#x69;&#x6c;&#x74;&#111;&#58;&#115;&#x75;&#x70;p&#111;&#114;&#x74;&#x40;e&#120;&#97;&#x6d;&#x70;&#x6c;&#101;&#46;&#x63;&#x6f;&#x6d;';
  89. $rel_url[9] = $url[9];
  90. $abs_url[9] = $url[9];
  91. $url[10] = '';
  92. $rel_url[10] = '';
  93. $abs_url[10] = $base_url . '/' . $this->getq;
  94. $size = count($url);
  95. for ($i = 0; $i < $size; $i++) {
  96. preg_match($pattern, $part1 . $url[$i] . $part2, $matches);
  97. $ret = _print_rewrite_urls($matches);
  98. $urls = _print_friendly_urls();
  99. $this->assertEqual($ret, $part1 . $rel_url[$i] . $part2 . $footnote, t('Original URL (!url)', array('!url' => $rel_url[$i])));
  100. $this->assertEqual($urls[0], $abs_url[$i], t('Absolute URL (!url)', array('!url' => $abs_url[$i])));
  101. }
  102. }
  103. }