Jacek Kowalski
2016-02-13 9f47c0fd4f94f45ce02c8c67ae59f5fc74f8ad9e
commit | author | age
0868e0 1 <?php
JK 2 class BotMsgTest extends PHPUnit_Framework_TestCase {
3     function testAppend() {
4         $text = '';
5
6         $substring = 'abc';
7         $msg = new BotMsg($substring);
8         $text .= $substring;
9         
10         $substring = 'cba';
11         $msg->a($substring);
12         $text .= $substring;
13         
14         $substring = 'cba';
15         $msg->append($substring);
16         $text .= $substring;
17
18         $this->assertEquals($text, $msg->getRaw());
19     }
20     
21     function testBeautifilText() {
22         $msg = new BotMsg('<h1>Test</h1><p><u><i>This.</i></u></p><p><b>That!</b></p>');
23         $expect = '= Test ='."\n"
24             .'_/This./_'."\n\n"
25             .'*That!*';
26         $msg->setBeautiful(TRUE);
27         $this->assertEquals($expect, $msg->getText());
28         
29         $expect = 'Test'."\n"
30             .'This.'."\n\n"
31             .'That!';
32         $msg->setBeautiful(FALSE);
33         $this->assertEquals($expect, $msg->getText());
34         
35     }
36     
37     function testGetText() {
38         $msg = new BotMsg('<h2>Test</h2>'."\n"
39             .'<h3>Test h3</h3>'."\n"
40             .'<p><a href="http://jacekk.info">http://jacekk.info</a><br />'."\n"
41             .'<a href="http://jacekk.info">Jacekk.info</a></p>');
42         $expect = '== Test =='."\n"
43             .'=== Test h3 ==='."\n"
44             .'http://jacekk.info'."\n"
45             .'Jacekk.info (http://jacekk.info)';
46         $this->assertEquals($expect, $msg->getText());
47         
48         $msg = new BotMsg('<table>'."\n"
49             .'<tr><th>Header 1</th> <th>Header 2</th></tr>'."\n"
50             .'<tr><td>Cell 1</td> <td>Cell 2<img src="" /></td></tr>'."\n"
51             .'</table>');
52         $expect = '*Header 1*     *Header 2*'."\n"
53             .'Cell 1     Cell 2';
54         $this->assertEquals($expect, $msg->getText());
55         
56         $msg = new BotMsg('<h3>Test h3</h3>abc<p>Test</p>');
57         $expect = '=== Test h3 ==='."\n"
58             .'abc'."\n\n"
59             .'Test';
60         $this->assertEquals($expect, $msg->getText());
61     }
62     
63     function testGetHTML() {
64         $msg = new BotMsg('<h1>Test</h1>'."\n"
65             .'<p><u><i>This.</i></u></p>'."\n"
66             .'<p><b color="#fff">That!</b></p>'."\n"
67             .'<p><a>http://jacekk.info</a></p>');
68         $expect = '<h1>Test</h1>'."\n"
69             .'<p><u><i>This.</i></u></p>'."\n"
70             .'<p><b style="color:#fff;">That!</b></p>'."\n"
71             .'<p><a href="http://jacekk.info">http://jacekk.info</a></p>';
72         
73         $this->assertEquals($expect, $msg->getHTML());
74         $this->assertEquals($expect, (string)$msg);
75     }
76     
77     function testHTMLError() {
78         $oldhandler = set_error_handler('errorToException');
79         
80         $msg = new BotMsg('<![CDATA[ <p></p> ]]>');
81         $msg->getHTML();
82         
83         set_error_handler($oldhandler);
84     }
85     
86     function testSleep() {
87         $msg = new BotMsg('<h1>Test</h1><p><u><i>This.</i></u></p><p><b>That!</b></p>');
88         $raw = $msg->getRaw();
89         $text = $msg->getText();
90         $html = $msg->getHTML();
91         
92         $serialized = serialize($msg);
93         $msg = unserialize($serialized);
94         
95         $this->assertEquals($raw, $msg->getRaw());
96         $this->assertEquals($text, $msg->getText());
97         $this->assertEquals($html, $msg->getHTML());
98     }
99 }