Skip to content

Commit 70588f2

Browse files
committed
Fixed bugs with Text class
1 parent 79f65f0 commit 70588f2

File tree

4 files changed

+72
-74
lines changed

4 files changed

+72
-74
lines changed

Classes/PHPWord/Section/Text.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class PHPWord_Section_Text
5151
*/
5252
private $paragraphStyle;
5353

54-
5554
/**
5655
* Create a new Text Element
5756
*
@@ -72,19 +71,20 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n
7271
* @param null|array|\PHPWord_Style_Font $style
7372
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
7473
* @return PHPWord_Style_Font
75-
* @throws \Exception
7674
*/
7775
public function setFontStyle($style = null, $paragraphStyle = null)
7876
{
7977
if ($style instanceof PHPWord_Style_Font) {
8078
$this->fontStyle = $style;
79+
$this->setParagraphStyle($paragraphStyle);
8180
} elseif (is_array($style)) {
8281
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
8382
$this->fontStyle->setArrayStyle($style);
8483
} elseif (null === $style) {
8584
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
8685
} else {
87-
throw new Exception('Expected array or PHPWord_Style_Font');
86+
$this->fontStyle = $style;
87+
$this->setParagraphStyle($paragraphStyle);
8888
}
8989
return $this->fontStyle;
9090
}
@@ -104,7 +104,6 @@ public function getFontStyle()
104104
*
105105
* @param null|array|\PHPWord_Style_Paragraph $style
106106
* @return null|\PHPWord_Style_Paragraph
107-
* @throws \Exception
108107
*/
109108
public function setParagraphStyle($style = null)
110109
{
@@ -116,7 +115,7 @@ public function setParagraphStyle($style = null)
116115
} elseif (null === $style) {
117116
$this->paragraphStyle = new PHPWord_Style_Paragraph;
118117
} else {
119-
throw new Exception('Expected array or PHPWord_Style_Paragraph');
118+
$this->paragraphStyle = $style;
120119
}
121120
return $this->paragraphStyle;
122121
}
@@ -150,4 +149,4 @@ public function getText()
150149
{
151150
return $this->text;
152151
}
153-
}
152+
}

Classes/PHPWord/Style/Font.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ class PHPWord_Style_Font
163163
*
164164
* @param string $type Type of font
165165
* @param array $paragraphStyle Paragraph styles definition
166-
* @throws \Exception
167166
*/
168167
public function __construct($type = 'text', $paragraphStyle = null)
169168
{
@@ -177,7 +176,7 @@ public function __construct($type = 'text', $paragraphStyle = null)
177176
} elseif (null === $paragraphStyle) {
178177
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
179178
} else {
180-
throw new Exception('Expected array or PHPWord_Style_Paragraph');
179+
$this->_paragraphStyle = $paragraphStyle;
181180
}
182181
}
183182

Tests/PHPWord/Section/SettingsTest.php

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ public function testSettingValue()
1515
$oSettings = new PHPWord_Section_Settings();
1616

1717
$oSettings->setSettingValue('_orientation', 'landscape');
18-
$this->assertEquals($oSettings->getOrientation(), 'landscape');
19-
$this->assertEquals($oSettings->getPageSizeW(), 16838);
20-
$this->assertEquals($oSettings->getPageSizeH(), 11906);
18+
$this->assertEquals('landscape', $oSettings->getOrientation());
19+
$this->assertEquals(16838, $oSettings->getPageSizeW());
20+
$this->assertEquals(11906, $oSettings->getPageSizeH());
2121

2222
$oSettings->setSettingValue('_orientation', null);
23-
$this->assertEquals($oSettings->getOrientation(), null);
24-
$this->assertEquals($oSettings->getPageSizeW(), 11906);
25-
$this->assertEquals($oSettings->getPageSizeH(), 16838);
23+
$this->assertNull($oSettings->getOrientation());
24+
$this->assertEquals(11906, $oSettings->getPageSizeW());
25+
$this->assertEquals(16838, $oSettings->getPageSizeH());
2626

