Files
firefly-iii/tests/Unit/Factory/AttachmentFactoryTest.php

113 lines
3.1 KiB
PHP
Raw Normal View History

2018-08-24 07:18:33 +02:00
<?php
/**
* AttachmentFactoryTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-08-24 07:18:33 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-08-24 07:18:33 +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-24 07:18:33 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-08-24 07:18:33 +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-24 07:18:33 +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-24 07:18:33 +02:00
*/
declare(strict_types=1);
namespace Tests\Unit\Factory;
2019-06-16 13:16:46 +02:00
use FireflyIII\Exceptions\FireflyException;
2018-08-24 07:18:33 +02:00
use FireflyIII\Factory\AttachmentFactory;
2019-06-16 13:16:46 +02:00
use FireflyIII\Models\Transaction;
2018-08-24 07:18:33 +02:00
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
*
* Class AttachmentFactoryTest
*/
class AttachmentFactoryTest 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-24 07:18:33 +02:00
}
/**
* @covers \FireflyIII\Factory\AttachmentFactory
*/
public function testCreate(): void
{
2019-06-16 13:16:46 +02:00
$journal = $this->getRandomWithdrawal();
2018-08-24 07:18:33 +02:00
$data = [
'model_id' => $journal->id,
'model' => TransactionJournal::class,
'filename' => 'testfile.pdf',
'title' => 'File name',
'notes' => 'Some notes',
];
2019-06-16 13:16:46 +02:00
/** @var AttachmentFactory $factory */
$factory = app(AttachmentFactory::class);
2018-08-24 07:18:33 +02:00
$factory->setUser($this->user());
2019-06-16 13:16:46 +02:00
try {
$result = $factory->create($data);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
2018-08-24 07:18:33 +02:00
$this->assertEquals($data['title'], $result->title);
$this->assertEquals(1, $result->notes()->count());
2020-08-23 07:42:14 +02:00
$result->forceDelete();
2018-08-24 07:18:33 +02:00
2019-06-16 13:16:46 +02:00
}
/**
* @covers \FireflyIII\Factory\AttachmentFactory
*/
public function testCreateWithTransaction(): void
2019-06-16 13:16:46 +02:00
{
$journal = $this->getRandomWithdrawal();
2019-06-16 13:16:46 +02:00
$transaction = $journal->transactions()->first();
$data = [
2019-06-16 13:16:46 +02:00
'model_id' => $transaction->id,
'model' => Transaction::class,
'filename' => 'testfile.pdf',
'title' => 'File name',
'notes' => 'Some notes',
];
/** @var AttachmentFactory $factory */
$factory = app(AttachmentFactory::class);
$factory->setUser($this->user());
try {
$result = $factory->create($data);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertEquals($data['title'], $result->title);
$this->assertEquals(1, $result->notes()->count());
$this->assertEquals($journal->id, $result->attachable_id);
2019-06-16 13:16:46 +02:00
2020-08-23 07:42:14 +02:00
$result->forceDelete();
2019-06-16 13:16:46 +02:00
2018-08-24 07:18:33 +02:00
}
2018-12-31 07:48:23 +01:00
}