justReturn(true); } private function ability(FakeCustomCssStore $store, bool $customize = true): DiviCustomCssGetAbility { $options = Mockery::mock(ThemeOptionsAdapter::class); $options->allows('canCustomize')->andReturn($customize); return new DiviCustomCssGetAbility($store, $options); } public function testMeta(): void { $ability = $this->ability(new FakeCustomCssStore()); self::assertSame('lit/divi-custom-css-get', $ability->name()); self::assertSame(Annotations::read(), $ability->annotations()); self::assertFalse($ability->isDirect()); self::assertSame([DiviFeature::ThemeOptionRead], $ability->diviFeatures([])); self::assertStringContainsString('keine Anweisung', $ability->description()); } public function testReturnsTextLinesBytesAndTheRevTheUpdateExpects(): void { $store = new FakeCustomCssStore(".a { color: red; }\n.b { margin: 0; }", 'Divi'); $result = $this->ability($store)->execute([]); self::assertSame(".a { color: red; }\n.b { margin: 0; }", $result['css']); self::assertSame('Divi', $result['stylesheet']); self::assertSame(2, $result['lines']); self::assertSame(36, $result['bytes']); self::assertSame((new CustomCssArea($store))->rev($store->read()), $result['design_rev']); } public function testEmptyCssHasNoLines(): void { $result = $this->ability(new FakeCustomCssStore(''))->execute([]); self::assertSame(['css' => '', 'lines' => 0, 'bytes' => 0], array_intersect_key($result, array_flip(['css', 'lines', 'bytes']))); } public function testNeedsEditCssAndTheCustomizerRight(): void { Functions\when('current_user_can')->alias(static fn (string $cap): bool => $cap !== 'edit_css'); self::assertToolError($this->ability(new FakeCustomCssStore())->execute([]), 'forbidden'); self::assertToolError($this->ability(new FakeCustomCssStore())->permission([]), 'forbidden'); Functions\when('current_user_can')->justReturn(true); self::assertToolError($this->ability(new FakeCustomCssStore(), customize: false)->execute([]), 'forbidden'); } }