View a policy version's content, and make policy text readable
CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m12s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m50s
CI / PHPStan (pull_request) Successful in 3m4s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m12s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m50s
CI / PHPStan (pull_request) Successful in 3m4s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
The Policies admin page listed versions but never showed what any of them said, so revising a policy meant retyping it blind into an empty draft box. Each version row now has a View action that renders that version's text on the page, editable in place. A draft is saved back to itself; editing a published or archived version branches a new draft and leaves the original alone, because acceptances are recorded against policy_version_id and text a student agreed to must stay exactly as they saw it. That viewer also exposed why a studio reported the acceptance box as unreadable — one squashed line, overlapping words, a horizontal scrollbar. Bodies are typed into a bare textarea, so most carry no markup, and the raw text was emitted with its blank lines intact but nothing to turn them into paragraphs. PolicyVersion::bodyHtml() now renders every body the way WordPress renders post content (kses, then wpautop) and feeds all three consumers: the booking/enrolment JSON, the signup form, and the new viewer. Bodies written with markup are unaffected. The other half was that .us-policy-body had no CSS whatsoever and inherited whatever the theme did with an unstyled block in a form. It is now a bounded reading box that scrolls vertically and breaks long tokens, so a pasted URL cannot force the page sideways and a long policy cannot push the accept checkbox out of view. RegistrationPage was also never enqueueing the plugin stylesheet, which is why the signup gate looked worst of all. Closes #126 Closes #127 Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -9,12 +9,14 @@ use Unsupervised\Schedular\Policy\Policy;
|
||||
use Unsupervised\Schedular\Policy\PolicyEndpoint;
|
||||
use Unsupervised\Schedular\Policy\PolicyRepository;
|
||||
use Unsupervised\Schedular\Policy\PolicyService;
|
||||
use Unsupervised\Schedular\Policy\PolicyVersion;
|
||||
use Unsupervised\Schedular\Policy\PolicyVersionRepository;
|
||||
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class PolicyEndpointTest extends TestCase
|
||||
{
|
||||
private PolicyRepository&Mockery\MockInterface $policies;
|
||||
private PolicyVersionRepository&Mockery\MockInterface $versions;
|
||||
private PolicyService&Mockery\MockInterface $service;
|
||||
private PolicyEndpoint $endpoint;
|
||||
|
||||
@@ -24,16 +26,43 @@ class PolicyEndpointTest extends TestCase
|
||||
|
||||
Functions\when('sanitize_text_field')->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,
|
||||
Mockery::mock(PolicyVersionRepository::class),
|
||||
$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(
|
||||
'<p>Give 24 hours notice.</p><p>Late cancellations are billed in full.</p>',
|
||||
$body[0]['body']
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateRejectsTitleLongerThanColumnLimit(): void
|
||||
{
|
||||
$this->service->shouldNotReceive('createPolicy');
|
||||
|
||||
Reference in New Issue
Block a user