192 lines
5.0 KiB
PHP
Raw Normal View History

<?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
2022-09-16 11:45:45 +02:00
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Style;
use PhpOffice\PhpWord\Style\Chart;
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Style\Chart.
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Chart
2022-09-16 11:45:45 +02:00
*
* @runTestsInSeparateProcesses
*/
class ChartTest extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* Testing getter and setter for chart width.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetWidth(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getWidth(), 1000000);
$chart->setWidth(200);
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getWidth(), 200);
}
/**
2022-09-16 11:45:45 +02:00
* Testing getter and setter for chart height.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetHeight(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getHeight(), 1000000);
$chart->setHeight(200);
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getHeight(), 200);
}
/**
2022-09-16 11:45:45 +02:00
* Testing getter and setter for is3d.
*/
2022-09-16 11:45:45 +02:00
public function testSetIs3d(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->is3d(), false);
$chart->set3d(true);
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->is3d(), true);
}
/**
2022-09-16 11:45:45 +02:00
* Testing getter and setter for chart colors.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetColors(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertIsArray($chart->getColors());
2022-09-16 11:45:45 +02:00
self::assertEquals(count($chart->getColors()), 0);
2022-09-16 11:45:45 +02:00
$chart->setColors(['FFFFFFFF', 'FF000000', 'FFFF0000']);
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']);
}
/**
2022-09-16 11:45:45 +02:00
* Testing getter and setter for dataLabelOptions.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetDataLabelOptions(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
$originalDataLabelOptions = [
'showVal' => true,
'showCatName' => true,
'showLegendKey' => false,
'showSerName' => false,
'showPercent' => false,
'showLeaderLines' => false,
'showBubbleSize' => false,
];
self::assertEquals($chart->getDataLabelOptions(), $originalDataLabelOptions);
$changedDataLabelOptions = [
'showVal' => false,
'showCatName' => false,
'showLegendKey' => true,
'showSerName' => true,
'showPercent' => true,
'showLeaderLines' => true,
'showBubbleSize' => true,
];
$chart->setDataLabelOptions(
2022-09-16 11:45:45 +02:00
[
'showVal' => false,
'showCatName' => false,
'showLegendKey' => true,
'showSerName' => true,
'showPercent' => true,
'showLeaderLines' => true,
'showBubbleSize' => true,
]
);
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions);
}
/**
2022-09-16 11:45:45 +02:00
* Testing categoryLabelPosition getter and setter.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetCategoryLabelPosition(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getCategoryLabelPosition(), 'nextTo');
$chart->setCategoryLabelPosition('high');
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getCategoryLabelPosition(), 'high');
}
/**
2022-09-16 11:45:45 +02:00
* Testing valueLabelPosition getter and setter.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetValueLabelPosition(): void
{
$chart = new Chart();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getValueLabelPosition(), 'nextTo');
$chart->setValueLabelPosition('low');
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getValueLabelPosition(), 'low');
}
/**
2022-09-16 11:45:45 +02:00
* Testing categoryAxisTitle getter and setter.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetCategoryAxisTitle(): void
{
$chart = new Chart();
$chart->getCategoryAxisTitle();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getCategoryAxisTitle(), null);
$chart->setCategoryAxisTitle('Test Category Axis Title');
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getCategoryAxisTitle(), 'Test Category Axis Title');
}
/**
2022-09-16 11:45:45 +02:00
* Testing valueAxisTitle getter and setter.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetValueAxisTitle(): void
{
$chart = new Chart();
$chart->getValueAxisTitle();
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getValueAxisTitle(), null);
$chart->setValueAxisTitle('Test Value Axis Title');
2022-09-16 11:45:45 +02:00
self::assertEquals($chart->getValueAxisTitle(), 'Test Value Axis Title');
}
}