2017-02-12 12:00:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* HelpControllerTest.php
|
2019-10-02 06:45:03 +02:00
|
|
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
2017-02-12 12:00:11 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +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.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:45:03 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +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/>.
|
2017-02-12 12:00:11 +01:00
|
|
|
*/
|
2017-07-08 06:28:44 +02:00
|
|
|
declare(strict_types=1);
|
2017-02-12 12:00:11 +01:00
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers;
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
use FireflyIII\Helpers\Help\HelpInterface;
|
2017-03-19 17:54:21 +01:00
|
|
|
use FireflyIII\Models\Preference;
|
2018-03-24 06:08:50 +01:00
|
|
|
use Log;
|
2017-02-12 12:00:11 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2017-03-05 13:21:36 +01:00
|
|
|
/**
|
|
|
|
* Class HelpControllerTest
|
|
|
|
*
|
2017-08-12 10:27:45 +02:00
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
2017-03-05 13:21:36 +01:00
|
|
|
*/
|
2017-02-12 12:00:11 +01:00
|
|
|
class HelpControllerTest extends TestCase
|
|
|
|
{
|
2018-03-24 06:08:50 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-09-02 20:27:26 +02:00
|
|
|
public function setUp(): void
|
2018-03-24 06:08:50 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-03-24 06:08:50 +01:00
|
|
|
}
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\HelpController
|
2017-02-12 12:21:44 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShow(): void
|
2017-02-12 12:21:44 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-02-12 12:21:44 +01:00
|
|
|
$help = $this->mock(HelpInterface::class);
|
|
|
|
$help->shouldReceive('hasRoute')->andReturn(true)->once();
|
|
|
|
$help->shouldReceive('inCache')->andReturn(false)->once();
|
2017-03-19 17:54:21 +01:00
|
|
|
$help->shouldReceive('getFromGithub')->andReturn('Recent new content here.')->once();
|
2017-02-12 12:21:44 +01:00
|
|
|
$help->shouldReceive('putInCache')->once();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('help.show', ['index']));
|
|
|
|
$response->assertStatus(200);
|
2017-03-19 17:54:21 +01:00
|
|
|
$response->assertSee('Recent new content here.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\HelpController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowBackupFromCache(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
$help = $this->mock(HelpInterface::class);
|
|
|
|
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
|
2019-07-21 17:15:06 +02:00
|
|
|
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
|
|
|
|
$help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
// is US in cache?
|
2017-07-23 08:32:51 +02:00
|
|
|
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once();
|
2017-03-19 17:54:21 +01:00
|
|
|
$help->shouldReceive('getFromCache')->withArgs(['index', 'en_US'])->andReturn('US from cache.')->once();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('help.show', ['index']));
|
|
|
|
$response->assertStatus(200);
|
2019-07-21 17:15:06 +02:00
|
|
|
$response->assertSee('US from cache.');
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
// put English back:
|
|
|
|
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
|
2017-11-22 21:12:27 +01:00
|
|
|
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US']);
|
2017-03-19 17:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\HelpController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowBackupFromGithub(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
$help = $this->mock(HelpInterface::class);
|
|
|
|
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
|
2019-07-21 17:15:06 +02:00
|
|
|
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
|
|
|
|
$help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
// is US in cache?
|
2017-07-23 08:32:51 +02:00
|
|
|
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
|
2017-03-19 17:54:21 +01:00
|
|
|
$help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
|
|
|
|
|
2018-08-17 06:45:57 +02:00
|
|
|
$help->shouldReceive('putInCache')->once();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('help.show', ['index']));
|
|
|
|
$response->assertStatus(200);
|
2019-07-21 17:15:06 +02:00
|
|
|
$response->assertSee('This help text is not yet available in your language');
|
2017-03-19 17:54:21 +01:00
|
|
|
|
|
|
|
// put English back:
|
|
|
|
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
|
2017-11-22 21:12:27 +01:00
|
|
|
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US']);
|
2017-03-19 17:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\HelpController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowCached(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$help = $this->mock(HelpInterface::class);
|
|
|
|
$help->shouldReceive('hasRoute')->andReturn(true)->once();
|
|
|
|
$help->shouldReceive('inCache')->andReturn(true)->once();
|
|
|
|
$help->shouldReceive('getFromCache')->andReturn('Cached help content here.')->once();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('help.show', ['index']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('Cached help content here.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 20:17:15 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\HelpController
|
2017-03-19 17:54:21 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testShowNoRoute(): void
|
2017-03-19 17:54:21 +01:00
|
|
|
{
|
2019-07-21 17:15:06 +02:00
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
2017-03-19 17:54:21 +01:00
|
|
|
$help = $this->mock(HelpInterface::class);
|
|
|
|
$help->shouldReceive('hasRoute')->andReturn(false)->once();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('help.show', ['index']));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('There is no help for this route.');
|
2017-02-12 12:21:44 +01:00
|
|
|
}
|
2017-02-16 22:33:32 +01:00
|
|
|
}
|