2016-11-19 20:30:30 +01:00
|
|
|
<?php
|
2016-12-06 09:16:36 +01:00
|
|
|
/**
|
|
|
|
* AttachmentControllerTest.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
*/
|
2016-12-11 13:28:13 +01:00
|
|
|
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
2016-11-19 20:30:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-10 06:54:50 +01:00
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:38.
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
class AttachmentControllerTest extends TestCase
|
|
|
|
{
|
2016-11-20 07:24:18 +01:00
|
|
|
|
2016-11-19 20:30:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-11-20 08:30:25 +01:00
|
|
|
parent::setUp();
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::delete
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testDelete()
|
|
|
|
{
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('attachments.delete', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::destroy
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testDestroy()
|
|
|
|
{
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->session(['attachments.delete.url' => 'http://localhost']);
|
|
|
|
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('destroy')->andReturn(true);
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('attachments.destroy', [1]));
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::download
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testDownload()
|
|
|
|
{
|
2016-12-25 12:23:36 +01:00
|
|
|
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('exists')->once()->andReturn(true);
|
|
|
|
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
|
|
|
|
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('attachments.download', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('This is attachment number one.');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::edit
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testEdit()
|
|
|
|
{
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('attachments.edit', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::preview
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testPreview()
|
|
|
|
{
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('attachments.preview', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 19:53:41 +01:00
|
|
|
* @covers \FireflyIII\Http\Controllers\AttachmentController::update
|
2016-11-19 20:30:30 +01:00
|
|
|
*/
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->session(['attachments.edit.url' => 'http://localhost']);
|
|
|
|
$data = [
|
|
|
|
'title' => 'Some updated title ' . rand(1000, 9999),
|
|
|
|
'notes' => '',
|
|
|
|
'description' => '',
|
|
|
|
];
|
2016-11-20 11:43:19 +01:00
|
|
|
|
2016-12-11 13:28:13 +01:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('attachments.update', [1]), $data);
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
|
|
|
|
// view should be updated
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('attachments.edit', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
$this->see($data['title']);
|
2016-11-20 11:43:19 +01:00
|
|
|
}
|
2016-12-11 13:28:13 +01:00
|
|
|
|
2016-11-19 20:30:30 +01:00
|
|
|
}
|