Files
firefly-iii/tests/Unit/Handlers/Events/AdminEventHandlerTest.php

96 lines
2.9 KiB
PHP
Raw Normal View History

2018-03-30 22:40:20 +02:00
<?php
/**
* AdminEventHandlerTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-03-30 22:40:20 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-03-30 22:40:20 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-03-30 22:40:20 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-03-30 22:40:20 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-03-30 22:40:20 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-03-30 22:40:20 +02:00
*/
declare(strict_types=1);
namespace Tests\Unit\Handlers\Events;
use FireflyIII\Events\AdminRequestedTestMessage;
use FireflyIII\Handlers\Events\AdminEventHandler;
use FireflyIII\Mail\AdminTestMail;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Facades\Mail;
2018-09-02 20:27:26 +02:00
use Log;
2018-03-30 22:40:20 +02:00
use Mockery;
use Tests\TestCase;
2018-09-02 20:27:26 +02:00
2018-03-30 22:40:20 +02:00
/**
* Class AdminEventHandlerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-03-30 22:40:20 +02:00
*/
class AdminEventHandlerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
2018-03-30 22:40:20 +02:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Handlers\Events\AdminEventHandler
2018-03-30 22:40:20 +02:00
* @covers \FireflyIII\Events\AdminRequestedTestMessage
*/
2018-05-11 19:58:10 +02:00
public function testSendNoMessage(): void
2018-03-30 22:40:20 +02:00
{
$repository = $this->mock(UserRepositoryInterface::class);
$event = new AdminRequestedTestMessage($this->user(), '127.0.0.1');
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false)->once();
$listener = new AdminEventHandler();
$this->assertTrue($listener->sendTestMessage($event));
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Handlers\Events\AdminEventHandler
2018-03-30 22:40:20 +02:00
* @covers \FireflyIII\Events\AdminRequestedTestMessage
*/
2018-05-11 19:58:10 +02:00
public function testSendTestMessage(): void
2018-03-30 22:40:20 +02:00
{
Mail::fake();
$repository = $this->mock(UserRepositoryInterface::class);
$event = new AdminRequestedTestMessage($this->user(), '127.0.0.1');
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->once();
$listener = new AdminEventHandler();
$this->assertTrue($listener->sendTestMessage($event));
// assert a message was sent.
Mail::assertSent(
AdminTestMail::class, function ($mail) {
2020-02-16 13:59:55 +01:00
return $mail->hasTo('james@firefly-iii.org') && '127.0.0.1' === $mail->ipAddress;
2018-03-30 22:40:20 +02:00
}
);
}
2018-03-30 22:40:20 +02:00
}