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\Legend;
|
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 LegendTest extends TestCase
|
2012-06-24 12:34:57 +00:00
|
|
|
{
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetPosition(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$positionValues = [
|
2016-08-14 04:08:43 +00:00
|
|
|
Legend::POSITION_RIGHT,
|
|
|
|
Legend::POSITION_LEFT,
|
|
|
|
Legend::POSITION_TOP,
|
|
|
|
Legend::POSITION_BOTTOM,
|
|
|
|
Legend::POSITION_TOPRIGHT,
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($positionValues as $positionValue) {
|
|
|
|
$result = $testInstance->setPosition($positionValue);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertTrue($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetInvalidPositionReturnsFalse(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->setPosition('BottomLeft');
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
// Ensure that value is unchanged
|
|
|
|
$result = $testInstance->getPosition();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals(Legend::POSITION_RIGHT, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetPosition(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$PositionValue = Legend::POSITION_BOTTOM;
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2017-10-29 05:09:38 +00:00
|
|
|
$testInstance->setPosition($PositionValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->getPosition();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($PositionValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetPositionXL(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$positionValues = [
|
2016-08-14 04:08:43 +00:00
|
|
|
Legend::XL_LEGEND_POSITION_BOTTOM,
|
|
|
|
Legend::XL_LEGEND_POSITION_CORNER,
|
|
|
|
Legend::XL_LEGEND_POSITION_CUSTOM,
|
|
|
|
Legend::XL_LEGEND_POSITION_LEFT,
|
|
|
|
Legend::XL_LEGEND_POSITION_RIGHT,
|
|
|
|
Legend::XL_LEGEND_POSITION_TOP,
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($positionValues as $positionValue) {
|
|
|
|
$result = $testInstance->setPositionXL($positionValue);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertTrue($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetInvalidXLPositionReturnsFalse(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->setPositionXL(999);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
// Ensure that value is unchanged
|
|
|
|
$result = $testInstance->getPositionXL();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals(Legend::XL_LEGEND_POSITION_RIGHT, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetPositionXL(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$PositionValue = Legend::XL_LEGEND_POSITION_CORNER;
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2017-10-29 05:09:38 +00:00
|
|
|
$testInstance->setPositionXL($PositionValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->getPositionXL();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($PositionValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetOverlay(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$overlayValues = [
|
2015-05-17 13:00:02 +00:00
|
|
|
true,
|
|
|
|
false,
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($overlayValues as $overlayValue) {
|
|
|
|
$result = $testInstance->setOverlay($overlayValue);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertTrue($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetInvalidOverlayReturnsFalse(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->setOverlay('INVALID');
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->getOverlay();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGetOverlay(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$OverlayValue = true;
|
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
$testInstance = new Legend();
|
2017-10-29 05:09:38 +00:00
|
|
|
$testInstance->setOverlay($OverlayValue);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$result = $testInstance->getOverlay();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($OverlayValue, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-24 12:34:57 +00:00
|
|
|
}
|