diff --git a/Classes/PHPWord/Section/Text.php b/Classes/PHPWord/Section/Text.php index 6b87ae40..5d628d2c 100755 --- a/Classes/PHPWord/Section/Text.php +++ b/Classes/PHPWord/Section/Text.php @@ -51,7 +51,6 @@ class PHPWord_Section_Text */ private $paragraphStyle; - /** * Create a new Text Element * @@ -72,19 +71,20 @@ class PHPWord_Section_Text * @param null|array|\PHPWord_Style_Font $style * @param null|array|\PHPWord_Style_Paragraph $paragraphStyle * @return PHPWord_Style_Font - * @throws \Exception */ public function setFontStyle($style = null, $paragraphStyle = null) { if ($style instanceof PHPWord_Style_Font) { $this->fontStyle = $style; + $this->setParagraphStyle($paragraphStyle); } elseif (is_array($style)) { $this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); $this->fontStyle->setArrayStyle($style); } elseif (null === $style) { $this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); } else { - throw new Exception('Expected array or PHPWord_Style_Font'); + $this->fontStyle = $style; + $this->setParagraphStyle($paragraphStyle); } return $this->fontStyle; } @@ -104,7 +104,6 @@ class PHPWord_Section_Text * * @param null|array|\PHPWord_Style_Paragraph $style * @return null|\PHPWord_Style_Paragraph - * @throws \Exception */ public function setParagraphStyle($style = null) { @@ -116,7 +115,7 @@ class PHPWord_Section_Text } elseif (null === $style) { $this->paragraphStyle = new PHPWord_Style_Paragraph; } else { - throw new Exception('Expected array or PHPWord_Style_Paragraph'); + $this->paragraphStyle = $style; } return $this->paragraphStyle; } @@ -150,4 +149,4 @@ class PHPWord_Section_Text { return $this->text; } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index e7f89705..ccbeb400 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -163,7 +163,6 @@ class PHPWord_Style_Font * * @param string $type Type of font * @param array $paragraphStyle Paragraph styles definition - * @throws \Exception */ public function __construct($type = 'text', $paragraphStyle = null) { @@ -177,7 +176,7 @@ class PHPWord_Style_Font } elseif (null === $paragraphStyle) { $this->_paragraphStyle = new PHPWord_Style_Paragraph; } else { - throw new Exception('Expected array or PHPWord_Style_Paragraph'); + $this->_paragraphStyle = $paragraphStyle; } } diff --git a/Tests/PHPWord/Section/SettingsTest.php b/Tests/PHPWord/Section/SettingsTest.php index 83c1c888..89308088 100644 --- a/Tests/PHPWord/Section/SettingsTest.php +++ b/Tests/PHPWord/Section/SettingsTest.php @@ -15,33 +15,33 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); $oSettings->setSettingValue('_orientation', 'landscape'); - $this->assertEquals($oSettings->getOrientation(), 'landscape'); - $this->assertEquals($oSettings->getPageSizeW(), 16838); - $this->assertEquals($oSettings->getPageSizeH(), 11906); + $this->assertEquals('landscape', $oSettings->getOrientation()); + $this->assertEquals(16838, $oSettings->getPageSizeW()); + $this->assertEquals(11906, $oSettings->getPageSizeH()); $oSettings->setSettingValue('_orientation', null); - $this->assertEquals($oSettings->getOrientation(), null); - $this->assertEquals($oSettings->getPageSizeW(), 11906); - $this->assertEquals($oSettings->getPageSizeH(), 16838); + $this->assertNull($oSettings->getOrientation()); + $this->assertEquals(11906, $oSettings->getPageSizeW()); + $this->assertEquals(16838, $oSettings->getPageSizeH()); $iVal = rand(1, 1000); $oSettings->setSettingValue('_borderSize', $iVal); - $this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal)); - $this->assertEquals($oSettings->getBorderBottomSize(), $iVal); - $this->assertEquals($oSettings->getBorderLeftSize(), $iVal); - $this->assertEquals($oSettings->getBorderRightSize(), $iVal); - $this->assertEquals($oSettings->getBorderTopSize(), $iVal); + $this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize()); + $this->assertEquals($iVal, $oSettings->getBorderBottomSize()); + $this->assertEquals($iVal, $oSettings->getBorderLeftSize()); + $this->assertEquals($iVal, $oSettings->getBorderRightSize()); + $this->assertEquals($iVal, $oSettings->getBorderTopSize()); $oSettings->setSettingValue('_borderColor', 'FF00AA'); - $this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA')); - $this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA'); + $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderBottomColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderLeftColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderRightColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderTopColor()); $iVal = rand(1, 1000); $oSettings->setSettingValue('headerHeight', $iVal); - $this->assertEquals($oSettings->getHeaderHeight(), $iVal); + $this->assertEquals($iVal, $oSettings->getHeaderHeight()); } public function testMargin() @@ -51,19 +51,19 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oSettings->setMarginTop($iVal); - $this->assertEquals($oSettings->getMarginTop(), $iVal); + $this->assertEquals($iVal, $oSettings->getMarginTop()); $iVal = rand(1, 1000); $oSettings->setMarginBottom($iVal); - $this->assertEquals($oSettings->getMarginBottom(), $iVal); + $this->assertEquals($iVal, $oSettings->getMarginBottom()); $iVal = rand(1, 1000); $oSettings->setMarginLeft($iVal); - $this->assertEquals($oSettings->getMarginLeft(), $iVal); + $this->assertEquals($iVal, $oSettings->getMarginLeft()); $iVal = rand(1, 1000); $oSettings->setMarginRight($iVal); - $this->assertEquals($oSettings->getMarginRight(), $iVal); + $this->assertEquals($iVal, $oSettings->getMarginRight()); } public function testOrientationLandscape() @@ -72,9 +72,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); $oSettings->setLandscape(); - $this->assertEquals($oSettings->getOrientation(), 'landscape'); - $this->assertEquals($oSettings->getPageSizeW(), 16838); - $this->assertEquals($oSettings->getPageSizeH(), 11906); + $this->assertEquals('landscape', $oSettings->getOrientation()); + $this->assertEquals(16838, $oSettings->getPageSizeW()); + $this->assertEquals(11906, $oSettings->getPageSizeH()); } public function testOrientationPortrait() @@ -83,9 +83,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); $oSettings->setPortrait(); - $this->assertEquals($oSettings->getOrientation(), null); - $this->assertEquals($oSettings->getPageSizeW(), 11906); - $this->assertEquals($oSettings->getPageSizeH(), 16838); + $this->assertNull($oSettings->getOrientation()); + $this->assertEquals(11906, $oSettings->getPageSizeW()); + $this->assertEquals(16838, $oSettings->getPageSizeH()); } public function testBorderSize() @@ -95,27 +95,27 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oSettings->setBorderSize($iVal); - $this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal)); - $this->assertEquals($oSettings->getBorderBottomSize(), $iVal); - $this->assertEquals($oSettings->getBorderLeftSize(), $iVal); - $this->assertEquals($oSettings->getBorderRightSize(), $iVal); - $this->assertEquals($oSettings->getBorderTopSize(), $iVal); + $this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize()); + $this->assertEquals($iVal, $oSettings->getBorderBottomSize()); + $this->assertEquals($iVal, $oSettings->getBorderLeftSize()); + $this->assertEquals($iVal, $oSettings->getBorderRightSize()); + $this->assertEquals($iVal, $oSettings->getBorderTopSize()); $iVal = rand(1, 1000); $oSettings->setBorderBottomSize($iVal); - $this->assertEquals($oSettings->getBorderBottomSize(), $iVal); + $this->assertEquals($iVal, $oSettings->getBorderBottomSize()); $iVal = rand(1, 1000); $oSettings->setBorderLeftSize($iVal); - $this->assertEquals($oSettings->getBorderLeftSize(), $iVal); + $this->assertEquals($iVal, $oSettings->getBorderLeftSize()); $iVal = rand(1, 1000); $oSettings->setBorderRightSize($iVal); - $this->assertEquals($oSettings->getBorderRightSize(), $iVal); + $this->assertEquals($iVal, $oSettings->getBorderRightSize()); $iVal = rand(1, 1000); $oSettings->setBorderTopSize($iVal); - $this->assertEquals($oSettings->getBorderTopSize(), $iVal); + $this->assertEquals($iVal, $oSettings->getBorderTopSize()); } public function testBorderColor() @@ -124,23 +124,23 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); $oSettings->setBorderColor('FF00AA'); - $this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA')); - $this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA'); - $this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA'); + $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderBottomColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderLeftColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderRightColor()); + $this->assertEquals('FF00AA', $oSettings->getBorderTopColor()); $oSettings->setBorderBottomColor('BBCCDD'); - $this->assertEquals($oSettings->getBorderBottomColor(), 'BBCCDD'); + $this->assertEquals('BBCCDD', $oSettings->getBorderBottomColor()); $oSettings->setBorderLeftColor('CCDDEE'); - $this->assertEquals($oSettings->getBorderLeftColor(), 'CCDDEE'); + $this->assertEquals('CCDDEE', $oSettings->getBorderLeftColor()); $oSettings->setBorderRightColor('11EE22'); - $this->assertEquals($oSettings->getBorderRightColor(), '11EE22'); + $this->assertEquals('11EE22', $oSettings->getBorderRightColor()); $oSettings->setBorderTopColor('22FF33'); - $this->assertEquals($oSettings->getBorderTopColor(), '22FF33'); + $this->assertEquals('22FF33', $oSettings->getBorderTopColor()); } public function testNumberingStart() @@ -148,14 +148,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase // Section Settings $oSettings = new PHPWord_Section_Settings(); - $this->assertEquals($oSettings->getPageNumberingStart(), null); + $this->assertNull($oSettings->getPageNumberingStart()); $iVal = rand(1, 1000); $oSettings->setPageNumberingStart($iVal); - $this->assertEquals($oSettings->getPageNumberingStart(), $iVal); + $this->assertEquals($iVal, $oSettings->getPageNumberingStart()); $oSettings->setPageNumberingStart(); - $this->assertEquals($oSettings->getPageNumberingStart(), null); + $this->assertNull($oSettings->getPageNumberingStart()); } public function testHeader() @@ -163,14 +163,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase // Section Settings $oSettings = new PHPWord_Section_Settings(); - $this->assertEquals($oSettings->getHeaderHeight(), 720); + $this->assertEquals(720, $oSettings->getHeaderHeight()); $iVal = rand(1, 1000); $oSettings->setHeaderHeight($iVal); - $this->assertEquals($oSettings->getHeaderHeight(), $iVal); + $this->assertEquals($iVal, $oSettings->getHeaderHeight()); $oSettings->setHeaderHeight(); - $this->assertEquals($oSettings->getHeaderHeight(), 720); + $this->assertEquals(720, $oSettings->getHeaderHeight()); } public function testFooter() @@ -178,14 +178,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase // Section Settings $oSettings = new PHPWord_Section_Settings(); - $this->assertEquals($oSettings->getFooterHeight(), 720); + $this->assertEquals(720, $oSettings->getFooterHeight()); $iVal = rand(1, 1000); $oSettings->setFooterHeight($iVal); - $this->assertEquals($oSettings->getFooterHeight(), $iVal); + $this->assertEquals($iVal, $oSettings->getFooterHeight()); $oSettings->setFooterHeight(); - $this->assertEquals($oSettings->getFooterHeight(), 720); + $this->assertEquals(720, $oSettings->getFooterHeight()); } public function testColumnsNum() @@ -194,14 +194,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); // Default - $this->assertEquals($oSettings->getColsNum(), 1); + $this->assertEquals(1, $oSettings->getColsNum()); $iVal = rand(1, 1000); $oSettings->setColsNum($iVal); - $this->assertEquals($oSettings->getColsNum(), $iVal); + $this->assertEquals($iVal, $oSettings->getColsNum()); $oSettings->setColsNum(); - $this->assertEquals($oSettings->getColsNum(), 1); + $this->assertEquals(1, $oSettings->getColsNum()); } public function testColumnsSpace() @@ -210,14 +210,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings = new PHPWord_Section_Settings(); // Default - $this->assertEquals($oSettings->getColsSpace(), 720); + $this->assertEquals(720, $oSettings->getColsSpace()); $iVal = rand(1, 1000); $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal)); - $this->assertEquals($oSettings->getColsSpace(), $iVal); + $this->assertEquals($iVal, $oSettings->getColsSpace()); $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace()); - $this->assertEquals($oSettings->getColsSpace(), 1); + $this->assertEquals(1, $oSettings->getColsSpace()); } public function testBreakType() @@ -225,12 +225,12 @@ class SettingsTest extends \PHPUnit_Framework_TestCase // Section Settings $oSettings = new PHPWord_Section_Settings(); - $this->assertEquals($oSettings->getBreakType(), null); + $this->assertNull($oSettings->getBreakType()); $oSettings->setBreakType('continuous'); - $this->assertEquals($oSettings->getBreakType(), 'continuous'); + $this->assertEquals('continuous', $oSettings->getBreakType()); $oSettings->setBreakType(); - $this->assertEquals($oSettings->getBreakType(), null); + $this->assertNull($oSettings->getBreakType()); } } \ No newline at end of file diff --git a/Tests/PHPWord/Section/TextTest.php b/Tests/PHPWord/Section/TextTest.php index 6fe0cf38..8a2bf321 100644 --- a/Tests/PHPWord/Section/TextTest.php +++ b/Tests/PHPWord/Section/TextTest.php @@ -11,9 +11,9 @@ class TextTest extends \PHPUnit_Framework_TestCase $oText = new PHPWord_Section_Text(); $this->assertInstanceOf('PHPWord_Section_Text', $oText); - $this->assertEquals($oText->getText(), null); - $this->assertEquals($oText->getFontStyle(), null); - $this->assertEquals($oText->getParagraphStyle(), null); + $this->assertEquals(null, $oText->getText()); + $this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle()); + $this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle()); } public function testText()