DateRecurPartGridUnitTest.php in Recurring Dates Field 3.1.x
File
tests/src/Unit/DateRecurPartGridUnitTest.php
View source
<?php
namespace Drupal\Tests\date_recur\Unit;
use Drupal\date_recur\DateRecurPartGrid;
use Drupal\date_recur\Exception\DateRecurRulePartIncompatible;
use Drupal\Tests\UnitTestCase;
class DateRecurPartGridUnitTest extends UnitTestCase {
public function testOriginal() {
$partGrid = $this
->createPartGrid();
$this
->assertTrue($partGrid
->isAllowEverything());
$this
->assertTrue($partGrid
->isFrequencyAllowed('WEEKLY'));
$this
->assertTrue($partGrid
->isPartAllowed('DAILY', 'BYMONTH'));
}
public function testAllowParts() {
$partGrid = $this
->createPartGrid();
$partGrid
->allowParts('DAILY', [
'BYSETPOS',
]);
$this
->assertFalse($partGrid
->isAllowEverything());
$this
->assertTrue($partGrid
->isFrequencyAllowed('DAILY'));
$this
->assertFalse($partGrid
->isFrequencyAllowed('WEEKLY'));
$this
->assertTrue($partGrid
->isPartAllowed('DAILY', 'BYSETPOS'));
$this
->assertFalse($partGrid
->isPartAllowed('DAILY', 'BYMONTH'));
}
public function testSettingsToGridOriginal() {
$parts = [];
$partGrid = DateRecurPartGrid::configSettingsToGrid($parts);
$this
->assertTrue($partGrid
->isAllowEverything());
}
public function testSettingsToGridAllowEverything() {
$parts = [
'all' => TRUE,
];
$partGrid = DateRecurPartGrid::configSettingsToGrid($parts);
$this
->assertTrue($partGrid
->isAllowEverything());
$parts = [
'all' => FALSE,
];
$partGrid = DateRecurPartGrid::configSettingsToGrid($parts);
$this
->assertTrue($partGrid
->isAllowEverything());
}
public function testSettingsToGridAllFrequenciesDisabled() {
$parts = [
'all' => FALSE,
'frequencies' => [
'WEEKLY' => [],
],
];
$partGrid = DateRecurPartGrid::configSettingsToGrid($parts);
$this
->assertFalse($partGrid
->isFrequencyAllowed('WEEKLY'));
$this
->assertFalse($partGrid
->isFrequencyAllowed('DAILY'));
}
public function testSettingsToGridAllPartsForFrequencyAllowed() {
$parts = [
'all' => FALSE,
'frequencies' => [
'WEEKLY' => [],
'MONTHLY' => [
'*',
'BYSETPOS',
],
],
];
$partGrid = DateRecurPartGrid::configSettingsToGrid($parts);
$this
->assertFalse($partGrid
->isFrequencyAllowed('WEEKLY'));
$this
->assertFalse($partGrid
->isPartAllowed('WEEKLY', 'BYSETPOS'));
$this
->assertFalse($partGrid
->isFrequencyAllowed('DAILY'));
$this
->assertFalse($partGrid
->isPartAllowed('DAILY', 'BYSETPOS'));
$this
->assertTrue($partGrid
->isFrequencyAllowed('MONTHLY'));
$this
->assertTrue($partGrid
->isPartAllowed('MONTHLY', 'BYSETPOS'));
$this
->assertTrue($partGrid
->isPartAllowed('MONTHLY', 'BYMONTH'));
}
public function testIncompatiblePartException() {
$partGrid = $this
->createPartGrid();
$partGrid
->allowParts('DAILY', [
'*',
]);
$this
->expectException(DateRecurRulePartIncompatible::class);
$partGrid
->isPartAllowed('DAILY', 'BYWEEKNO');
}
protected function createPartGrid() {
return new DateRecurPartGrid();
}
}