2017-12-28 11:57:38 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* UpdateControllerTest.php
|
2020-02-16 13:59:55 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-12-28 11:57:38 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-12-28 11:57:38 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +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.
|
2017-12-28 11:57:38 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-12-28 11:57:38 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:45:03 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-12-28 11:57:38 +01:00
|
|
|
*
|
2019-10-02 06:45:03 +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/>.
|
2017-12-28 11:57:38 +01:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers\Admin;
|
|
|
|
|
2017-12-28 19:16:27 +01:00
|
|
|
use Carbon\Carbon;
|
2017-12-28 11:57:38 +01:00
|
|
|
use FireflyConfig;
|
2017-12-28 19:55:10 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2017-12-28 11:57:38 +01:00
|
|
|
use FireflyIII\Models\Configuration;
|
2018-09-03 18:52:46 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2020-01-05 19:29:28 +01:00
|
|
|
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequest;
|
2017-12-28 19:16:27 +01:00
|
|
|
use FireflyIII\Services\Github\Object\Release;
|
2018-03-02 17:07:32 +01:00
|
|
|
use Log;
|
2017-12-28 19:47:58 +01:00
|
|
|
use Mockery;
|
2017-12-28 11:57:38 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class UpdateControllerTest
|
2019-08-17 10:48:28 +02:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2017-12-28 11:57:38 +01:00
|
|
|
*/
|
2017-12-28 18:39:17 +01:00
|
|
|
class UpdateControllerTest extends TestCase
|
2017-12-28 11:57:38 +01:00
|
|
|
{
|
2018-02-28 20:18:47 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-09-02 20:27:26 +02:00
|
|
|
public function setUp(): void
|
2018-02-28 20:18:47 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-02-28 20:18:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-28 11:57:38 +01:00
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2017-12-28 11:57:38 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testIndex(): void
|
2017-12-28 11:57:38 +01:00
|
|
|
{
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock stuff
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock calls
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock update calls.
|
2020-01-05 19:29:28 +01:00
|
|
|
$config = new Configuration;
|
|
|
|
$config->data = -1;
|
|
|
|
$channelConfig = new Configuration;
|
|
|
|
$channelConfig->data = 'stable';
|
2017-12-28 11:57:38 +01:00
|
|
|
|
2020-01-05 19:29:28 +01:00
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
|
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
2019-06-23 11:13:36 +02:00
|
|
|
// call service
|
|
|
|
$this->be($this->user());
|
2017-12-28 11:57:38 +01:00
|
|
|
$response = $this->get(route('admin.update-check'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:39:17 +01:00
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2017-12-28 18:39:17 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testPost(): void
|
2017-12-28 18:39:17 +01:00
|
|
|
{
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock stuff
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock calls
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock update calls
|
2017-12-28 18:39:17 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
|
2017-12-28 19:47:58 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
2020-01-05 19:29:28 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['update_channel','stable'])->once()->andReturn(new Configuration);
|
|
|
|
//FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->once()->andReturn($channelConfig);
|
2019-06-23 11:13:36 +02:00
|
|
|
|
|
|
|
// call service
|
2017-12-28 18:39:17 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
|
|
|
|
$response->assertSessionHas('success');
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$response->assertRedirect(route('admin.update-check'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2018-08-30 20:58:07 +02:00
|
|
|
* @covers \FireflyIII\Helpers\Update\UpdateTrait
|
2017-12-28 18:39:17 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdateCheck(): void
|
2017-12-28 18:39:17 +01:00
|
|
|
{
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock stuff
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
2019-06-23 11:13:36 +02:00
|
|
|
// mock calls
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
2017-12-28 19:47:58 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2017-12-28 18:39:17 +01:00
|
|
|
|
2020-01-05 19:29:28 +01:00
|
|
|
$return = [
|
|
|
|
'version' => '2.0.0',
|
|
|
|
'date' => '2020-01-01'
|
2017-12-28 19:16:27 +01:00
|
|
|
];
|
2020-01-05 19:29:28 +01:00
|
|
|
|
|
|
|
// set some data
|
2017-12-28 19:16:27 +01:00
|
|
|
$updater = $this->mock(UpdateRequest::class);
|
2020-01-05 19:29:28 +01:00
|
|
|
$updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
|
|
|
|
->andReturn($return);
|
|
|
|
|
|
|
|
|
|
|
|
$channelConfig = new Configuration;
|
|
|
|
$channelConfig->data = 'stable';
|
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
|
2017-12-28 19:16:27 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('admin.update-check.manual'));
|
|
|
|
$response->assertStatus(200);
|
2020-01-05 19:29:28 +01:00
|
|
|
$response->assertSee(config('firefly.version'));
|
|
|
|
$response->assertSee('which is newer than the latest release');
|
2017-12-28 19:16:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2018-08-30 20:58:07 +02:00
|
|
|
* @covers \FireflyIII\Helpers\Update\UpdateTrait
|
2017-12-28 19:16:27 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdateCheckCurrent(): void
|
2017-12-28 19:16:27 +01:00
|
|
|
{
|
2019-06-23 11:13:36 +02:00
|
|
|
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2017-12-28 19:47:58 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
2020-01-05 19:29:28 +01:00
|
|
|
$channelConfig = new Configuration;
|
|
|
|
$channelConfig->data = 'stable';
|
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
|
2017-12-28 18:39:17 +01:00
|
|
|
|
2020-01-05 19:29:28 +01:00
|
|
|
$return = [
|
|
|
|
'version' => config('firefly.version'),
|
|
|
|
'date' => '2020-01-01'
|
2017-12-28 18:39:17 +01:00
|
|
|
];
|
2020-01-05 19:29:28 +01:00
|
|
|
|
|
|
|
// set some data
|
2017-12-28 19:16:27 +01:00
|
|
|
$updater = $this->mock(UpdateRequest::class);
|
2020-01-05 19:29:28 +01:00
|
|
|
$updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
|
|
|
|
->andReturn($return);
|
2017-12-28 19:16:27 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('admin.update-check.manual'));
|
|
|
|
$response->assertStatus(200);
|
2020-01-05 19:29:28 +01:00
|
|
|
$response->assertSee(config('firefly.version'));
|
2017-12-28 19:16:27 +01:00
|
|
|
$response->assertSee('the latest available release');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2018-08-30 20:58:07 +02:00
|
|
|
* @covers \FireflyIII\Helpers\Update\UpdateTrait
|
2017-12-28 19:16:27 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdateCheckError(): void
|
2017-12-28 19:16:27 +01:00
|
|
|
{
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2018-07-08 12:08:53 +02:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
2020-01-05 19:29:28 +01:00
|
|
|
$channelConfig = new Configuration;
|
|
|
|
$channelConfig->data = 'stable';
|
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
|
2017-12-28 18:39:17 +01:00
|
|
|
|
2017-12-28 19:16:27 +01:00
|
|
|
$updater = $this->mock(UpdateRequest::class);
|
2020-01-05 19:29:28 +01:00
|
|
|
$updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
|
|
|
|
->andThrow(new FireflyException('Something broke.'));
|
|
|
|
|
|
|
|
|
2017-12-28 18:39:17 +01:00
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('admin.update-check.manual'));
|
|
|
|
$response->assertStatus(200);
|
2017-12-29 09:05:35 +01:00
|
|
|
$response->assertSee('An error occurred while checking');
|
2017-12-28 18:39:17 +01:00
|
|
|
}
|
2017-12-28 19:55:10 +01:00
|
|
|
|
|
|
|
/**
|
2018-07-01 09:27:22 +02:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Admin\UpdateController
|
2018-08-30 20:58:07 +02:00
|
|
|
* @covers \FireflyIII\Helpers\Update\UpdateTrait
|
2017-12-28 19:55:10 +01:00
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testUpdateCheckNewer(): void
|
2017-12-28 19:55:10 +01:00
|
|
|
{
|
2018-09-03 18:52:46 +02:00
|
|
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
|
|
|
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
|
|
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->mockDefaultSession();
|
2018-09-03 18:52:46 +02:00
|
|
|
|
2017-12-29 09:05:35 +01:00
|
|
|
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
2017-12-28 19:55:10 +01:00
|
|
|
|
2020-01-05 19:29:28 +01:00
|
|
|
$channelConfig = new Configuration;
|
|
|
|
$channelConfig->data = 'stable';
|
|
|
|
FireflyConfig::shouldReceive('get')->withArgs(['update_channel', 'stable'])->atleast()->once()->andReturn($channelConfig);
|
|
|
|
|
|
|
|
$return = [
|
|
|
|
'version' => '100',
|
|
|
|
'date' => '2020-01-01'
|
2017-12-28 19:55:10 +01:00
|
|
|
];
|
2020-01-05 19:29:28 +01:00
|
|
|
|
|
|
|
// set some data
|
2017-12-28 19:55:10 +01:00
|
|
|
$updater = $this->mock(UpdateRequest::class);
|
2020-01-05 19:29:28 +01:00
|
|
|
$updater->shouldReceive('getVersion')->withArgs(['stable'])->atLeast()->once()
|
|
|
|
->andReturn($return);
|
2017-12-28 19:55:10 +01:00
|
|
|
|
|
|
|
// expect a new release (because of .1)
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->post(route('admin.update-check.manual'));
|
|
|
|
$response->assertStatus(200);
|
2020-01-05 19:29:28 +01:00
|
|
|
$response->assertSee('A new version of Firefly III is available');
|
2017-12-28 19:55:10 +01:00
|
|
|
}
|
2017-12-28 11:57:38 +01:00
|
|
|
}
|