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

131 lines
5.0 KiB
PHP
Raw Normal View History

2017-02-12 05:00:11 -06:00
<?php
/**
* HelpControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2017-07-07 23:28:44 -05:00
declare(strict_types=1);
2017-02-12 05:00:11 -06:00
namespace Tests\Feature\Controllers;
2017-02-12 05:21:44 -06:00
use FireflyIII\Helpers\Help\HelpInterface;
2017-03-19 11:54:21 -05:00
use FireflyIII\Models\Preference;
2017-02-12 05:00:11 -06:00
use Tests\TestCase;
2017-03-05 06:21:36 -06:00
/**
* Class HelpControllerTest
*
* @package Tests\Feature\Controllers
*/
2017-02-12 05:00:11 -06:00
class HelpControllerTest extends TestCase
{
2017-02-12 05:21:44 -06:00
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
2017-03-19 11:54:21 -05:00
* @covers \FireflyIII\Http\Controllers\HelpController::__construct
2017-02-12 05:21:44 -06:00
*/
public function testShow()
{
$help = $this->mock(HelpInterface::class);
$help->shouldReceive('hasRoute')->andReturn(true)->once();
$help->shouldReceive('inCache')->andReturn(false)->once();
2017-03-19 11:54:21 -05:00
$help->shouldReceive('getFromGithub')->andReturn('Recent new content here.')->once();
2017-02-12 05:21:44 -06:00
$help->shouldReceive('putInCache')->once();
$this->be($this->user());
$response = $this->get(route('help.show', ['index']));
$response->assertStatus(200);
2017-03-19 11:54:21 -05:00
$response->assertSee('Recent new content here.');
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
*/
public function testShowBackupFromCache()
{
// force pref in dutch for test
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'nl_NL',]);
$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 01:32:51 -05:00
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once();
2017-03-19 11:54:21 -05: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();
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US',]);
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
*/
public function testShowBackupFromGithub()
{
// force pref in dutch for test
Preference::where('user_id', $this->user()->id)->where('name', 'language')->delete();
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'nl_NL',]);
$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 01:32:51 -05:00
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
2017-03-19 11:54:21 -05: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();
Preference::create(['user_id' => $this->user()->id, 'name' => 'language', 'data' => 'en_US',]);
}
/**
* @covers \FireflyIII\Http\Controllers\HelpController::show
*/
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
*/
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 05:21:44 -06:00
}
2017-02-16 15:33:32 -06:00
}