Files
firefly-iii/tests/acceptance/Controllers/RuleControllerTest.php

229 lines
6.5 KiB
PHP
Raw Normal View History

2016-11-19 20:30:30 +01:00
<?php
2016-12-06 09:16:36 +01:00
/**
* RuleControllerTest.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-18 19:34:03 +01:00
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
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:43.
2016-11-19 20:30:30 +01:00
*/
class RuleControllerTest 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\RuleController::create
2016-11-19 20:30:30 +01:00
*/
public function testCreate()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.create', [1]));
$this->assertResponseStatus(200);
$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\RuleController::delete
2016-11-19 20:30:30 +01:00
*/
public function testDelete()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.delete', [1]));
$this->assertResponseStatus(200);
$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\RuleController::destroy
2016-11-19 20:30:30 +01:00
*/
public function testDestroy()
{
2016-12-18 19:34:03 +01:00
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('destroy');
$this->session(['rules.delete.url' => 'http://localhost']);
$this->be($this->user());
$this->call('post', route('rules.destroy', [1]));
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
$this->assertRedirectedToRoute('index');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::down
2016-11-19 20:30:30 +01:00
*/
public function testDown()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.down', [1]));
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('rules.index');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::edit
2016-11-19 20:30:30 +01:00
*/
public function testEdit()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.edit', [1]));
$this->assertResponseStatus(200);
$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\RuleController::index
2016-11-19 20:30:30 +01:00
*/
public function testIndex()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.index'));
$this->assertResponseStatus(200);
$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\RuleController::reorderRuleActions
2016-11-19 20:30:30 +01:00
*/
public function testReorderRuleActions()
{
2016-12-18 19:34:03 +01:00
$data = [
'triggers' => [1, 2, 3],
];
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('reorderRuleActions');
$this->be($this->user());
$this->call('post', route('rules.reorder-actions', [1]), $data);
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::reorderRuleTriggers
2016-11-19 20:30:30 +01:00
*/
public function testReorderRuleTriggers()
{
2016-12-18 19:34:03 +01:00
$data = [
'triggers' => [1, 2, 3],
];
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('reorderRuleTriggers');
$this->be($this->user());
$this->call('post', route('rules.reorder-triggers', [1]), $data);
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::store
2016-11-19 20:30:30 +01:00
*/
public function testStore()
{
2016-12-18 19:34:03 +01:00
$this->session(['rules.create.url' => 'http://localhost']);
$data = [
'rule_group_id' => 1,
'active' => 1,
'title' => 'A',
'trigger' => 'store-journal',
'description' => 'D',
'rule-trigger' => [
1 => 'from_account_starts',
],
'rule-trigger-value' => [
1 => 'B',
],
'rule-action' => [
1 => 'set_category',
],
'rule-action-value' => [
1 => 'C',
],
];
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('store')->andReturn(new Rule);
$this->be($this->user());
$this->call('post', route('rules.store', [1]), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-18 19:34:03 +01:00
* This actually hits an error and not the actually code but OK.
*
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::testTriggers
2016-11-19 20:30:30 +01:00
*/
public function testTestTriggers()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.test-triggers', [1]));
$this->assertResponseStatus(200);
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::up
2016-11-19 20:30:30 +01:00
*/
public function testUp()
{
2016-12-18 19:34:03 +01:00
$this->be($this->user());
$this->call('get', route('rules.up', [1]));
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('rules.index');
2016-11-19 20:30:30 +01:00
}
/**
2016-12-07 19:53:41 +01:00
* @covers \FireflyIII\Http\Controllers\RuleController::update
2016-11-19 20:30:30 +01:00
*/
public function testUpdate()
{
2016-12-18 19:34:03 +01:00
$data = [
'rule_group_id' => 1,
'title' => 'Your first default rule',
'trigger' => 'store-journal',
'active' => 1,
'description' => 'This rule is an example. You can safely delete it.',
'rule-trigger' => [
1 => 'description_is',
],
'rule-trigger-value' => [
1 => 'something',
],
'rule-action' => [
1 => 'prepend_description',
],
'rule-action-value' => [
1 => 'Bla bla',
],
];
$this->session(['rules.edit.url' => 'http://localhost']);
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('update');
$this->be($this->user());
$this->call('post', route('rules.update', [1]), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
2016-11-19 20:30:30 +01:00
}
}