Files
oleibman d55978cf93 Correct Namespaces in 11 Tests (#3020)
The setup for unit testing in Github in the "Install dependencies" log reports 11 members as "does not comply with with psr-4 autoloading standard." In each case, it is because the test namespace does not match the directory; in most cases, it was caused by the member being moved from one directory to another without changing the namespace declaration. No harm results from these problems, but there's also no reason to not correct them.
2022-08-20 19:58:43 -07:00

78 lines
2.4 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting\Wizard;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
use PhpOffice\PhpSpreadsheet\Style\Style;
use PHPUnit\Framework\TestCase;
class DateValueWizardTest extends TestCase
{
/**
* @var Style
*/
protected $style;
/**
* @var string
*/
protected $range = '$C$3:$E$5';
/**
* @var Wizard
*/
protected $wizardFactory;
protected function setUp(): void
{
$this->wizardFactory = new Wizard($this->range);
$this->style = new Style();
}
/**
* @dataProvider dateValueWizardProvider
*/
public function testDateValueWizard(string $operator, string $expectedReference, string $expectedExpression): void
{
$ruleType = Wizard::DATES_OCCURRING;
/** @var Wizard\DateValue $dateWizard */
$dateWizard = $this->wizardFactory->newRule($ruleType);
$dateWizard->setStyle($this->style);
$dateWizard->$operator();
$conditional = $dateWizard->getConditional();
self::assertSame(Conditional::CONDITION_TIMEPERIOD, $conditional->getConditionType());
self:self::assertSame($expectedReference, $conditional->getText());
$conditions = $conditional->getConditions();
self::assertSame([$expectedExpression], $conditions);
$newWizard = Wizard::fromConditional($conditional, $this->range);
$newWizard->getConditional();
self::assertEquals($newWizard, $dateWizard, 'fromConditional() Failure');
}
public function dateValueWizardProvider(): array
{
return [
['today', 'today', 'FLOOR(C3,1)=TODAY()'],
['yesterday', 'yesterday', 'FLOOR(C3,1)=TODAY()-1'],
['tomorrow', 'tomorrow', 'FLOOR(C3,1)=TODAY()+1'],
['lastSevenDays', 'last7Days', 'AND(TODAY()-FLOOR(C3,1)<=6,FLOOR(C3,1)<=TODAY())'],
];
}
public function testInvalidFromConditional(): void
{
$ruleType = 'Unknown';
$this->expectException(Exception::class);
$this->expectExceptionMessage('Conditional is not a Date Value CF Rule conditional');
$conditional = new Conditional();
$conditional->setConditionType($ruleType);
Wizard\DateValue::fromConditional($conditional);
}
}