Improve test coverage.

This commit is contained in:
James Cole
2019-08-29 17:53:25 +02:00
parent 91b6b86202
commit 19feefda2d
86 changed files with 3173 additions and 2626 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@ namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Http\Middleware\StartFireflySession;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Route;
use Symfony\Component\HttpFoundation\Response;
@@ -57,6 +58,10 @@ class IsDemoUserTest extends TestCase
*/
public function testMiddlewareAuthenticated(): void
{
$userRepos =$this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnFalse();
$this->be($this->user());
$response = $this->get('/_test/is-demo');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
@@ -67,6 +72,10 @@ class IsDemoUserTest extends TestCase
*/
public function testMiddlewareIsDemoUser(): void
{
$userRepos =$this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->atLeast()->once()->andReturnTrue();
$this->be($this->demoUser());
$response = $this->get('/_test/is-demo');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());

View File

@@ -24,12 +24,16 @@ declare(strict_types=1);
namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\Range;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
use Preferences;
use Mockery;
use Amount;
/**
* Class RangeTest
@@ -61,6 +65,27 @@ class RangeTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('firstNull')->andReturn(TransactionJournal::first());
$this->withoutExceptionHandling();
$viewPreference = new Preference;
$viewPreference->data = '1M';
$langPreference = new Preference;
$langPreference->data = 'en_US';
$currPreference = new Preference;
$currPreference->data = 'EUR';
$listPreference = new Preference;
$listPreference->data = 10;
Preferences::shouldReceive('get')->withArgs(['viewRange','1M'])->atLeast()->once()->andReturn($viewPreference);
Preferences::shouldReceive('get')->withArgs(['language','en_US'])->atLeast()->once()->andReturn($langPreference);
Preferences::shouldReceive('get')->withArgs(['list-length',10])->atLeast()->once()->andReturn($listPreference);
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($this->getEuro());
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$this->be($this->user());
$response = $this->get('/_test/range');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());