returnArg(); Functions\when('sanitize_title')->returnArg(); Functions\when('wp_kses_post')->returnArg(); $this->stubAutop(); $this->policies = Mockery::mock(PolicyRepository::class); $this->versions = Mockery::mock(PolicyVersionRepository::class); $this->service = Mockery::mock(PolicyService::class); $this->endpoint = new PolicyEndpoint( $this->policies, $this->versions, $this->service, ); } public function testIndexReturnsPlainTextBodiesAsParagraphs(): void { $policy = new Policy('Cancellation', 'cancellation', currentVersionId: 7, id: 4); $version = new PolicyVersion( policyId: 4, versionNumber: 2, body: "Give 24 hours notice.\n\nLate cancellations are billed in full.", status: PolicyVersion::STATUS_PUBLISHED, id: 7, ); $this->policies->shouldReceive('findAll')->andReturn([$policy]); $this->versions->shouldReceive('findById')->with(7)->andReturn($version); $body = $this->endpoint->index(new \WP_REST_Request([]))->get_data(); // The admin typed no markup, so the gate still receives real paragraphs // rather than one unbroken run of text. self::assertSame( '

Give 24 hours notice.

Late cancellations are billed in full.

', $body[0]['body'] ); } public function testCreateRejectsTitleLongerThanColumnLimit(): void { $this->service->shouldNotReceive('createPolicy'); $request = new \WP_REST_Request([ 'title' => str_repeat('a', Policy::MAX_TITLE_LENGTH + 1), ]); $response = $this->endpoint->create($request); self::assertInstanceOf(\WP_Error::class, $response); self::assertSame(400, $response->error_data['invalid_policy']['status']); } public function testCreateRejectsSlugLongerThanColumnLimit(): void { $this->service->shouldNotReceive('createPolicy'); $request = new \WP_REST_Request([ 'title' => 'Cancellation', 'slug' => str_repeat('a', Policy::MAX_SLUG_LENGTH + 1), ]); $response = $this->endpoint->create($request); self::assertInstanceOf(\WP_Error::class, $response); self::assertSame(400, $response->error_data['invalid_policy']['status']); } }