2012-06-24 12:34:57 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Chart;
|
2012-06-24 12:34:57 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class DataSeriesValuesTest extends TestCase
|
2012-06-24 12:34:57 +00:00
|
|
|
{
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetDataType(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$dataTypeValues = [
|
2015-05-17 13:00:02 +00:00
|
|
|
'Number',
|
2016-08-16 15:33:57 +00:00
|
|
|
'String',
|
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new DataSeriesValues();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($dataTypeValues as $dataTypeValue) {
|
|
|
|
$result = $testInstance->setDataType($dataTypeValue);
|
2017-12-06 09:46:31 +00:00
|
|
|
self::assertInstanceOf(DataSeriesValues::class, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetInvalidDataTypeThrowsException(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new DataSeriesValues();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
try {
|
2016-08-26 06:05:40 +00:00
|
|
|
$testInstance->setDataType('BOOLEAN');
|
2016-08-14 04:08:43 +00:00
|
|
|
} catch (Exception $e) {
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($e->getMessage(), 'Invalid datatype for chart data series values');
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-18 04:49:57 +00:00
|
|
|
self::fail('An expected exception has not been raised.');
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetDataType(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$dataTypeValue = 'String';
|
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new DataSeriesValues();
|
2016-08-26 06:05:40 +00:00
|
|
|
$testInstance->setDataType($dataTypeValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->getDataType();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($dataTypeValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2018-01-09 23:12:38 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetLineWidth(): void
|
2018-01-09 23:12:38 +00:00
|
|
|
{
|
|
|
|
$testInstance = new DataSeriesValues();
|
|
|
|
self::assertEquals(12700, $testInstance->getLineWidth(), 'should have default');
|
|
|
|
|
|
|
|
$testInstance->setLineWidth(40000);
|
|
|
|
self::assertEquals(40000, $testInstance->getLineWidth());
|
|
|
|
|
|
|
|
$testInstance->setLineWidth(1);
|
|
|
|
self::assertEquals(12700, $testInstance->getLineWidth(), 'should enforce minimum width');
|
|
|
|
}
|
2018-11-09 12:29:55 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testFillColorCorrectInput(): void
|
2018-11-09 12:29:55 +00:00
|
|
|
{
|
|
|
|
$testInstance = new DataSeriesValues();
|
|
|
|
|
|
|
|
self::assertEquals($testInstance, $testInstance->setFillColor('00abb8'));
|
|
|
|
self::assertEquals($testInstance, $testInstance->setFillColor(['00abb8', 'b8292f']));
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testFillColorInvalidInput(): void
|
2018-11-09 12:29:55 +00:00
|
|
|
{
|
|
|
|
$testInstance = new DataSeriesValues();
|
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Invalid hex color for chart series');
|
|
|
|
|
|
|
|
$testInstance->setFillColor('WRONG COLOR');
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testFillColorInvalidInputInArray(): void
|
2018-11-09 12:29:55 +00:00
|
|
|
{
|
|
|
|
$testInstance = new DataSeriesValues();
|
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Invalid hex color for chart series (color: "WRONG COLOR")');
|
|
|
|
|
|
|
|
$testInstance->setFillColor(['b8292f', 'WRONG COLOR']);
|
|
|
|
}
|
2012-06-24 12:34:57 +00:00
|
|
|
}
|