Files
firefly-iii/tests/Feature/Controllers/Import/CallbackControllerTest.php

112 lines
3.6 KiB
PHP
Raw Normal View History

2018-08-30 20:58:07 +02:00
<?php
/**
* CallbackControllerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-08-30 20:58:07 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-08-30 20:58:07 +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.
2018-08-30 20:58:07 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-08-30 20:58:07 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-08-30 20:58:07 +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/>.
2018-08-30 20:58:07 +02:00
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Import;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Log;
use Mockery;
2018-09-02 20:27:26 +02:00
use Tests\TestCase;
2018-08-30 20:58:07 +02:00
/**
*
* Class CallbackControllerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-08-30 20:58:07 +02:00
*/
class CallbackControllerTest extends TestCase
{
/**
*
*/
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-30 20:58:07 +02:00
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
2018-09-02 20:27:26 +02:00
public function testYnabBasic(): void
{
2018-08-30 20:58:07 +02:00
$repository = $this->mock(ImportJobRepositoryInterface::class);
2020-01-05 19:29:28 +01:00
$importJob = $this->getRandomImportJob();
2018-08-30 20:58:07 +02:00
// config for job:
2018-09-02 20:27:26 +02:00
$config = [];
2018-08-30 20:58:07 +02:00
$newConfig = ['auth_code' => 'abc'];
2019-06-29 08:14:28 +02:00
$this->mockDefaultSession();
2018-08-30 20:58:07 +02:00
// mock calls.
2020-01-05 19:29:28 +01:00
$repository->shouldReceive('findByKey')->andReturn($importJob)->once();
2018-08-30 20:58:07 +02:00
$repository->shouldReceive('getConfiguration')->andReturn($config)->once();
$repository->shouldReceive('setConfiguration')->once()->withArgs([Mockery::any(), $newConfig]);
$repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'ready_to_run']);
$repository->shouldReceive('setStage')->once()->withArgs([Mockery::any(), 'get_access_token']);
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
2018-09-02 20:27:26 +02:00
public function testYnabBasicBadJob(): void
{
2018-08-30 20:58:07 +02:00
$repository = $this->mock(ImportJobRepositoryInterface::class);
// mock calls.
$repository->shouldReceive('findByKey')->andReturnNull()->once();
2019-06-29 08:14:28 +02:00
$this->mockDefaultSession();
2018-08-30 20:58:07 +02:00
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
$response->assertStatus(200);
$response->assertSee('You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.');
}
/**
* @covers \FireflyIII\Http\Controllers\Import\CallbackController
*/
2018-09-02 20:27:26 +02:00
public function testYnabBasicNoCode(): void
{
2019-06-29 08:14:28 +02:00
$this->mock(ImportJobRepositoryInterface::class);
2018-08-30 20:58:07 +02:00
2019-06-29 08:14:28 +02:00
$this->mockDefaultSession();
2018-08-30 20:58:07 +02:00
// mock calls.
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=&state=def');
$response->assertStatus(200);
$response->assertSee('You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.');
}
2018-12-31 07:48:23 +01:00
}