|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * The aanbesteding package seeds its decision types and its standstill term |
| 5 | + * |
| 6 | + * An award is a decision, and a refusal of a bid is one too; both are decision |
| 7 | + * types of the tender case type. The award only becomes final once the 20-day |
| 8 | + * standstill term has ended, so the package also ships that term for the case |
| 9 | + * type, counted in calendar days. |
| 10 | + * |
| 11 | + * @category Test |
| 12 | + * @package OCA\Dossiq\Tests\Unit\Settings |
| 13 | + * |
| 14 | + * @author Conduction Development Team <info@conduction.nl> |
| 15 | + * @copyright 2026 Conduction B.V. |
| 16 | + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 |
| 17 | + * |
| 18 | + * SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl> |
| 19 | + * SPDX-License-Identifier: EUPL-1.2 |
| 20 | + * |
| 21 | + * @link https://conduction.nl |
| 22 | + * |
| 23 | + * @spec openspec/changes/tenders-run-on-the-tender-case-type/tasks.md |
| 24 | + */ |
| 25 | + |
| 26 | +declare(strict_types=1); |
| 27 | + |
| 28 | +namespace OCA\Dossiq\Tests\Unit\Settings; |
| 29 | + |
| 30 | +use OCA\Dossiq\Service\CaseDefinition\ShippedPackageRules; |
| 31 | +use PHPUnit\Framework\TestCase; |
| 32 | + |
| 33 | +class AanbestedingPackageSeedTest extends TestCase { |
| 34 | + |
| 35 | + /** |
| 36 | + * The package directory. |
| 37 | + */ |
| 38 | + private const DIR = __DIR__ . '/../../../lib/Settings/packages/aanbesteding'; |
| 39 | + |
| 40 | + /** |
| 41 | + * One file of the package, decoded. |
| 42 | + * |
| 43 | + * @param string $path The path in the package. |
| 44 | + * |
| 45 | + * @return array<string, mixed> |
| 46 | + */ |
| 47 | + private static function json(string $path): array { |
| 48 | + return json_decode((string)file_get_contents(self::DIR . '/' . $path), true, 512, JSON_THROW_ON_ERROR); |
| 49 | + }//end json() |
| 50 | + |
| 51 | + /** |
| 52 | + * A schema of the register by key, from the main file or a fragment. |
| 53 | + * |
| 54 | + * @param string $key The schema key. |
| 55 | + * |
| 56 | + * @return array<string, mixed> |
| 57 | + */ |
| 58 | + private static function schema(string $key): array { |
| 59 | + $files = array_merge([__DIR__ . '/../../../lib/Settings/dossiq_register.json'], glob(__DIR__ . '/../../../lib/Settings/register.d/*.json')); |
| 60 | + foreach ($files as $file) { |
| 61 | + $register = json_decode((string)file_get_contents($file), true); |
| 62 | + if (isset($register['components']['schemas'][$key]) === true) { |
| 63 | + return $register['components']['schemas'][$key]; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return []; |
| 68 | + }//end schema() |
| 69 | + |
| 70 | + public function testThePackagePassesTheShippedPackageRulesWithItsSeed(): void { |
| 71 | + $files = []; |
| 72 | + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::DIR, \FilesystemIterator::SKIP_DOTS)); |
| 73 | + foreach ($iterator as $file) { |
| 74 | + $files[substr($file->getPathname(), strlen(self::DIR) + 1)] = (string)file_get_contents($file->getPathname()); |
| 75 | + } |
| 76 | + |
| 77 | + $result = (new ShippedPackageRules())->check(['id' => 'aanbesteding', 'files' => $files]); |
| 78 | + |
| 79 | + $this->assertSame([], $result['errors']); |
| 80 | + $this->assertSame([], $result['warnings']); |
| 81 | + $this->assertTrue($result['valid']); |
| 82 | + $this->assertContains('seed', $result['manifest']['parts']); |
| 83 | + $this->assertSame('1.9.0', $result['manifest']['version']); |
| 84 | + }//end testThePackagePassesTheShippedPackageRulesWithItsSeed() |
| 85 | + |
| 86 | + public function testTheAwardAndTheRefusalAreDecisionTypesOfTheTenderCaseType(): void { |
| 87 | + $caseType = self::json('case-type.json')['caseType']['id']; |
| 88 | + $seed = self::json('seed/10-decision-types.json'); |
| 89 | + |
| 90 | + $this->assertSame('decision_type_schema', $seed['schema']); |
| 91 | + $this->assertSame(['Gunningsbeslissing', 'Afwijzingsbeslissing'], array_column($seed['rows'], 'name')); |
| 92 | + $declared = array_keys(self::schema('decisionType')['properties']); |
| 93 | + foreach ($seed['rows'] as $row) { |
| 94 | + $this->assertSame($caseType, $row['caseType']); |
| 95 | + $this->assertSame([$caseType], $row['caseTypes']); |
| 96 | + $this->assertFalse($row['isDraft']); |
| 97 | + $this->assertNotSame('', trim($row['description'])); |
| 98 | + $this->assertSame([], array_diff(array_keys($row), array_merge($declared, ['id'])), 'only declared fields'); |
| 99 | + } |
| 100 | + |
| 101 | + $this->assertSame(2, count(array_unique(array_column($seed['rows'], 'id')))); |
| 102 | + }//end testTheAwardAndTheRefusalAreDecisionTypesOfTheTenderCaseType() |
| 103 | + |
| 104 | + public function testTheStandstillIsTwentyCalendarDaysForTheTenderCaseType(): void { |
| 105 | + $seed = self::json('seed/20-standstill-term.json'); |
| 106 | + $schema = self::schema('deadlineDefinition'); |
| 107 | + |
| 108 | + $this->assertSame('termijn_definitie_schema', $seed['schema']); |
| 109 | + $this->assertCount(1, $seed['rows']); |
| 110 | + $term = $seed['rows'][0]; |
| 111 | + |
| 112 | + $this->assertSame(self::json('case-type.json')['caseType']['identifier'], $term['caseType'], 'bound by the case type slug'); |
| 113 | + $this->assertSame('Aw 2012 art. 2.127', $term['legalBasis']); |
| 114 | + $this->assertSame(20, $term['standardDurationDays']); |
| 115 | + $this->assertSame('calendarDays', $term['countingMode']); |
| 116 | + $this->assertFalse($term['rollToWorkingDay']); |
| 117 | + |
| 118 | + foreach ($schema['required'] as $field) { |
| 119 | + $this->assertArrayHasKey($field, $term, "the term carries required $field"); |
| 120 | + } |
| 121 | + |
| 122 | + $this->assertContains($term['countingMode'], $schema['properties']['countingMode']['enum']); |
| 123 | + $this->assertContains($term['kind'], $schema['properties']['kind']['enum']); |
| 124 | + $this->assertSame([], array_diff(array_keys($term), array_merge(array_keys($schema['properties']), ['id'])), 'only declared fields'); |
| 125 | + }//end testTheStandstillIsTwentyCalendarDaysForTheTenderCaseType() |
| 126 | +}//end class |
0 commit comments