Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
* @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
* @see https://github.com/PHPOffice/PHPWord
*/

namespace PhpOffice\PhpWord\Style;
Expand Down Expand Up @@ -61,7 +61,7 @@ class Chart extends AbstractStyle
private $dataLabelOptions = array(
"showVal" => true, // value
"showCatName" => true, // category name
"showLegendKey" => false,
"showLegendKey" => false, //show the cart legend
"showSerName" => false, // series name
"showPercent" => false,
"showLeaderLines" => false,
Expand Down Expand Up @@ -126,7 +126,6 @@ public function getWidth()

/**
* Set width
*
* @param int $value
* @return self
*/
Expand Down Expand Up @@ -172,7 +171,6 @@ public function is3d()

/**
* Set 3D
*
* @param bool $value
* @return self
*/
Expand Down
182 changes: 182 additions & 0 deletions tests/PhpWord/Style/ChartTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Style;

/**
* Test class for PhpOffice\PhpWord\Style\Chart
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Chart
* @runTestsInSeparateProcesses
*/
class ChartTest extends \PHPUnit\Framework\TestCase
{
/**
* Testing getter and setter for chart width
*/
public function testSetGetWidth() {

$chart = new Chart();

$this->assertEquals($chart->getWidth(), 1000000);

$chart->setWidth(200);

$this->assertEquals($chart->getWidth(), 200);

}

/**
* Testing getter and setter for chart height
*/
public function testSetGetHeight() {
$chart = new Chart();

$this->assertEquals($chart->getHeight(), 1000000);

$chart->setHeight(200);

$this->assertEquals($chart->getHeight(), 200);
}

/**
* Testing getter and setter for is3d
*/
public function testSetIs3d() {
$chart = new Chart();

$this->assertEquals($chart->is3d(), false);

$chart->set3d(true);

$this->assertEquals($chart->is3d(), true);
}

/**
* Testing getter and setter for chart colors
*/
public function testSetGetColors() {
$chart = new Chart();

$this->assertInternalType('array', $chart->getColors());

$this->assertEquals(count($chart->getColors()), 0);

$chart->setColors(['FFFFFFFF', 'FF000000', 'FFFF0000']);

$this->assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']);
}

/**
* Testing getter and setter for dataLabelOptions
*/
public function testSetGetDataLabelOptions() {

$chart = new Chart();

$originalDataLabelOptions = array(
"showVal" => true,
"showCatName" => true,
"showLegendKey" => false,
"showSerName" => false,
"showPercent" => false,
"showLeaderLines" => false,
"showBubbleSize" => false,
);

$this->assertEquals($chart->getDataLabelOptions(), $originalDataLabelOptions);

$changedDataLabelOptions = array(
"showVal" => false,
"showCatName" => false,
"showLegendKey" => true,
"showSerName" => true,
"showPercent" => true,
"showLeaderLines" => true,
"showBubbleSize" => true,
);

$chart->setDataLabelOptions(
array(
"showVal" => false,
"showCatName" => false,
"showLegendKey" => true,
"showSerName" => true,
"showPercent" => true,
"showLeaderLines" => true,
"showBubbleSize" => true,
));
$this->assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions);
}

/**
* Testing categoryLabelPosition getter and setter
*/
public function testSetGetCategoryLabelPosition() {
$chart = new Chart();

$this->assertEquals($chart->getCategoryLabelPosition(), "none");

$chart->setCategoryLabelPosition("nextTo");

$this->assertEquals($chart->getCategoryLabelPosition(), "nextTo");

}
/**
* Testing valueLabelPosition getter and setter
*/
public function testSetGetValueLabelPosition() {
$chart = new Chart();

$this->assertEquals($chart->getValueLabelPosition(), "none");

$chart->setValueLabelPosition("low");

$this->assertEquals($chart->getValueLabelPosition(), "low");

}

/**
* Testing categoryAxisTitle getter and setter
*/
public function testSetGetCategoryAxisTitle() {
$chart = new Chart();

$chart->getCategoryAxisTitle();

$this->assertEquals($chart->getCategoryAxisTitle(), NULL);

$chart->setCategoryAxisTitle("Test Category Axis Title");

$this->assertEquals($chart->getCategoryAxisTitle(), "Test Category Axis Title");
}

/**
* Testing valueAxisTitle getter and setter
*/
public function testSetGetValueAxisTitle() {
$chart = new Chart();

$chart->getValueAxisTitle();

$this->assertEquals($chart->getValueAxisTitle(), NULL);

$chart->setValueAxisTitle("Test Value Axis Title");

$this->assertEquals($chart->getValueAxisTitle(), "Test Value Axis Title");
}
}