Project

General

Profile

Paste
Download (3.54 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / print / tests / print_basic.test @ 76bdcd04

1
<?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
/**
13
 * Class PrintBasicTest.
14
 */
15
class PrintBasicTest extends DrupalWebTestCase {
16
  protected $webUser;
17
  protected $getq;
18

    
19
  /**
20
   * Implementation of getInfo().
21
   */
22
  public function getInfo() {
23
    return array(
24
      'name' => t('Printer, email and PDF versions tests'),
25
      'description' => t('Unit tests for the print, print_mail and print_pdf modules.'),
26
      'group' => t('Printer, email and PDF versions'),
27
    );
28
  }
29

    
30
  /**
31
   * Implementation of setUp().
32
   */
33
  public function setUp() {
34
    parent::setUp();
35

    
36
    // User to set up print.
37
    /*
38
    $this->webUser = $this->drupalCreateUserRolePerm(array('administer print'));
39

    
40
    $this->drupalGet('logout');
41
    $this->drupalLoginUser($this->webUser);
42
     */
43

    
44
    $this->getq = $_GET['q'];
45
    $_GET['q'] = 'print/' . $_GET['q'];
46
  }
47

    
48
  /**
49
   * Implementation of tearDown().
50
   */
51
  public function tearDown() {
52
    $_GET['q'] = $this->getq;
53

    
54
    parent::tearDown();
55
  }
56

    
57
  /**
58
   * Test rewrite of URLs.
59
   */
60
  public function testPrintRewriteUrls() {
61
    global $base_url, $base_root, $_print_urls;
62

    
63
    // Must require it, since this function gets called via Drupal's dynamic
64
    // loading.
65
    module_load_include('inc', 'print', 'print.pages');
66

    
67
    variable_set('print_urls_anchors', 1);
68

    
69
    $_print_urls = TRUE;
70

    
71
    $pattern = '!<(a\s[^>]*?)>(.*?)(</a>)!is';
72
    $footnote = ' <span class="print-footnote">[1]</span>';
73
    $part1 = '<a class=\'class1 class2\' target=_blank hreflang="en" id="some complicated \"href=lala.com\" text" href="';
74
    $part2 = '">Example</a>';
75

    
76
    $url[0] = 'http://www.example.com';
77
    $url[1] = '#here';
78
    $url[2] = '/relative/to/host';
79
    $url[3] = 'relative/to/base';
80
    $url[4] = 'index.php?q=sample/path';
81
    $rel_url[0] = $url[0];
82
    $rel_url[1] = base_path() . $_GET['q'] . $url[1];
83
    $rel_url[2] = $base_root . $url[2];
84
    $rel_url[3] = $base_url . '/' . $url[3];
85
    $rel_url[4] = $base_url . '/' . $url[4];
86
    $abs_url[0] = $url[0];
87
    $abs_url[1] = $base_url . '/' . $this->getq . $url[1];
88
    $abs_url[2] = $base_root . $url[2];
89
    $abs_url[3] = $base_url . '/' . $url[3];
90
    $abs_url[4] = $base_url . '/' . $url[4];
91

    
92
    $url[5] = '#here with spaces';
93
    $url[6] = '/relative/to/host with spaces';
94
    $url[7] = 'relative/to/base with spaces';
95
    $url[8] = 'index.php?q=sample/path with spaces';
96
    $rel_url[5] = base_path() . $_GET['q'] . $url[5];
97
    $rel_url[6] = $base_root . $url[6];
98
    $rel_url[7] = $base_url . '/' . $url[7];
99
    $rel_url[8] = $base_url . '/' . $url[8];
100
    $abs_url[5] = $base_url . '/' . $this->getq . $url[5];
101
    $abs_url[6] = $base_root . $url[6];
102
    $abs_url[7] = $base_url . '/' . $url[7];
103
    $abs_url[8] = $base_url . '/' . $url[8];
104

    
105
    $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;';
106
    $rel_url[9] = $url[9];
107
    $abs_url[9] = $url[9];
108

    
109
    $url[10] = '';
110
    $rel_url[10] = '';
111
    $abs_url[10] = $base_url . '/' . $this->getq;
112

    
113
    $size = count($url);
114
    for ($i = 0; $i < $size; $i++) {
115
      preg_match($pattern, $part1 . $url[$i] . $part2, $matches);
116
      $ret = _print_rewrite_urls($matches);
117
      $urls = _print_friendly_urls();
118
      $this->assertEqual($ret, $part1 . $rel_url[$i] . $part2 . $footnote, t('Original URL (!url)', array('!url' => $rel_url[$i])));
119
      $this->assertEqual($urls[0], $abs_url[$i], t('Absolute URL (!url)', array('!url' => $abs_url[$i])));
120
    }
121
  }
122

    
123
}