print_basic.test 3.4 KB

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