7
7
/**
8
8
* Class ODTextTest
9
9
*
10
- * @package PHPWord\Tests
10
+ * @package PHPWord\Tests
11
+ * @coversDefaultClass PHPWord_Writer_ODText
11
12
* @runTestsInSeparateProcesses
12
13
*/
13
14
class ODTextTest extends \PHPUnit_Framework_TestCase
@@ -37,10 +38,9 @@ public function testConstruct()
37
38
}
38
39
39
40
/**
40
- * Test construct with null value/without PHPWord
41
- *
42
- * @expectedException Exception
43
- * @expectedExceptionMessage No PHPWord assigned.
41
+ * @covers ::getPHPWord
42
+ * @expectedException Exception
43
+ * @expectedExceptionMessage No PHPWord assigned.
44
44
*/
45
45
public function testConstructWithNull ()
46
46
{
@@ -49,39 +49,106 @@ public function testConstructWithNull()
49
49
}
50
50
51
51
/**
52
- * Test save()
52
+ * @covers :: save
53
53
*/
54
54
public function testSave ()
55
55
{
56
+ $ imageSrc = \join (
57
+ \DIRECTORY_SEPARATOR ,
58
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'images ' , 'PHPWord.png ' )
59
+ );
60
+ $ objectSrc = \join (
61
+ \DIRECTORY_SEPARATOR ,
62
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'documents ' , 'sheet.xls ' )
63
+ );
64
+ $ file = \join (
65
+ \DIRECTORY_SEPARATOR ,
66
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'temp.odt ' )
67
+ );
68
+
56
69
$ phpWord = new PHPWord ();
57
70
$ phpWord ->addFontStyle ('Font ' , array ('size ' => 11 ));
58
71
$ phpWord ->addParagraphStyle ('Paragraph ' , array ('align ' => 'center ' ));
59
72
$ section = $ phpWord ->createSection ();
60
- $ section ->addText ('Test 1 ' , 'Font ' , ' Paragraph ' );
73
+ $ section ->addText ('Test 1 ' , 'Font ' );
61
74
$ section ->addTextBreak ();
62
- $ section ->addText ('Test 2 ' );
75
+ $ section ->addText ('Test 2 ' , null , 'Paragraph ' );
76
+ $ section ->addLink ('http://test.com ' );
77
+ $ section ->addTitle ('Test ' , 1 );
78
+ $ section ->addPageBreak ();
79
+ $ section ->addTable ();
80
+ $ section ->addListItem ('Test ' );
81
+ $ section ->addImage ($ imageSrc );
82
+ $ section ->addObject ($ objectSrc );
83
+ $ section ->addTOC ();
63
84
$ section = $ phpWord ->createSection ();
64
85
$ textrun = $ section ->createTextRun ();
65
86
$ textrun ->addText ('Test 3 ' );
66
-
67
87
$ writer = new PHPWord_Writer_ODText ($ phpWord );
68
- $ file = join (
69
- DIRECTORY_SEPARATOR ,
70
- array (PHPWORD_TESTS_DIR_ROOT , '_files ' , 'temp.odt ' )
71
- );
72
88
$ writer ->save ($ file );
89
+
73
90
$ this ->assertTrue (file_exists ($ file ));
91
+
74
92
unlink ($ file );
75
93
}
76
94
77
95
/**
78
- * Test disk caching parameters
96
+ * @covers ::save
97
+ * @todo Haven't got any method to test this
98
+ */
99
+ public function testSavePhpOutput ()
100
+ {
101
+ $ phpWord = new PHPWord ();
102
+ $ section = $ phpWord ->createSection ();
103
+ $ section ->addText ('Test ' );
104
+ $ writer = new PHPWord_Writer_ODText ($ phpWord );
105
+ $ writer ->save ('php://output ' );
106
+ }
107
+
108
+ /**
109
+ * @covers ::save
110
+ * @expectedException Exception
111
+ * @expectedExceptionMessage PHPWord object unassigned.
112
+ */
113
+ public function testSaveException ()
114
+ {
115
+ $ writer = new PHPWord_Writer_ODText ();
116
+ $ writer ->save ();
117
+ }
118
+
119
+ /**
120
+ * @covers ::getWriterPart
79
121
*/
80
- public function testSetDiskCaching ()
122
+ public function testGetWriterPartNull ()
123
+ {
124
+ $ object = new PHPWord_Writer_ODText ();
125
+ $ this ->assertNull ($ object ->getWriterPart ('foo ' ));
126
+ }
127
+
128
+ /**
129
+ * @covers ::setUseDiskCaching
130
+ * @covers ::getUseDiskCaching
131
+ */
132
+ public function testSetGetUseDiskCaching ()
81
133
{
82
134
$ object = new PHPWord_Writer_ODText ();
83
135
$ object ->setUseDiskCaching (true , PHPWORD_TESTS_DIR_ROOT );
84
136
$ this ->assertTrue ($ object ->getUseDiskCaching ());
85
137
$ this ->assertEquals (PHPWORD_TESTS_DIR_ROOT , $ object ->getDiskCachingDirectory ());
86
138
}
139
+
140
+ /**
141
+ * @covers ::setUseDiskCaching
142
+ * @expectedException Exception
143
+ */
144
+ public function testSetUseDiskCachingException ()
145
+ {
146
+ $ dir = \join (
147
+ \DIRECTORY_SEPARATOR ,
148
+ array (\PHPWORD_TESTS_DIR_ROOT , 'foo ' )
149
+ );
150
+
151
+ $ object = new PHPWord_Writer_ODText ($ phpWord );
152
+ $ object ->setUseDiskCaching (true , $ dir );
153
+ }
87
154
}
0 commit comments