summaryrefslogtreecommitdiff
path: root/test/UtilTest.php
blob: af03332fbd14c69c3b9fbaac549325b4ba6a7aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

require_once('PHPUnit/Framework.php');

require_once(__DIR__ . '/../src/Util.php');

class UtilTest extends PHPUnit_Framework_TestCase {

  public function has_rfc822_specials_provider() {
    return array(
      array('Joel Uckelman', false),
      array('L.Tankersley', true),
      array('()<>@,;:\".[]', true)
    );
  }

  /** @dataProvider has_rfc822_specials_provider */
  public function test_has_rfc822_specials($string, $expected) {
    $this->assertEquals($expected, has_rfc822_specials($string));
  }

  public function rfc822_quote_provider() {
    return array(
      array('Joel Uckelman', 'Joel Uckelman'),
      array('L.Tankersley',  '"L.Tankersley"'),
      array('"\foo\"',       '"\"\\foo\\\""')
    );
  }

  /** @dataProvider rfc822_quote_provider */
  public function test_rfc822_quote($string, $expected) {
    $this->assertEquals($expected, rfc822_quote($string));
  }

  public function is_ascii_provider() {
    return array(
      array('', true),
      array('foo', true),
      array('Heizölrückstoßabdämpfung', false)
    );
  }

  /** @dataProvider is_ascii_provider */
  public function test_is_ascii($string, $expected) {
    $this->assertEquals($expected, is_ascii($string));   
  }

  public function utf8_quote_provider() {
    return array(
      array('', '=?UTF-8?B??='),
      array('foo', '=?UTF-8?B?Zm9v?='),
      array('Heizölrückstoßabdämpfung', '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?=')
    );
  }

  /** @dataProvider utf8_quote_provider */
  public function test_utf8_quote($string, $expected) {
    $this->assertEquals($expected, utf8_quote($string));
  }

  public function utf8_quote_non_ascii_provider() {
    return array(
      array('', ''),
      array('foo', 'foo'),
      array('Heizölrückstoßabdämpfung', '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?=')
    );
  }

  /** @dataProvider utf8_quote_non_ascii_provider */
  public function test_utf8_quote_non_ascii($string, $expected) {
    $this->assertEquals($expected, utf8_quote_non_ascii($string));
  }
}

?>