2727
$iVal = rand(1, 1000);
2828
$oSettings->setSettingValue('_borderSize', $iVal);
29-
$this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal));
30-
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal);
31-
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal);
32-
$this->assertEquals($oSettings->getBorderRightSize(), $iVal);
33-
$this->assertEquals($oSettings->getBorderTopSize(), $iVal);
29+
$this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize());
30+
$this->assertEquals($iVal, $oSettings->getBorderBottomSize());
31+
$this->assertEquals($iVal, $oSettings->getBorderLeftSize());
32+
$this->assertEquals($iVal, $oSettings->getBorderRightSize());
33+
$this->assertEquals($iVal, $oSettings->getBorderTopSize());
3434

3535
$oSettings->setSettingValue('_borderColor', 'FF00AA');
36-
$this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'));
37-
$this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA');
38-
$this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA');
39-
$this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA');
40-
$this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA');
36+
$this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
37+
$this->assertEquals('FF00AA', $oSettings->getBorderBottomColor());
38+
$this->assertEquals('FF00AA', $oSettings->getBorderLeftColor());
39+
$this->assertEquals('FF00AA', $oSettings->getBorderRightColor());
40+
$this->assertEquals('FF00AA', $oSettings->getBorderTopColor());
4141

4242
$iVal = rand(1, 1000);
4343
$oSettings->setSettingValue('headerHeight', $iVal);
44-
$this->assertEquals($oSettings->getHeaderHeight(), $iVal);
44+
$this->assertEquals($iVal, $oSettings->getHeaderHeight());
4545
}
4646

4747
public function testMargin()
@@ -51,19 +51,19 @@ public function testMargin()
5151

5252
$iVal = rand(1, 1000);
5353
$oSettings->setMarginTop($iVal);
54-
$this->assertEquals($oSettings->getMarginTop(), $iVal);
54+
$this->assertEquals($iVal, $oSettings->getMarginTop());
5555

5656
$iVal = rand(1, 1000);
5757
$oSettings->setMarginBottom($iVal);
58-
$this->assertEquals($oSettings->getMarginBottom(), $iVal);
58+
$this->assertEquals($iVal, $oSettings->getMarginBottom());
5959

6060
$iVal = rand(1, 1000);
6161
$oSettings->setMarginLeft($iVal);
62-
$this->assertEquals($oSettings->getMarginLeft(), $iVal);
62+
$this->assertEquals($iVal, $oSettings->getMarginLeft());
6363

6464
$iVal = rand(1, 1000);
6565
$oSettings->setMarginRight($iVal);
66-
$this->assertEquals($oSettings->getMarginRight(), $iVal);
66+
$this->assertEquals($iVal, $oSettings->getMarginRight());
6767
}
6868

6969
public function testOrientationLandscape()
@@ -72,9 +72,9 @@ public function testOrientationLandscape()
7272
$oSettings = new PHPWord_Section_Settings();
7373

7474
$oSettings->setLandscape();
75-
$this->assertEquals($oSettings->getOrientation(), 'landscape');
76-
$this->assertEquals($oSettings->getPageSizeW(), 16838);
77-
$this->assertEquals($oSettings->getPageSizeH(), 11906);
75+
$this->assertEquals('landscape', $oSettings->getOrientation());
76+
$this->assertEquals(16838, $oSettings->getPageSizeW());
77+
$this->assertEquals(11906, $oSettings->getPageSizeH());
7878
}
7979

8080
public function testOrientationPortrait()
@@ -83,9 +83,9 @@ public function testOrientationPortrait()
8383
$oSettings = new PHPWord_Section_Settings();
8484

8585
$oSettings->setPortrait();
86-
$this->assertEquals($oSettings->getOrientation(), null);
87-
$this->assertEquals($oSettings->getPageSizeW(), 11906);
88-
$this->assertEquals($oSettings->getPageSizeH(), 16838);
86+
$this->assertNull($oSettings->getOrientation());
87+
$this->assertEquals(11906, $oSettings->getPageSizeW());
88+
$this->assertEquals(16838, $oSettings->getPageSizeH());
8989
}
9090

9191
public function testBorderSize()
@@ -95,27 +95,27 @@ public function testBorderSize()
9595

