|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of PHPWord - A pure PHP library for reading and writing |
| 4 | + * word processing documents. |
| 5 | + * |
| 6 | + * PHPWord is free software distributed under the terms of the GNU Lesser |
| 7 | + * General Public License version 3 as published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * For the full copyright and license information, please read the LICENSE |
| 10 | + * file that was distributed with this source code. For the full list of |
| 11 | + * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 12 | + * |
| 13 | + * @see https://github.com/PHPOffice/PHPWord |
| 14 | + * @copyright 2010-2017 PHPWord contributors |
| 15 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | + */ |
| 17 | + |
| 18 | +namespace PhpOffice\PhpWord\Style; |
| 19 | + |
| 20 | +/** |
| 21 | + * Test class for PhpOffice\PhpWord\Style\Chart |
| 22 | + * |
| 23 | + * @coversDefaultClass \PhpOffice\PhpWord\Style\Chart |
| 24 | + * @runTestsInSeparateProcesses |
| 25 | + */ |
| 26 | +class ChartTest extends \PHPUnit\Framework\TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * Testing getter and setter for chart width |
| 30 | + */ |
| 31 | + public function testSetGetWidth() { |
| 32 | + |
| 33 | + $chart = new Chart(); |
| 34 | + |
| 35 | + $this->assertEquals($chart->getWidth(), 1000000); |
| 36 | + |
| 37 | + $chart->setWidth(200); |
| 38 | + |
| 39 | + $this->assertEquals($chart->getWidth(), 200); |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Testing getter and setter for chart height |
| 45 | + */ |
| 46 | + public function testSetGetHeight() { |
| 47 | + $chart = new Chart(); |
| 48 | + |
| 49 | + $this->assertEquals($chart->getHeight(), 1000000); |
| 50 | + |
| 51 | + $chart->setHeight(200); |
| 52 | + |
| 53 | + $this->assertEquals($chart->getHeight(), 200); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Testing getter and setter for is3d |
| 58 | + */ |
| 59 | + public function testSetIs3d() { |
| 60 | + $chart = new Chart(); |
| 61 | + |
| 62 | + $this->assertEquals($chart->is3d(), false); |
| 63 | + |
| 64 | + $chart->set3d(true); |
| 65 | + |
| 66 | + $this->assertEquals($chart->is3d(), true); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Testing getter and setter for chart colors |
| 71 | + */ |
| 72 | + public function testSetGetColors() { |
| 73 | + $chart = new Chart(); |
| 74 | + |
| 75 | + $this->assertInternalType('array', $chart->getColors()); |
| 76 | + |
| 77 | + $this->assertEquals(count($chart->getColors()), 0); |
| 78 | + |
| 79 | + $chart->setColors(['FFFFFFFF', 'FF000000', 'FFFF0000']); |
| 80 | + |
| 81 | + $this->assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Testing getter and setter for dataLabelOptions |
| 86 | + */ |
| 87 | + public function testSetGetDataLabelOptions() { |
| 88 | + |
| 89 | + $chart = new Chart(); |
| 90 | + |
| 91 | + $originalDataLabelOptions = array( |
| 92 | + "showVal" => true, |
| 93 | + "showCatName" => true, |
| 94 | + "showLegendKey" => false, |
| 95 | + "showSerName" => false, |
| 96 | + "showPercent" => false, |
| 97 | + "showLeaderLines" => false, |
| 98 | + "showBubbleSize" => false, |
| 99 | + ); |
| 100 | + |
| 101 | + $this->assertEquals($chart->getDataLabelOptions(), $originalDataLabelOptions); |
| 102 | + |
| 103 | + $changedDataLabelOptions = array( |
| 104 | + "showVal" => false, |
| 105 | + "showCatName" => false, |
| 106 | + "showLegendKey" => true, |
| 107 | + "showSerName" => true, |
| 108 | + "showPercent" => true, |
| 109 | + "showLeaderLines" => true, |
| 110 | + "showBubbleSize" => true, |
| 111 | + ); |
| 112 | + |
| 113 | + $chart->setDataLabelOptions( |
| 114 | + array( |
| 115 | + "showVal" => false, |
| 116 | + "showCatName" => false, |
| 117 | + "showLegendKey" => true, |
| 118 | + "showSerName" => true, |
| 119 | + "showPercent" => true, |
| 120 | + "showLeaderLines" => true, |
| 121 | + "showBubbleSize" => true, |
| 122 | + )); |
| 123 | + $this->assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Testing categoryLabelPosition getter and setter |
| 128 | + */ |
| 129 | + public function testSetGetCategoryLabelPosition() { |
| 130 | + $chart = new Chart(); |
| 131 | + |
| 132 | + $this->assertEquals($chart->getCategoryLabelPosition(), "none"); |
| 133 | + |
| 134 | + $chart->setCategoryLabelPosition("nextTo"); |
| 135 | + |
| 136 | + $this->assertEquals($chart->getCategoryLabelPosition(), "nextTo"); |
| 137 | + |
| 138 | + } |
| 139 | + /** |
| 140 | + * Testing valueLabelPosition getter and setter |
| 141 | + */ |
| 142 | + public function testSetGetValueLabelPosition() { |
| 143 | + $chart = new Chart(); |
| 144 | + |
| 145 | + $this->assertEquals($chart->getValueLabelPosition(), "none"); |
| 146 | + |
| 147 | + $chart->setValueLabelPosition("low"); |
| 148 | + |
| 149 | + $this->assertEquals($chart->getValueLabelPosition(), "low"); |
| 150 | + |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Testing categoryAxisTitle getter and setter |
| 155 | + */ |
| 156 | + public function testSetGetCategoryAxisTitle() { |
| 157 | + $chart = new Chart(); |
| 158 | + |
| 159 | + $chart->getCategoryAxisTitle(); |
| 160 | + |
| 161 | + $this->assertEquals($chart->getCategoryAxisTitle(), NULL); |
| 162 | + |
| 163 | + $chart->setCategoryAxisTitle("Test Category Axis Title"); |
| 164 | + |
| 165 | + $this->assertEquals($chart->getCategoryAxisTitle(), "Test Category Axis Title"); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Testing valueAxisTitle getter and setter |
| 170 | + */ |
| 171 | + public function testSetGetValueAxisTitle() { |
| 172 | + $chart = new Chart(); |
| 173 | + |
| 174 | + $chart->getValueAxisTitle(); |
| 175 | + |
| 176 | + $this->assertEquals($chart->getValueAxisTitle(), NULL); |
| 177 | + |
| 178 | + $chart->setValueAxisTitle("Test Value Axis Title"); |
| 179 | + |
| 180 | + $this->assertEquals($chart->getValueAxisTitle(), "Test Value Axis Title"); |
| 181 | + } |
| 182 | +} |
0 commit comments