2018-03-30 22:40:20 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AdminEventHandlerTest.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
class AdminEventHandlerTest extends TestCase
|
|
|
|
{
|
2018-08-24 16:07:33 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-08-24 16:07:33 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
return $mail->hasTo('thegrumpydictator@gmail.com') && '127.0.0.1' === $mail->ipAddress;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-08-24 16:07:33 +02:00
|
|
|
}
|
2018-03-30 22:40:20 +02:00
|
|
|
}
|