1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* print module simpletest tests
|
6 |
|
|
*
|
7 |
|
|
* This file includes the defined tests for the print module.
|
8 |
|
|
*
|
9 |
|
|
* @ingroup print
|
10 |
|
|
*/
|
11 |
|
|
|
12 |
|
|
class PrintBasicTest extends DrupalWebTestCase {
|
13 |
|
|
protected $web_user;
|
14 |
|
|
protected $getq;
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Implementation of getInfo().
|
18 |
|
|
*/
|
19 |
|
|
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 |
|
|
/**
|
28 |
|
|
* Implementation of setUp().
|
29 |
|
|
*/
|
30 |
|
|
function setUp() {
|
31 |
|
|
parent::setUp();
|
32 |
|
|
|
33 |
|
|
// User to set up print.
|
34 |
|
|
// $this->web_user = $this->drupalCreateUserRolePerm(array('administer print'));
|
35 |
|
|
|
36 |
|
|
// $this->drupalGet('logout');
|
37 |
|
|
// $this->drupalLoginUser($this->web_user);
|
38 |
|
|
|
39 |
|
|
$this->getq = $_GET['q'];
|
40 |
|
|
$_GET['q'] = 'print/' . $_GET['q'];
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Implementation of tearDown().
|
45 |
|
|
*/
|
46 |
|
|
function tearDown() {
|
47 |
|
|
$_GET['q'] = $this->getq;
|
48 |
|
|
|
49 |
|
|
parent::tearDown();
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
function testPrintRewriteUrls() {
|
53 |
|
|
global $base_url, $base_root, $_print_urls;
|
54 |
|
|
|
55 |
|
|
// Must require it, since this function gets called via Drupal's dynamic loading
|
56 |
|
|
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'print') . '/print.pages.inc');
|
57 |
|
|
|
58 |
|
|
variable_set('print_urls_anchors', 1);
|
59 |
|
|
|
60 |
|
|
$_print_urls = TRUE;
|
61 |
|
|
|
62 |
|
|
$pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
|
63 |
|
|
$footnote = ' <span class="print-footnote">[1]</span>';
|
64 |
|
|
$part1 = '<a class=\'class1 class2\' target=_blank hreflang="en" id="some complicated \"href=lala.com\" text" href="';
|
65 |
|
|
$part2 = '">Example</a>';
|
66 |
|
|
|
67 |
|
|
$url[0] = 'http://www.example.com';
|
68 |
|
|
$url[1] = '#here';
|
69 |
|
|
$url[2] = '/relative/to/host';
|
70 |
|
|
$url[3] = 'relative/to/base';
|
71 |
|
|
$url[4] = 'index.php?q=sample/path';
|
72 |
|
|
$rel_url[0] = $url[0];
|
73 |
|
|
$rel_url[1] = base_path() . $_GET['q'] . $url[1];
|
74 |
|
|
$rel_url[2] = $base_root . $url[2];
|
75 |
|
|
$rel_url[3] = $base_url . '/' . $url[3];
|
76 |
|
|
$rel_url[4] = $base_url . '/' . $url[4];
|
77 |
|
|
$abs_url[0] = $url[0];
|
78 |
|
|
$abs_url[1] = $base_url . '/' . $this->getq . $url[1];
|
79 |
|
|
$abs_url[2] = $base_root . $url[2];
|
80 |
|
|
$abs_url[3] = $base_url . '/' . $url[3];
|
81 |
|
|
$abs_url[4] = $base_url . '/' . $url[4];
|
82 |
|
|
|
83 |
|
|
$url[5] = '#here with spaces';
|
84 |
|
|
$url[6] = '/relative/to/host with spaces';
|
85 |
|
|
$url[7] = 'relative/to/base with spaces';
|
86 |
|
|
$url[8] = 'index.php?q=sample/path with spaces';
|
87 |
|
|
$rel_url[5] = base_path() . $_GET['q'] . $url[5];
|
88 |
|
|
$rel_url[6] = $base_root . $url[6];
|
89 |
|
|
$rel_url[7] = $base_url . '/' . $url[7];
|
90 |
|
|
$rel_url[8] = $base_url . '/' . $url[8];
|
91 |
|
|
$abs_url[5] = $base_url . '/' . $this->getq . $url[5];
|
92 |
|
|
$abs_url[6] = $base_root . $url[6];
|
93 |
|
|
$abs_url[7] = $base_url . '/' . $url[7];
|
94 |
|
|
$abs_url[8] = $base_url . '/' . $url[8];
|
95 |
|
|
|
96 |
|
|
$url[9] = 'mailto:support@example.com';
|
97 |
|
|
$rel_url[9] = $url[9];
|
98 |
|
|
$abs_url[9] = $url[9];
|
99 |
|
|
|
100 |
|
|
$url[10] = '';
|
101 |
|
|
$rel_url[10] = '';
|
102 |
|
|
$abs_url[10] = $base_url . '/' . $this->getq;
|
103 |
|
|
|
104 |
|
|
$size = count($url);
|
105 |
|
|
for ($i = 0; $i < $size; $i++) {
|
106 |
|
|
preg_match($pattern, $part1 . $url[$i] . $part2, $matches);
|
107 |
|
|
$ret = _print_rewrite_urls($matches);
|
108 |
|
|
$urls = _print_friendly_urls();
|
109 |
|
|
$this->assertEqual($ret, $part1 . $rel_url[$i] . $part2 . $footnote, t('Original URL (!url)', array('!url' => $rel_url[$i])));
|
110 |
|
|
$this->assertEqual($urls[0], $abs_url[$i], t('Absolute URL (!url)', array('!url' => $abs_url[$i])));
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
} |