CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m49s
CI / Coding Standards (pull_request) Successful in 2m55s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m40s
CI / Build Plugin Zip (pull_request) Skipped
Group classes can now be marked invite-only (us_offerings.access_mode). Invite-only classes are hidden from the public catalog and reachable only when the instructor lets someone in via one of three paths, managed from My Lessons -> My Group Classes: - Add students directly: enrols them now with a pending payment. - Make available: grants registered students access to self-enrol through the normal paid flow (multi-select, emailed a notice). - Invite by email: tokenised registration invite tied to the class for a non-account address; after they register the class becomes enrollable. Reuses an existing pending invite instead of sending a second link. New us_group_access table records grants; GET /offerings merges granted invite-only classes for the caller; enrolment requires a grant (403 invite_required) and flips it to enrolled on success. composer test (487), composer lint, composer cs all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
123 lines
4.0 KiB
PHP
123 lines
4.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Mockery;
|
|
use Unsupervised\Schedular\Auth\RegistrationMailer;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class RegistrationMailerTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Functions\when('get_bloginfo')->justReturn('Test Studio');
|
|
Functions\when('wp_login_url')->justReturn('http://example.test/login');
|
|
}
|
|
|
|
private function user(string $email): \WP_User
|
|
{
|
|
$user = Mockery::mock(\WP_User::class);
|
|
$user->user_email = $email;
|
|
$user->display_name = 'Ada';
|
|
|
|
return $user;
|
|
}
|
|
|
|
public function testSendConfirmationEmailsTheStudent(): void
|
|
{
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with(
|
|
'[email protected]',
|
|
Mockery::type('string'),
|
|
Mockery::on(static fn (string $body): bool => str_contains($body, 'http://confirm.test'))
|
|
)
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->sendConfirmation($this->user('[email protected]'), 'http://confirm.test'));
|
|
}
|
|
|
|
public function testSendConfirmationReturnsFalseWithoutRecipient(): void
|
|
{
|
|
self::assertFalse((new RegistrationMailer())->sendConfirmation($this->user(''), 'http://confirm.test'));
|
|
}
|
|
|
|
public function testNotifyAdminsPendingUsesAdminEmail(): void
|
|
{
|
|
Functions\when('get_option')->alias(static fn (string $name) => $name === 'admin_email' ? '[email protected]' : '');
|
|
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with('[email protected]', Mockery::type('string'), Mockery::type('string'))
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->notifyAdminsPending($this->user('[email protected]')));
|
|
}
|
|
|
|
public function testSendApprovedEmailsTheStudent(): void
|
|
{
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with('[email protected]', Mockery::type('string'), Mockery::type('string'))
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->sendApproved($this->user('[email protected]')));
|
|
}
|
|
|
|
public function testSendRejectedEmailsTheAddress(): void
|
|
{
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with('[email protected]', Mockery::type('string'), Mockery::type('string'))
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->sendRejected('[email protected]'));
|
|
}
|
|
|
|
public function testSendRejectedReturnsFalseWithoutRecipient(): void
|
|
{
|
|
self::assertFalse((new RegistrationMailer())->sendRejected(''));
|
|
}
|
|
|
|
public function testSendClassAccessGrantedEmailsTheStudent(): void
|
|
{
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with(
|
|
'[email protected]',
|
|
Mockery::on(static fn (string $subject): bool => str_contains($subject, 'Choir')),
|
|
Mockery::on(static fn (string $body): bool => str_contains($body, 'Choir'))
|
|
)
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->sendClassAccessGranted($this->user('[email protected]'), 'Choir'));
|
|
}
|
|
|
|
public function testSendClassAccessGrantedReturnsFalseWithoutRecipient(): void
|
|
{
|
|
self::assertFalse((new RegistrationMailer())->sendClassAccessGranted($this->user(''), 'Choir'));
|
|
}
|
|
|
|
public function testSendClassInviteIncludesTheLink(): void
|
|
{
|
|
Functions\expect('wp_mail')
|
|
->once()
|
|
->with(
|
|
'[email protected]',
|
|
Mockery::type('string'),
|
|
Mockery::on(static fn (string $body): bool => str_contains($body, 'http://join.test'))
|
|
)
|
|
->andReturn(true);
|
|
|
|
self::assertTrue((new RegistrationMailer())->sendClassInvite('[email protected]', 'http://join.test', 'Choir'));
|
|
}
|
|
|
|
public function testSendClassInviteReturnsFalseWithoutRecipient(): void
|
|
{
|
|
self::assertFalse((new RegistrationMailer())->sendClassInvite('', 'http://join.test', 'Choir'));
|
|
}
|
|
}
|