Files
firefly-iii/tests/Feature/Controllers/HelpControllerTest.php

151 lines
6.0 KiB
PHP
Raw Normal View History

2017-02-12 12:00:11 +01:00
<?php
/**
* HelpControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* 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
2017-12-17 14:42:21 +01:00
* along with Firefly III. If not, see <http://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;
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
{
2017-02-12 12:21:44 +01:00
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-09-03 10:09:27 +02:00
* @covers \FireflyIII\Http\Controllers\HelpController::getHelpText
2017-03-19 17:54:21 +01:00
* @covers \FireflyIII\Http\Controllers\HelpController::__construct
2017-02-12 12:21:44 +01:00
*/
public function testShow()
{
$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.');
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-09-03 10:09:27 +02:00
* @covers \FireflyIII\Http\Controllers\HelpController::getHelpText
2017-12-17 14:30:53 +01:00
* @throws \Exception
* @throws \Exception
2017-03-19 17:54:21 +01:00
*/
public function testShowBackupFromCache()
{
// force pref in dutch for test
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' => 'nl_NL']);
2017-03-19 17:54:21 +01:00
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
$help->shouldReceive('inCache')->withArgs(['index', 'nl_NL'])->andReturn(false)->once();
$help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
// 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);
$response->assertSee('US from cache.'); // Dutch translation
// 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
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-09-03 10:09:27 +02:00
* @covers \FireflyIII\Http\Controllers\HelpController::getHelpText
2017-12-17 14:30:53 +01:00
* @throws \Exception
* @throws \Exception
2017-03-19 17:54:21 +01:00
*/
public function testShowBackupFromGithub()
{
// force pref in dutch for test
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' => 'nl_NL']);
2017-03-19 17:54:21 +01:00
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->withArgs(['index'])->andReturn(true)->once();
$help->shouldReceive('inCache')->withArgs(['index', 'nl_NL'])->andReturn(false)->once();
$help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
// 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();
$this->be($this->user());
$response = $this->get(route('help.show', ['index']));
$response->assertStatus(200);
$response->assertSee('Er is geen hulptekst voor deze pagina.'); // Dutch
// 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
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-09-03 10:09:27 +02:00
* @covers \FireflyIII\Http\Controllers\HelpController::getHelpText
2017-03-19 17:54:21 +01:00
*/
public function testShowCached()
{
$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.');
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-09-03 10:09:27 +02:00
* @covers \FireflyIII\Http\Controllers\HelpController::getHelpText
2017-03-19 17:54:21 +01:00
*/
public function testShowNoRoute()
{
$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
}