justReturn(new WP_Post(['ID' => 5, 'post_type' => 'page', 'post_title' => 'Team', 'post_status' => $status])); Functions\when('current_user_can')->justReturn(true); Functions\when('get_preview_post_link')->justReturn('https://kunde.de/?p=5&preview=true'); Functions\when('get_edit_post_link')->justReturn('https://kunde.de/wp-admin/post.php?post=5&action=edit'); $schema = Mockery::mock(ContentSchema::class); $schema->allows('isManaged')->andReturn(true); return new PostUnpublishAbility($schema, $log); } public function testPublishedPostBecomesDraft(): void { Functions\expect('wp_update_post')->once()->with(['ID' => 5, 'post_status' => 'draft'], true)->andReturn(5); $log = Mockery::mock(ChangeLog::class); $log->expects('record')->andReturn(3); $result = $this->ability($log, 'publish')->execute(['post_id' => 5]); self::assertSame('unpublished', $result['changed'][0]['action']); } public function testDraftIsANoOp(): void { Functions\expect('wp_update_post')->never(); $result = $this->ability(Mockery::mock(ChangeLog::class), 'draft')->execute(['post_id' => 5]); self::assertSame([], $result['changed']); } }