| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
- use PhpOffice\PhpSpreadsheet\Reader\Xls;
- use PhpOffice\PhpSpreadsheet\Style\Conditional;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use PHPUnit\Framework\TestCase;
- class ConditionalFormattingBasicTest extends TestCase
- {
- /**
- * @var Worksheet
- */
- protected $sheet;
- protected function setUp(): void
- {
- $filename = 'tests/data/Reader/XLS/CF_Basic_Comparisons.xls';
- $reader = new Xls();
- $spreadsheet = $reader->load($filename);
- $this->sheet = $spreadsheet->getActiveSheet();
- }
- /**
- * @dataProvider conditionalFormattingProvider
- */
- public function testReadConditionalFormatting(string $expectedRange, array $expectedRules): void
- {
- $hasConditionalStyles = $this->sheet->conditionalStylesExists($expectedRange);
- self::assertTrue($hasConditionalStyles);
- $conditionalStyles = $this->sheet->getConditionalStyles($expectedRange);
- foreach ($conditionalStyles as $index => $conditionalStyle) {
- self::assertSame($expectedRules[$index]['type'], $conditionalStyle->getConditionType());
- self::assertSame($expectedRules[$index]['operator'], $conditionalStyle->getOperatorType());
- self::assertSame($expectedRules[$index]['conditions'], $conditionalStyle->getConditions());
- }
- }
- public function conditionalFormattingProvider(): array
- {
- return [
- [
- 'A2:E5',
- [
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_EQUAL,
- 'conditions' => [
- 0,
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_GREATERTHAN,
- 'conditions' => [
- 0,
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_LESSTHAN,
- 'conditions' => [
- 0,
- ],
- ],
- ],
- ],
- [
- 'A10:E13',
- [
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_EQUAL,
- 'conditions' => [
- '$H$9',
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_GREATERTHAN,
- 'conditions' => [
- '$H$9',
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_LESSTHAN,
- 'conditions' => [
- '$H$9',
- ],
- ],
- ],
- ],
- [
- 'A18:A20',
- [
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_BETWEEN,
- 'conditions' => [
- '$B1',
- '$C1',
- ],
- ],
- ],
- ],
- [
- 'A24:E27',
- [
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_BETWEEN,
- 'conditions' => [
- 'AVERAGE($A$24:$E$27)-STDEV($A$24:$E$27)',
- 'AVERAGE($A$24:$E$27)+STDEV($A$24:$E$27)',
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_GREATERTHAN,
- 'conditions' => [
- 'AVERAGE($A$24:$E$27)+STDEV($A$24:$E$27)',
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_LESSTHAN,
- 'conditions' => [
- 'AVERAGE($A$24:$E$27)-STDEV($A$24:$E$27)',
- ],
- ],
- ],
- ],
- [
- 'A31:A33',
- [
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_EQUAL,
- 'conditions' => [
- '"LOVE"',
- ],
- ],
- [
- 'type' => Conditional::CONDITION_CELLIS,
- 'operator' => Conditional::OPERATOR_EQUAL,
- 'conditions' => [
- '"PHP"',
- ],
- ],
- ],
- ],
- ];
- }
- }
|