9696
$iVal = rand(1, 1000);
9797
$oSettings->setBorderSize($iVal);
98-
$this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal));
99-
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal);
100-
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal);
101-
$this->assertEquals($oSettings->getBorderRightSize(), $iVal);
102-
$this->assertEquals($oSettings->getBorderTopSize(), $iVal);
98+
$this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize());
99+
$this->assertEquals($iVal, $oSettings->getBorderBottomSize());
100+
$this->assertEquals($iVal, $oSettings->getBorderLeftSize());
101+
$this->assertEquals($iVal, $oSettings->getBorderRightSize());
102+
$this->assertEquals($iVal, $oSettings->getBorderTopSize());
103103

104104
$iVal = rand(1, 1000);
105105
$oSettings->setBorderBottomSize($iVal);
106-
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal);
106+
$this->assertEquals($iVal, $oSettings->getBorderBottomSize());
107107

108108
$iVal = rand(1, 1000);
109109
$oSettings->setBorderLeftSize($iVal);
110-
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal);
110+
$this->assertEquals($iVal, $oSettings->getBorderLeftSize());
111111

112112
$iVal = rand(1, 1000);
113113
$oSettings->setBorderRightSize($iVal);
114-
$this->assertEquals($oSettings->getBorderRightSize(), $iVal);
114+
$this->assertEquals($iVal, $oSettings->getBorderRightSize());
115115

116116
$iVal = rand(1, 1000);
117117
$oSettings->setBorderTopSize($iVal);
118-
$this->assertEquals($oSettings->getBorderTopSize(), $iVal);
118+
$this->assertEquals($iVal, $oSettings->getBorderTopSize());
119119
}
120120

121121
public function testBorderColor()
@@ -124,68 +124,68 @@ public function testBorderColor()
124124
$oSettings = new PHPWord_Section_Settings();
125125

126126
$oSettings->setBorderColor('FF00AA');
127-
$this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'));
128-
$this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA');
129-
$this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA');
130-
$this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA');
131-
$this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA');
127+
$this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
128+
$this->assertEquals('FF00AA', $oSettings->getBorderBottomColor());
129+
$this->assertEquals('FF00AA', $oSettings->getBorderLeftColor());
130+
$this->assertEquals('FF00AA', $oSettings->getBorderRightColor());
131+
$this->assertEquals('FF00AA', $oSettings->getBorderTopColor());
132132

133133
$oSettings->setBorderBottomColor('BBCCDD');
134-
$this->assertEquals($oSettings->getBorderBottomColor(), 'BBCCDD');
134+
$this->assertEquals('BBCCDD', $oSettings->getBorderBottomColor());
135135

136136
$oSettings->setBorderLeftColor('CCDDEE');
137-
$this->assertEquals($oSettings->getBorderLeftColor(), 'CCDDEE');
137+
$this->assertEquals('CCDDEE', $oSettings->getBorderLeftColor());
138138

139139
$oSettings->setBorderRightColor('11EE22');
140-
$this->assertEquals($oSettings->getBorderRightColor(), '11EE22');
140+
$this->assertEquals('11EE22', $oSettings->getBorderRightColor());
141141

142142
$oSettings->setBorderTopColor('22FF33');
143-
$this->assertEquals($oSettings->getBorderTopColor(), '22FF33');
143+
$this->assertEquals('22FF33', $oSettings->getBorderTopColor());
144144
}
145145

146146
public function testNumberingStart()
147147
{
148148
// Section Settings
149149
$oSettings = new PHPWord_Section_Settings();
150150

151-
$this->assertEquals($oSettings->getPageNumberingStart(), null);
151+
$this->assertNull($oSettings->getPageNumberingStart());
152152

153153
$iVal = rand(1, 1000);
154154
$oSettings->setPageNumberingStart($iVal);
155-
$this->assertEquals($oSettings->getPageNumberingStart(), $iVal);
155+
$this->assertEquals($iVal, $oSettings->getPageNumberingStart());
156156

157157
$oSettings->setPageNumberingStart();
158-
$this->assertEquals($oSettings->getPageNumberingStart(), null);
158+
$this->assertNull($oSettings->getPageNumberingStart());
159159
}
160160

