mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Move tests
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* MigrateAttachmentsTest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Console\Commands\Upgrade;
|
||||
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class MigrateAttachmentsTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class MigrateAttachmentsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::markTestIncomplete('Incomplete for refactor.');
|
||||
|
||||
return;
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
|
||||
*/
|
||||
public function testHandle(): void
|
||||
{
|
||||
$false = new Configuration;
|
||||
$false->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
|
||||
// assume all is well.
|
||||
$this->artisan('firefly-iii:migrate-attachments')
|
||||
->expectsOutput('All attachments are OK.')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateAttachments
|
||||
*/
|
||||
public function testHandleMigrate(): void
|
||||
{
|
||||
$false = new Configuration;
|
||||
$false->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_attachments', false])->andReturn($false);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_attachments', true]);
|
||||
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => 1,
|
||||
'attachable_id' => 1,
|
||||
'attachable_type' => TransactionJournal::class,
|
||||
'description' => 'Hello',
|
||||
'md5' => md5('hello'),
|
||||
'filename' => 'test.pdf',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 1,
|
||||
]);
|
||||
|
||||
// assume all is well.
|
||||
$this->artisan('firefly-iii:migrate-attachments')
|
||||
->expectsOutput('Updated 1 attachment(s).')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertCount(0, Attachment::where('id', $attachment->id)->where('description', '!=', '')->get());
|
||||
$this->assertCount(1, Attachment::where('id', $attachment->id)->where('description', '=', '')->get());
|
||||
$this->assertCount(1, Note::where('noteable_id', $attachment->id)->where('noteable_type', Attachment::class)->get());
|
||||
|
||||
$attachment->forceDelete();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user