PhpSpreadsheet/tests/PhpSpreadsheetTests/Style/ConditionalTest.php

53 lines
2.1 KiB
PHP
Raw Normal View History

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
<?php
namespace PhpOffice\PhpSpreadsheetTests\Style;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PHPUnit\Framework\TestCase;
class ConditionalTest extends TestCase
{
public function testClone(): void
{
$condition1 = new Conditional();
$condition1->setConditionType(Conditional::CONDITION_CELLIS);
$condition1->setOperatorType(Conditional::OPERATOR_LESSTHAN);
$condition1->addCondition(0.6);
$condition1->getStyle()->getFill()
->setFillType(Fill::FILL_SOLID)
->getEndColor()->setARGB('FFFF0000');
$conditionclone = clone $condition1;
self::AssertEquals($condition1, $conditionclone);
self::AssertEquals($condition1->getStyle(), $conditionclone->getStyle());
self::AssertNotSame($condition1->getStyle(), $conditionclone->getStyle());
}
public function testVariousAdds(): void
{
$condition1 = new Conditional();
$condition1->setConditionType(Conditional::CONDITION_CELLIS);
$condition1->setOperatorType(Conditional::OPERATOR_LESSTHAN);
$condition1->addCondition(0.6);
$condition1->getStyle()->getFill()
->setFillType(Fill::FILL_SOLID)
->getEndColor()->setARGB('FFFF0000');
$condition2 = new Conditional();
$condition2->setConditionType(Conditional::CONDITION_CELLIS);
$condition2->setOperatorType(Conditional::OPERATOR_LESSTHAN);
$condition2->setConditions(0.6);
$condition2->getStyle()->getFill()
->setFillType(Fill::FILL_SOLID)
->getEndColor()->setARGB('FFFF0000');
$condition3 = new Conditional();
$condition3->setConditionType(Conditional::CONDITION_CELLIS);
$condition3->setOperatorType(Conditional::OPERATOR_LESSTHAN);
$condition3->setConditions([0.6]);
$condition3->getStyle()->getFill()
->setFillType(Fill::FILL_SOLID)
->getEndColor()->setARGB('FFFF0000');
self::AssertEquals($condition1, $condition2);
self::AssertEquals($condition1, $condition3);
}
}