2017-09-22 05:30:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Commands\Environment;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Tests\Unit\Commands\CommandTestCase;
|
|
|
|
use Illuminate\Contracts\Config\Repository;
|
|
|
|
use Pterodactyl\Console\Commands\Environment\EmailSettingsCommand;
|
|
|
|
|
|
|
|
class EmailSettingsCommandTest extends CommandTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Console\Commands\Environment\EmailSettingsCommand|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
protected $command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2017-09-22 05:30:09 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = m::mock(Repository::class);
|
|
|
|
$this->command = m::mock(EmailSettingsCommand::class . '[call, writeToEnvironment]', [$this->config]);
|
|
|
|
$this->command->setLaravel($this->app);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selection of the SMTP driver with no options passed.
|
|
|
|
*/
|
|
|
|
public function testSmtpDriverSelection()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'smtp',
|
|
|
|
'MAIL_HOST' => 'mail.test.com',
|
|
|
|
'MAIL_PORT' => '567',
|
|
|
|
'MAIL_USERNAME' => 'username',
|
|
|
|
'MAIL_PASSWORD' => 'password',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->runCommand($this->command, [], array_values($data));
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the command can run when all variables are passed in as options.
|
|
|
|
*/
|
|
|
|
public function testSmtpDriverSelectionWithOptionsPassed()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'smtp',
|
|
|
|
'MAIL_HOST' => 'mail.test.com',
|
|
|
|
'MAIL_PORT' => '567',
|
|
|
|
'MAIL_USERNAME' => 'username',
|
|
|
|
'MAIL_PASSWORD' => 'password',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->withoutInteraction()->runCommand($this->command, [
|
|
|
|
'--driver' => $data['MAIL_DRIVER'],
|
|
|
|
'--email' => $data['MAIL_FROM'],
|
|
|
|
'--from' => $data['MAIL_FROM_NAME'],
|
|
|
|
'--encryption' => $data['MAIL_ENCRYPTION'],
|
|
|
|
'--host' => $data['MAIL_HOST'],
|
|
|
|
'--port' => $data['MAIL_PORT'],
|
|
|
|
'--username' => $data['MAIL_USERNAME'],
|
|
|
|
'--password' => $data['MAIL_PASSWORD'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selection of PHP mail() as the driver.
|
|
|
|
*/
|
|
|
|
public function testPHPMailDriverSelection()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'mail',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
|
|
|
|
// The driver flag is passed because there seems to be some issue with the command tester
|
|
|
|
// when using a choice() method when two keys start with the same letters.
|
|
|
|
//
|
|
|
|
// In this case, mail and mailgun.
|
|
|
|
unset($data['MAIL_DRIVER']);
|
|
|
|
$display = $this->runCommand($this->command, ['--driver' => 'mail'], array_values($data));
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selection of the Mailgun driver with no options passed.
|
|
|
|
*/
|
|
|
|
public function testMailgunDriverSelection()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'mailgun',
|
|
|
|
'MAILGUN_DOMAIN' => 'domain.com',
|
2018-02-17 19:00:11 +00:00
|
|
|
'MAILGUN_SECRET' => '123456',
|
2017-09-22 05:30:09 +00:00
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->runCommand($this->command, [], array_values($data));
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test mailgun driver selection when variables are passed as options.
|
|
|
|
*/
|
|
|
|
public function testMailgunDriverSelectionWithOptionsPassed()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'mailgun',
|
|
|
|
'MAILGUN_DOMAIN' => 'domain.com',
|
2018-02-17 19:00:11 +00:00
|
|
|
'MAILGUN_SECRET' => '123456',
|
2017-09-22 05:30:09 +00:00
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->withoutInteraction()->runCommand($this->command, [
|
|
|
|
'--driver' => $data['MAIL_DRIVER'],
|
|
|
|
'--email' => $data['MAIL_FROM'],
|
|
|
|
'--from' => $data['MAIL_FROM_NAME'],
|
|
|
|
'--encryption' => $data['MAIL_ENCRYPTION'],
|
|
|
|
'--host' => $data['MAILGUN_DOMAIN'],
|
2018-02-17 19:00:11 +00:00
|
|
|
'--password' => $data['MAILGUN_SECRET'],
|
2017-09-22 05:30:09 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selection of the Mandrill driver with no options passed.
|
|
|
|
*/
|
|
|
|
public function testMandrillDriverSelection()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'mandrill',
|
|
|
|
'MANDRILL_SECRET' => '123456',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->runCommand($this->command, [], array_values($data));
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test mandrill driver selection when variables are passed as options.
|
|
|
|
*/
|
|
|
|
public function testMandrillDriverSelectionWithOptionsPassed()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'mandrill',
|
|
|
|
'MANDRILL_SECRET' => '123456',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->withoutInteraction()->runCommand($this->command, [
|
|
|
|
'--driver' => $data['MAIL_DRIVER'],
|
|
|
|
'--email' => $data['MAIL_FROM'],
|
|
|
|
'--from' => $data['MAIL_FROM_NAME'],
|
|
|
|
'--encryption' => $data['MAIL_ENCRYPTION'],
|
|
|
|
'--password' => $data['MANDRILL_SECRET'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test selection of the Postmark driver with no options passed.
|
|
|
|
*/
|
|
|
|
public function testPostmarkDriverSelection()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'smtp',
|
|
|
|
'MAIL_HOST' => 'smtp.postmarkapp.com',
|
|
|
|
'MAIL_PORT' => '587',
|
|
|
|
'MAIL_USERNAME' => '123456',
|
|
|
|
'MAIL_PASSWORD' => '123456',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->runCommand($this->command, [], [
|
|
|
|
'postmark', '123456', $data['MAIL_FROM'], $data['MAIL_FROM_NAME'], $data['MAIL_ENCRYPTION'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test postmark driver selection when variables are passed as options.
|
|
|
|
*/
|
|
|
|
public function testPostmarkDriverSelectionWithOptionsPassed()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'MAIL_DRIVER' => 'smtp',
|
|
|
|
'MAIL_HOST' => 'smtp.postmarkapp.com',
|
|
|
|
'MAIL_PORT' => '587',
|
|
|
|
'MAIL_USERNAME' => '123456',
|
|
|
|
'MAIL_PASSWORD' => '123456',
|
|
|
|
'MAIL_FROM' => 'mail@from.com',
|
|
|
|
'MAIL_FROM_NAME' => 'MailName',
|
|
|
|
'MAIL_ENCRYPTION' => 'tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->setupCoreFunctions($data);
|
|
|
|
$display = $this->withoutInteraction()->runCommand($this->command, [
|
|
|
|
'--driver' => 'postmark',
|
|
|
|
'--email' => $data['MAIL_FROM'],
|
|
|
|
'--from' => $data['MAIL_FROM_NAME'],
|
|
|
|
'--encryption' => $data['MAIL_ENCRYPTION'],
|
|
|
|
'--username' => $data['MAIL_USERNAME'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotEmpty($display);
|
2020-06-24 04:33:56 +00:00
|
|
|
$this->assertStringContainsString('Updating stored environment configuration file.', $display);
|
2017-09-22 05:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the core functions that are repeated across all of these tests.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
private function setupCoreFunctions(array $data)
|
|
|
|
{
|
|
|
|
$this->config->shouldReceive('get')->withAnyArgs()->zeroOrMoreTimes()->andReturnNull();
|
|
|
|
$this->command->shouldReceive('writeToEnvironment')->with($data)->once()->andReturnNull();
|
|
|
|
}
|
|
|
|
}
|