161161
public function testHeader()
162162
{
163163
// Section Settings
164164
$oSettings = new PHPWord_Section_Settings();
165165

166-
$this->assertEquals($oSettings->getHeaderHeight(), 720);
166+
$this->assertEquals(720, $oSettings->getHeaderHeight());
167167

168168
$iVal = rand(1, 1000);
169169
$oSettings->setHeaderHeight($iVal);
170-
$this->assertEquals($oSettings->getHeaderHeight(), $iVal);
170+
$this->assertEquals($iVal, $oSettings->getHeaderHeight());
171171

172172
$oSettings->setHeaderHeight();
173-
$this->assertEquals($oSettings->getHeaderHeight(), 720);
173+
$this->assertEquals(720, $oSettings->getHeaderHeight());
174174
}
175175

176176
public function testFooter()
177177
{
178178
// Section Settings
179179
$oSettings = new PHPWord_Section_Settings();
180180

181-
$this->assertEquals($oSettings->getFooterHeight(), 720);
181+
$this->assertEquals(720, $oSettings->getFooterHeight());
182182

183183
$iVal = rand(1, 1000);
184184
$oSettings->setFooterHeight($iVal);
185-
$this->assertEquals($oSettings->getFooterHeight(), $iVal);
185+
$this->assertEquals($iVal, $oSettings->getFooterHeight());
186186

187187
$oSettings->setFooterHeight();
188-
$this->assertEquals($oSettings->getFooterHeight(), 720);
188+
$this->assertEquals(720, $oSettings->getFooterHeight());
189189
}
190190

191191
public function testColumnsNum()
@@ -194,14 +194,14 @@ public function testColumnsNum()
194194
$oSettings = new PHPWord_Section_Settings();
195195

196196
// Default
197-
$this->assertEquals($oSettings->getColsNum(), 1);
197+
$this->assertEquals(1, $oSettings->getColsNum());
198198

199199
$iVal = rand(1, 1000);
200200
$oSettings->setColsNum($iVal);
201-
$this->assertEquals($oSettings->getColsNum(), $iVal);
201+
$this->assertEquals($iVal, $oSettings->getColsNum());
202202

203203
$oSettings->setColsNum();
204-
$this->assertEquals($oSettings->getColsNum(), 1);
204+
$this->assertEquals(1, $oSettings->getColsNum());
205205
}
206206

207207
public function testColumnsSpace()
@@ -210,27 +210,27 @@ public function testColumnsSpace()
210210
$oSettings = new PHPWord_Section_Settings();
211211

212212
// Default
213-
$this->assertEquals($oSettings->getColsSpace(), 720);
213+
$this->assertEquals(720, $oSettings->getColsSpace());
214214

215215
$iVal = rand(1, 1000);
216216
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal));
217-
$this->assertEquals($oSettings->getColsSpace(), $iVal);
217+
$this->assertEquals($iVal, $oSettings->getColsSpace());
218218

219219
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace());
220-
$this->assertEquals($oSettings->getColsSpace(), 1);
220+
$this->assertEquals(1, $oSettings->getColsSpace());
221221
}
222222

223223
public function testBreakType()
224224
{
225225
// Section Settings
226226
$oSettings = new PHPWord_Section_Settings();
227227

228-
$this->assertEquals($oSettings->getBreakType(), null);
228+
$this->assertNull($oSettings->getBreakType());
229229

230230
$oSettings->setBreakType('continuous');
231-
$this->assertEquals($oSettings->getBreakType(), 'continuous');
231+
$this->assertEquals('continuous', $oSettings->getBreakType());
232232

233233
$oSettings->setBreakType();
234-
$this->assertEquals($oSettings->getBreakType(), null);
234+
$this->assertNull($oSettings->getBreakType());
235235
}
236236
}

Tests/PHPWord/Section/TextTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public function testConstruct()
1111
$oText = new PHPWord_Section_Text();
1212

1313
$this->assertInstanceOf('PHPWord_Section_Text', $oText);
14-
$this->assertEquals($oText->getText(), null);
15-
$this->assertEquals($oText->getFontStyle(), null);
16-
$this->assertEquals($oText->getParagraphStyle(), null);
14+
$this->assertEquals(null, $oText->getText());
15+
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
16+
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
1717
}
1818

1919
public function testText()

0 commit comments

Comments
 (0)