ContainerTest.php
4.96 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Test class for PHPRtfLite_Container
*/
class PHPRtfLite_ContainerTest extends PHPUnit_Framework_TestCase
{
/**
* @var PHPRtfLite_Container mock object
*/
protected $_container;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$rtf = new PHPRtfLite();
$writer = new PHPRtfLite_Writer_String();
$rtf->setWriter($writer);
$this->_container = $this->getMockForAbstractClass('PHPRtfLite_Container',
array(),
'',
false);
$this->_container->__construct($rtf);
}
/**
* tests writeRtfCode
*/
public function testWriteRftCode()
{
$this->_container->writeRtfCode('test text');
$this->_container->render();
$this->assertEquals('{test text}', trim($this->_container->getRtf()->getWriter()->getContent()));
}
/**
* tests addEmptyParagraph
*/
public function testAddEmptyParagraph()
{
$this->_container->addEmptyParagraph();
$this->_container->render();
$this->assertEquals('\pard \ql {\par}', trim($this->_container->getRtf()->getWriter()->getContent()));
}
/**
* tests addEmptyParagraph
*/
public function testAddEmptyParagraphWithFontAndParFormat()
{
$font = new PHPRtfLite_Font();
$parFormat = new PHPRtfLite_ParFormat();
$this->_container->addEmptyParagraph($font, $parFormat);
$this->_container->render();
$this->assertEquals('\pard \ql {\fs20 \par}', trim($this->_container->getRtf()->getWriter()->getContent()));
}
/**
* tests writeText
*
* @return PHPRtfLite_Container
*/
public function testWriteTextForEmptyParagraph()
{
$this->_container->writeText('Hello world!');
$this->_container->render();
$this->assertEquals('{Hello world!}', trim($this->_container->getRtf()->getWriter()->getContent()));
return $this->_container;
}
/**
* tests addEmptyParagraph
* @depends testWriteTextForEmptyParagraph
*
* @param PHPRtfLite_Container $container
*/
public function testWriteTextAddEmptyParagraphWithFontAndParFormat(PHPRtfLite_Container $container)
{
$font = new PHPRtfLite_Font();
$parFormat = new PHPRtfLite_ParFormat();
$container->addEmptyParagraph($font, $parFormat);
$container->render();
$this->assertEquals('{Hello world!}' . "\r\n" . '\par \pard \ql {\fs20 \par}',
trim($container->getRtf()->getWriter()->getContent()));
}
/**
* @dataProvider provideWriteText
* tests writeText
*/
public function testWriteText($input, $expected)
{
#$this->_container->getRtf()->getWriter()->content = '';
$this->_container->writeText($input);
$this->_container->render();
$this->assertEquals($expected, trim($this->_container->getRtf()->getWriter()->getContent()));
}
/**
*
* @return array
*/
public function provideWriteText()
{
return array(
array('Hello world!', '{Hello world!}'),
array('<strong>Hello world!</strong>', '{\b Hello world!\b0 }'),
array('<STRONG>Hello world!</STRONG>', '{\b Hello world!\b0 }'),
array('<b>Hello world!</b>', '{\b Hello world!\b0 }'),
array('<B>Hello world!</B>', '{\b Hello world!\b0 }'),
array('<em>Hello world!</em>', '{\i Hello world!\i0 }'),
array('<EM>Hello world!</EM>', '{\i Hello world!\i0 }'),
array('<i>Hello world!</i>', '{\i Hello world!\i0 }'),
array('<I>Hello world!</I>', '{\i Hello world!\i0 }'),
array('<u>Hello world!</u>', '{\ul Hello world!\ul0 }'),
array('<U>Hello world!</U>', '{\ul Hello world!\ul0 }'),
array('Hello<br><BR>world!', '{Hello\line \line world!}'),
array('Hello<br/><BR/>world!', '{Hello\line \line world!}'),
array(
'Hello<hr><HR/>world!',
'{Hello{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}world!}'
),
array('', '{}'),
array('<CHDATE>', '{\chdate }'),
array('<CHDPL>', '{\chdpl }'),
array('<CHDPA>', '{\chdpa }'),
array('<CHTIME>', '{\chtime }'),
array('<CHPGN>', '{\chpgn }'),
array('<TAB>', '{\tab }'),
array('<BULLET>', '{\bullet }'),
array('<PAGENUM>', '{\chpgn }'),
array('<SECTNUM>', '{\sectnum }'),
array('<LINE>', '{\line }'),
);
}
}