PhpSpreadsheet/tests/PhpSpreadsheetTests/Style/ColorTest.php

91 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Style;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PHPUnit\Framework\TestCase;
class ColorTest extends TestCase
{
/**
* @dataProvider providerColorGetRed
*
* @param mixed $expectedResult
*/
2020-05-18 04:49:57 +00:00
public function testGetRed($expectedResult, ...$args): void
2015-05-17 13:00:02 +00:00
{
$result = Color::getRed(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerColorGetRed()
{
return require 'tests/data/Style/ColorGetRed.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerColorGetGreen
*
* @param mixed $expectedResult
*/
2020-05-18 04:49:57 +00:00
public function testGetGreen($expectedResult, ...$args): void
2015-05-17 13:00:02 +00:00
{
$result = Color::getGreen(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerColorGetGreen()
{
return require 'tests/data/Style/ColorGetGreen.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerColorGetBlue
*
* @param mixed $expectedResult
*/
2020-05-18 04:49:57 +00:00
public function testGetBlue($expectedResult, ...$args): void
2015-05-17 13:00:02 +00:00
{
$result = Color::getBlue(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerColorGetBlue()
{
return require 'tests/data/Style/ColorGetBlue.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerColorChangeBrightness
*
* @param mixed $expectedResult
*/
2020-05-18 04:49:57 +00:00
public function testChangeBrightness($expectedResult, ...$args): void
2015-05-17 13:00:02 +00:00
{
$result = Color::changeBrightness(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerColorChangeBrightness()
{
return require 'tests/data/Style/ColorChangeBrightness.php';
2015-05-17 13:00:02 +00:00
}
Add exportArray Method for Styles (#1580) Issue #580 has gone stale since I started work on this. Nevertheless, this implements an exportArray function as an exact counterpart of applyFromArry. I chose the name exportArray to avoid confusion with the existing method getStyleArray, which does something completely different. This change also increases coverage for all the Style classes to 100%, with the exception of Style.php itself. There were several (unchanged) places in Style.php where I did not have sufficient understanding of what was supposed to be happening, so could not create tests. All properties used by applyFromArray are exported by this method. Note that conditional styles are not covered; this is consistent with the fact that they are not covered by applyFromArray. The method is implemented as a final public function in Style/Supervisor, which calls abstract protected function exportArray1, which is implemented in each of the subclasses, and which calls final protected function exportArray2 in Style/Supervisor. So exportArray is usable for any of the subclasses as well. The new method is added to the documentation. The existing documentation for applyFromArray was alphabetized to make it easier to follow. One property (Style quotePrefix) was added to the documentation. Some Borders pseudo-properties (vertical, horizontal, and outline) were documented as usable by applyFromArray, but aren't actually supported - they were removed. The documentation of the properties seemed to use setProperty and getProperty fairly randomly - it now uses setProperty exclusively. New constants were added for the textRotation "angles" used to create a "stacked" cell. I felt that changing the readers and writers to use these constants was beyond the scope of this change, but it is on my to-do list.
2020-10-26 19:56:24 +00:00
public function testDefaultColor(): void
{
$color = new Color();
$color->setARGB('FFFF0000');
self::assertEquals('FFFF0000', $color->getARGB());
self::assertEquals('FF0000', $color->getRGB());
$color->setARGB('');
self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
self::assertEquals('000000', $color->getRGB());
$color->setARGB('FFFF0000');
self::assertEquals('FFFF0000', $color->getARGB());
self::assertEquals('FF0000', $color->getRGB());
$color->setRGB('');
self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
self::assertEquals('000000', $color->getRGB());
}
}