Files
firefly-iii/tests/Unit/Import/Prerequisites/YnabPrerequisitesTest.php

167 lines
5.4 KiB
PHP
Raw Normal View History

2018-09-30 11:57:51 +02:00
<?php
/**
* YnabPrerequisitesTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-09-30 11:57:51 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-09-30 11:57:51 +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-09-30 11:57:51 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-09-30 11:57:51 +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-09-30 11:57:51 +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-09-30 11:57:51 +02:00
*/
declare(strict_types=1);
namespace tests\Unit\Import\Prerequisites;
use FireflyIII\Import\Prerequisites\YnabPrerequisites;
use FireflyIII\Models\Preference;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
* Class YnabPrerequisitesTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-09-30 11:57:51 +02:00
*/
class YnabPrerequisitesTest 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-09-30 11:57:51 +02:00
}
/**
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetView(): void
{
$object = new YnabPrerequisites;
$object->setUser($this->user());
$this->assertEquals('import.ynab.prerequisites', $object->getView());
}
/**
* First test, user has empty.
2018-09-30 11:57:51 +02:00
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetViewParametersEmpty(): void
2018-09-30 11:57:51 +02:00
{
$clientId = new Preference;
$clientId->data = '';
2018-09-30 11:57:51 +02:00
$clientSecret = new Preference;
$clientSecret->data = '';
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn($clientId);
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn($clientSecret);
2018-09-30 11:57:51 +02:00
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => '', 'client_secret' => '', 'callback_uri' => 'http://localhost/import/ynab-callback', 'is_https' => false];
$this->assertEquals($expected, $result);
}
/**
* First test, user has nothing.
2018-09-30 11:57:51 +02:00
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
2018-09-30 11:57:51 +02:00
*/
public function testGetViewParametersFilled(): void
{
$clientId = new Preference;
$clientId->data = 'client-id';
2018-09-30 11:57:51 +02:00
$clientSecret = new Preference;
$clientSecret->data = 'client-secret';
2018-09-30 11:57:51 +02:00
Preferences::shouldReceive('getForUser')->twice()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn($clientId);
Preferences::shouldReceive('getForUser')->twice()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn($clientSecret);
2018-09-30 11:57:51 +02:00
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => 'client-id', 'client_secret' => 'client-secret', 'callback_uri' => 'http://localhost/import/ynab-callback',
'is_https' => false];
$this->assertEquals($expected, $result);
2018-09-30 11:57:51 +02:00
}
/**
* First test, user has nothing.
2018-09-30 11:57:51 +02:00
*
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testGetViewParametersNull(): void
2018-09-30 11:57:51 +02:00
{
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn(null);
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', null])->andReturn(null);
2018-09-30 11:57:51 +02:00
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->getViewParameters();
$expected = ['client_id' => '', 'client_secret' => '', 'callback_uri' => 'http://localhost/import/ynab-callback', 'is_https' => false];
$this->assertEquals($expected, $result);
}
/**
* @covers \FireflyIII\Import\Prerequisites\YnabPrerequisites
*/
public function testIsComplete(): void
{
Preferences::shouldReceive('getForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturn(null);
$object = new YnabPrerequisites();
$object->setUser($this->user());
$result = $object->isComplete();
$this->assertFalse($result);
}
/**
*
*/
public function testStorePrerequisites(): void
2018-09-30 11:57:51 +02:00
{
Preferences::shouldReceive('setForUser')->once()->withArgs([Mockery::any(), 'ynab_client_id', 'hello']);
Preferences::shouldReceive('setForUser')->once()->withArgs([Mockery::any(), 'ynab_client_secret', 'hi there']);
2018-09-30 11:57:51 +02:00
$data = [
'client_id' => 'hello',
'client_secret' => 'hi there',
];
2018-09-30 11:57:51 +02:00
$object = new YnabPrerequisites();
$object->setUser($this->user());
$object->storePrerequisites($data);
2018-09-30 11:57:51 +02:00
}
2018-12-31 07:48:23 +01:00
}