justReturn(null); self::assertToolError(MediaGuard::attachment(33), 'not_found'); Functions\when('get_post')->justReturn(new WP_Post(['ID' => 33, 'post_type' => 'page'])); self::assertToolError(MediaGuard::attachment(33), 'not_found'); } public function testChecksTheRequestedCapabilityOnTheAttachment(): void { $attachment = new WP_Post(['ID' => 33, 'post_type' => 'attachment', 'post_status' => 'inherit']); Functions\when('get_post')->justReturn($attachment); Functions\expect('current_user_can')->once()->with('delete_post', 33)->andReturn(false); self::assertToolError(MediaGuard::attachment('33', 'delete_post'), 'forbidden'); } public function testRefusesTrashedAttachmentsUnlessAllowed(): void { $attachment = new WP_Post(['ID' => 33, 'post_type' => 'attachment', 'post_status' => 'trash']); Functions\when('get_post')->justReturn($attachment); Functions\when('current_user_can')->justReturn(true); $error = MediaGuard::attachment(33); self::assertToolError($error, 'validation_failed'); self::assertStringContainsString('Papierkorb', $error->get_error_message()); self::assertSame($attachment, MediaGuard::attachment(33, 'read_post', true)); } }