allows('get_template')->andReturn($template); $theme->allows('parent')->andReturn(false); $theme->allows('get')->with('Version')->andReturn($version); Functions\when('wp_get_theme')->justReturn($theme); } public function testIsAnEnvironmentComponent(): void { self::assertInstanceOf(EnvironmentComponent::class, new DiviEnvironmentComponent()); } public function testCarriesTheCompatibilityFindings(): void { $this->theme('Divi'); $component = new DiviEnvironmentComponent( new DiviCompatibility(['GlobalLayout' => static fn (): bool => false]) ); $described = $component->describe(); self::assertSame('divi', $described['id']); self::assertTrue($described['active']); self::assertSame('5.2.1', $described['version']); self::assertSame(['GlobalLayout'], $described['problems']); } public function testCarriesTheReleaseStatus(): void { $this->theme('Divi'); $described = (new DiviEnvironmentComponent(new DiviCompatibility([])))->describe(); self::assertSame([], $described['problems']); self::assertSame('released', $described['release']['state'] ?? null); } public function testIsInactiveWithoutDiviAndHasNoProblemsOrRelease(): void { $this->theme('twentytwentysix', '1.0'); $described = (new DiviEnvironmentComponent( new DiviCompatibility(['GlobalLayout' => static fn (): bool => false]) ))->describe(); self::assertSame( ['id' => 'divi', 'active' => false, 'version' => null, 'problems' => [], 'release' => null, 'features' => []], $described ); } public function testListsEveryFeatureWithStateSourceProblemsAndTools(): void { $this->theme('Divi', '5.3.0'); $matrix = MatrixFixtures::with( DiviFeature::PageWrite, ReleaseState::Incompatible, 'auto', 'Seiten: Signatur von et_pb_x() geändert' ); ReleaseGate::useResolver(static fn (): ReleaseStatus => ReleaseStatus::of('5.3.0', $matrix)); $overview = new FeatureOverview(static fn (): array => [ new FeatureFakeTool('lit/divi-outline', true, [DiviFeature::PageRead]), new FeatureFakeTool('lit/divi-insert', true, [DiviFeature::PageRead, DiviFeature::PageWrite]), ]); $component = (new DiviEnvironmentComponent(new DiviCompatibility([]), $overview))->describe(); $features = array_column($component['features'], null, 'id'); self::assertSame('divi', $component['id']); self::assertCount(count(DiviFeature::cases()), $features); self::assertSame('incompatible', $features['page-write']['state']); self::assertNull($features['page-write']['source']); self::assertSame(['Seiten: Signatur von et_pb_x() geändert'], $features['page-write']['problems']); self::assertSame(['lit-divi-insert'], $features['page-write']['tools']); self::assertSame('Seiten schreiben', $features['page-write']['label']); self::assertSame('released', $features['page-read']['state']); self::assertSame('auto', $features['page-read']['source']); self::assertSame(['lit-divi-outline', 'lit-divi-insert'], $features['page-read']['tools']); self::assertSame('incompatible', $component['release']['state']); } public function testTheMatrixComesFromTheGateAndIsNotComputedAgain(): void { $this->theme('Divi', '5.3.0'); $calls = 0; ReleaseGate::useResolver(static function () use (&$calls): ReleaseStatus { ++$calls; return ReleaseMatrices::released('5.3.0'); }); $component = new DiviEnvironmentComponent(new DiviCompatibility([])); $component->describe(); $component->describe(); self::assertSame(1, $calls); } public function testWithoutDiviThereAreNoFeaturesAndNoGateCall(): void { $this->theme('twentytwentyfive', '1.0'); ReleaseGate::useResolver(static function (): ReleaseStatus { self::fail('the gate must not be asked without Divi'); }); $component = (new DiviEnvironmentComponent(new DiviCompatibility([])))->describe(); self::assertFalse($component['active']); self::assertSame([], $component['features']); self::assertNull($component['release']); } }