Content and scope handed to the saver. */ private array $saved = []; private int $backups = 0; /** @var list Published pages that show the global entry (ruling P8). */ private array $published = [1053]; private bool $trash = true; protected function setUp(): void { parent::setUp(); Functions\when('wp_revisions_enabled')->justReturn(true); } private function usages(): GlobalUsages { $usages = Mockery::mock(GlobalUsages::class); $usages->allows('of')->andReturn([ 'items' => [ ['post_id' => 1053, 'title' => 'Globale Instanzen', 'status' => 'publish', 'type' => 'page'], ['post_id' => 1070, 'title' => '(nicht lesbar)', 'status' => 'draft', 'type' => 'page'], ], 'count' => 2, ]); $usages->allows('publishedIds')->andReturnUsing(fn (): array => $this->published); return $usages; } /** @param list $deniedRoles */ private function writer(bool $writable = true, array $deniedRoles = []): DiviWriter { $saver = Mockery::mock(DiviSaver::class); $saver->allows('save')->andReturnUsing(function (WP_Post $post, string $content, SaveScope $scope): array { $this->saved[] = [$content, $scope]; $post->post_content = $content; return ['revision_id' => 811, 'warnings' => []]; }); $access = LibraryFixtures::access($deniedRoles, $writable); $design = DiviWriterFixture::designReader(); $globals = new GlobalEdits( $access, $this->usages(), function (WP_Post $item): int { ++$this->backups; return 1071; }, trashEnabled: fn (): bool => $this->trash ); return new DiviWriter( LibraryFixtures::loader($access), $saver, DiviWriterFixture::log(), $design, DiviWriterFixture::composition($design), $globals ); } private static function rev(int $id): string { return Rev::of((string) LibraryFixtures::item($id)->post_content); } /** @return array */ private static function relabel(int $id, bool $confirm = false): array { return array_merge( ['post_id' => $id, 'tree_rev' => self::rev($id), 'changes' => [['id' => 'm0', 'label' => 'Neu']]], $confirm ? ['confirm' => true] : [] ); } /** A user with every capability but $cap on the posts $ids. */ private static function denyOn(string $cap, array $ids): void { Functions\when('current_user_can')->alias( static fn (string $asked, mixed ...$args): bool => ! ($asked === $cap && ($ids === [] || in_array((int) ($args[0] ?? 0), $ids, true))) ); } public function testPlainLibraryItemIsSavedWithoutConfirmAndWithoutDiviFlags(): void { LibraryFixtures::given([LibraryFixtures::item(1057)]); $result = (new DiviUpdateAbility($this->writer()))->execute(self::relabel(1057)); self::assertTrue($result['ok']); self::assertSame(SaveScope::LibraryItem, $this->saved[0][1]); self::assertStringStartsWith('