diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 00000000..dd558b8e --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,13 @@ +filter: + excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ] + +before_commands: + - "composer install --prefer-source --dev" + +tools: + php_code_coverage: + enabled: true + test_command: phpunit -c phpunit.xml.dist + php_sim: true + php_pdepend: true + php_analyzer: true diff --git a/src/PhpWord/Style/Shading.php b/src/PhpWord/Style/Shading.php index 677e55d5..3e970e6e 100644 --- a/src/PhpWord/Style/Shading.php +++ b/src/PhpWord/Style/Shading.php @@ -25,20 +25,34 @@ namespace PhpOffice\PhpWord\Style; */ class Shading extends AbstractStyle { + /** + * Pattern constants (partly) + * + * @const string + * @link http://www.schemacentral.com/sc/ooxml/t-w_ST_Shd.html + */ + const PATTERN_CLEAR = 'clear'; // No pattern + const PATTERN_SOLID = 'solid'; // 100% fill pattern + const PATTERN_HSTRIPE = 'horzStripe'; // Horizontal stripe pattern + const PATTERN_VSTRIPE = 'vertStripe'; // Vertical stripe pattern + const PATTERN_DSTRIPE = 'diagStripe'; // Diagonal stripe pattern + const PATTERN_HCROSS = 'horzCross'; // Horizontal cross pattern + const PATTERN_DCROSS = 'diagCross'; // Diagonal cross pattern + /** * Shading pattern * * @var string * @link http://www.schemacentral.com/sc/ooxml/t-w_ST_Shd.html */ - private $pattern = 'clear'; + private $pattern = self::PATTERN_CLEAR; /** * Shading pattern color * * @var string */ - private $color = 'auto'; + private $color; /** * Shading background color @@ -75,7 +89,10 @@ class Shading extends AbstractStyle */ public function setPattern($value = null) { - $this->pattern = $value; + $enum = array(self::PATTERN_CLEAR, self::PATTERN_SOLID, self::PATTERN_HSTRIPE, + self::PATTERN_VSTRIPE, self::PATTERN_DSTRIPE, self::PATTERN_HCROSS, self::PATTERN_DCROSS); + + $this->pattern = $this->setEnumVal($value, $enum, $this->pattern); return $this; } diff --git a/src/PhpWord/Style/TOC.php b/src/PhpWord/Style/TOC.php index 75a20f6a..13a70294 100644 --- a/src/PhpWord/Style/TOC.php +++ b/src/PhpWord/Style/TOC.php @@ -22,6 +22,12 @@ namespace PhpOffice\PhpWord\Style; */ class TOC extends Tab { + /** + * Tab leader types for backward compatibility + * + * @const string + * @deprecated 0.11.0 + */ const TABLEADER_DOT = self::TAB_LEADER_DOT; const TABLEADER_UNDERSCORE = self::TAB_LEADER_UNDERSCORE; const TABLEADER_LINE = self::TAB_LEADER_HYPHEN; @@ -32,8 +38,7 @@ class TOC extends Tab * * @var int */ - private $indent; - + private $indent = 200; /** * Create a new TOC Style @@ -41,7 +46,6 @@ class TOC extends Tab public function __construct() { parent::__construct(self::TAB_STOP_RIGHT, 9062, self::TABLEADER_DOT); - $this->indent = 200; } /** diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index 5ffd557a..7aa108bf 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -143,6 +143,8 @@ class Table extends Border { if (!is_null($this->shading)) { return $this->shading->getFill(); + } else { + return null; } } diff --git a/tests/PhpWord/Tests/Collection/CollectionTest.php b/tests/PhpWord/Tests/Collection/CollectionTest.php new file mode 100644 index 00000000..e3d08da2 --- /dev/null +++ b/tests/PhpWord/Tests/Collection/CollectionTest.php @@ -0,0 +1,40 @@ +addItem(new Footnote()); // addItem #1 + + $this->assertEquals(2, $object->addItem(new Footnote())); // addItem #2. Should returns new item index + $this->assertEquals(2, $object->countItems()); // There are two items now + $this->assertEquals(2, count($object->getItems())); // getItems returns array + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $object->getItem(1)); // getItem returns object + $this->assertNull($object->getItem(3)); // getItem returns null when invalid index is referenced + + $object->setItem(2, null); // Set item #2 to null + + $this->assertNull($object->getItem(2)); // Check if it's null + } +} diff --git a/tests/PhpWord/Tests/Element/TOCTest.php b/tests/PhpWord/Tests/Element/TOCTest.php index eaa61c2f..d0ebf343 100644 --- a/tests/PhpWord/Tests/Element/TOCTest.php +++ b/tests/PhpWord/Tests/Element/TOCTest.php @@ -61,6 +61,17 @@ class TOCTest extends \PHPUnit_Framework_TestCase $this->assertEquals('Font Style', $object->getStyleFont()); } + /** + * Test when no PHPWord object is assigned: + */ + public function testNoPhpWord() + { + $object = new TOC(); + + $this->assertEmpty($object->getTitles()); + $this->assertNull($object->getPhpWord()); + } + /** * Set/get minDepth and maxDepth */ diff --git a/tests/PhpWord/Tests/Style/IndentationTest.php b/tests/PhpWord/Tests/Style/IndentationTest.php new file mode 100644 index 00000000..d0e88f2c --- /dev/null +++ b/tests/PhpWord/Tests/Style/IndentationTest.php @@ -0,0 +1,53 @@ + array(0, 10), + 'right' => array(0, 10), + 'firstLine' => array(null, 20), + 'hanging' => array(null, 20), + ); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value + } + } +} diff --git a/tests/PhpWord/Tests/Style/LineNumberingTest.php b/tests/PhpWord/Tests/Style/LineNumberingTest.php new file mode 100644 index 00000000..bc4dc603 --- /dev/null +++ b/tests/PhpWord/Tests/Style/LineNumberingTest.php @@ -0,0 +1,53 @@ + array(1, 2), + 'increment' => array(1, 10), + 'distance' => array(null, 10), + 'restart' => array(null, 'continuous'), + ); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value + } + } +} diff --git a/tests/PhpWord/Tests/Style/NumberingTest.php b/tests/PhpWord/Tests/Style/NumberingTest.php new file mode 100644 index 00000000..e1575357 --- /dev/null +++ b/tests/PhpWord/Tests/Style/NumberingTest.php @@ -0,0 +1,61 @@ +object = new Numbering(); + $this->properties = array( + 'numId' => array(null, 1), + 'type' => array(null, 'singleLevel'), + ); + foreach ($this->properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $this->object->$get()); // Default value + + $this->object->$set($expected); + + $this->assertEquals($expected, $this->object->$get()); // New value + } + } + + /** + * Test get level + */ + public function testGetLevels() + { + $this->object = new Numbering(); + + $this->assertEmpty($this->object->getLevels()); + } +} diff --git a/tests/PhpWord/Tests/Style/ShadingTest.php b/tests/PhpWord/Tests/Style/ShadingTest.php new file mode 100644 index 00000000..5a965e1d --- /dev/null +++ b/tests/PhpWord/Tests/Style/ShadingTest.php @@ -0,0 +1,52 @@ + array('clear', 'solid'), + 'color' => array(null, 'FF0000'), + 'fill' => array(null, 'FF0000'), + ); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value + } + } +} diff --git a/tests/PhpWord/Tests/Style/SpacingTest.php b/tests/PhpWord/Tests/Style/SpacingTest.php new file mode 100644 index 00000000..a4022b74 --- /dev/null +++ b/tests/PhpWord/Tests/Style/SpacingTest.php @@ -0,0 +1,53 @@ + array(null, 10), + 'after' => array(null, 10), + 'line' => array(null, 10), + 'rule' => array('auto', 'exact'), + ); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value + } + } +} diff --git a/tests/PhpWord/Tests/Style/TOCTest.php b/tests/PhpWord/Tests/Style/TOCTest.php index b70ed1bb..e6e32e6b 100644 --- a/tests/PhpWord/Tests/Style/TOCTest.php +++ b/tests/PhpWord/Tests/Style/TOCTest.php @@ -23,28 +23,30 @@ use PhpOffice\PhpWord\Style\TOC; * Test class for PhpOffice\PhpWord\Style\TOC * * @coversDefaultClass \PhpOffice\PhpWord\Style\TOC - * @runTestsInSeparateProcesses */ class TOCTest extends \PHPUnit_Framework_TestCase { /** - * Test properties with normal value + * Test get/set */ - public function testProperties() + public function testGetSet() { $object = new TOC(); - $properties = array( - 'position' => 9062, - 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, - 'indent' => 200, + 'tabLeader' => array(TOC::TAB_LEADER_DOT, TOC::TAB_LEADER_UNDERSCORE), + 'tabPos' => array(9062, 10), + 'indent' => array(200, 10), ); - foreach ($properties as $key => $value) { - // set/get - $set = "set{$key}"; - $get = "get{$key}"; - $object->$set($value); - $this->assertEquals($value, $object->$get()); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value } } } diff --git a/tests/PhpWord/Tests/Style/TabTest.php b/tests/PhpWord/Tests/Style/TabTest.php new file mode 100644 index 00000000..784b4e47 --- /dev/null +++ b/tests/PhpWord/Tests/Style/TabTest.php @@ -0,0 +1,52 @@ + array(Tab::TAB_STOP_CLEAR, Tab::TAB_STOP_RIGHT), + 'leader' => array(Tab::TAB_LEADER_NONE, Tab::TAB_LEADER_DOT), + 'position' => array(0, 10), + ); + foreach ($properties as $property => $value) { + list($default, $expected) = $value; + $get = "get{$property}"; + $set = "set{$property}"; + + $this->assertEquals($default, $object->$get()); // Default value + + $object->$set($expected); + + $this->assertEquals($expected, $object->$get()); // New value + } + } +} diff --git a/tests/PhpWord/Tests/Style/TableTest.php b/tests/PhpWord/Tests/Style/TableTest.php index 6ae2f35c..a7b46c1f 100644 --- a/tests/PhpWord/Tests/Style/TableTest.php +++ b/tests/PhpWord/Tests/Style/TableTest.php @@ -38,6 +38,9 @@ class TableTest extends \PHPUnit_Framework_TestCase $styleTable = array('bgColor' => 'FF0000'); $styleFirstRow = array('borderBottomSize' => 3); + $object = new Table(); + $this->assertNull($object->getBgColor()); + $object = new Table($styleTable, $styleFirstRow); $this->assertEquals('FF0000', $object->getBgColor()); diff --git a/tests/PhpWord/Tests/Style/TabsTest.php b/tests/PhpWord/Tests/Style/TabsTest.php deleted file mode 100644 index 94f6c900..00000000 --- a/tests/PhpWord/Tests/Style/TabsTest.php +++ /dev/null @@ -1,55 +0,0 @@ -addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot')))); - $doc = TestHelperDOCX::getDocument($phpWord); - $file = 'word/styles.xml'; - $path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]'; - $element = $doc->getElement($path, $file); - $this->assertEquals('left', $element->getAttribute('w:val')); - $this->assertEquals(1440, $element->getAttribute('w:pos')); - $this->assertEquals('dot', $element->getAttribute('w:leader')); - } -}