mirror of
https://github.com/flarum/framework.git
synced 2025-02-13 21:22:45 +08:00
84ded0ce50
- update actions ci - include json for 4 spaces tab - provide output int for process code exit - adhere to parent type hint of builder - mailer instance now needs a name, multiple can be instantiated - getOriginal now uses mutators in the model - Temporarily loosen MailableInterface requirements. This avoids an immediate BC break for classes in extensions that implement this interface. - Temporarily provide (and autoload) old symfony translator interface - make queue exception handler compatible with the contract of L8 - Update phpunit schema for newer version - Update phpunit assert calls for newer version
118 lines
3.0 KiB
PHP
118 lines
3.0 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* For detailed copyright and license information, please view the
|
|
* LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Tests\integration\extenders;
|
|
|
|
use Flarum\Extend;
|
|
use Flarum\Mail\DriverInterface;
|
|
use Flarum\Settings\SettingsRepositoryInterface;
|
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
|
use Flarum\Tests\integration\TestCase;
|
|
use Illuminate\Contracts\Validation\Factory;
|
|
use Illuminate\Support\MessageBag;
|
|
use Swift_NullTransport;
|
|
use Swift_Transport;
|
|
|
|
class MailTest extends TestCase
|
|
{
|
|
use RetrievesAuthorizedUsers;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function drivers_are_unchanged_by_default()
|
|
{
|
|
$response = $this->send(
|
|
$this->request('GET', '/api/mail/settings', [
|
|
'authenticatedAs' => 1,
|
|
])
|
|
);
|
|
|
|
$fields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields'];
|
|
|
|
// The custom driver does not exist
|
|
$this->assertArrayNotHasKey('custom', $fields);
|
|
|
|
// The SMTP driver has its normal fields
|
|
$this->assertEquals([
|
|
'mail_host' => '',
|
|
'mail_port' => '',
|
|
'mail_encryption' => '',
|
|
'mail_username' => '',
|
|
'mail_password' => '',
|
|
], $fields['smtp']);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function added_driver_appears_in_mail_settings()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Mail)
|
|
->driver('custom', CustomDriver::class)
|
|
);
|
|
|
|
$response = $this->send(
|
|
$this->request('GET', '/api/mail/settings', [
|
|
'authenticatedAs' => 1,
|
|
])
|
|
);
|
|
|
|
$fields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields'];
|
|
|
|
$this->assertArrayHasKey('custom', $fields);
|
|
$this->assertEquals(['customSetting1' => ''], $fields['custom']);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function adding_driver_with_duplicate_name_overrides_fields()
|
|
{
|
|
$this->extend(
|
|
(new Extend\Mail)
|
|
->driver('smtp', CustomDriver::class)
|
|
);
|
|
|
|
$response = $this->send(
|
|
$this->request('GET', '/api/mail/settings', [
|
|
'authenticatedAs' => 1,
|
|
])
|
|
);
|
|
|
|
$requiredFields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields']['smtp'];
|
|
|
|
$this->assertEquals(['customSetting1' => ''], $requiredFields);
|
|
}
|
|
}
|
|
|
|
class CustomDriver implements DriverInterface
|
|
{
|
|
public function availableSettings(): array
|
|
{
|
|
return ['customSetting1' => ''];
|
|
}
|
|
|
|
public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag
|
|
{
|
|
return new MessageBag;
|
|
}
|
|
|
|
public function canSend(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport
|
|
{
|
|
return new Swift_NullTransport;
|
|
}
|
|
}
|