Skip to content

Commit

Permalink
Tests for Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Batuhan Baş committed Oct 4, 2018
1 parent 320006a commit 1be4cc7
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/Feature/Settings/CategoriesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Tests\Feature\Settings;

use App\Models\Setting\Category;
use Tests\Feature\FeatureTestCase;

class CategoriesTest extends FeatureTestCase
{
public function testItShouldSeeCategoryListPage()
{
$this->loginAs()
->get(route('categories.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.categories', 2));
}

public function testItShouldSeeCategoryCreatePage()
{
$this->loginAs()
->get(route('categories.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.categories', 1)]));
}

public function testItShouldCreateCategory()
{
$this->loginAs()
->post(route('categories.store'), $this->getCategoryRequest())
->assertStatus(302)
->assertRedirect(route('categories.index'));

$this->assertFlashLevel('success');
}

public function testItShouldSeeCategoryUpdatePage()
{
$category = Category::create($this->getCategoryRequest());

$this->loginAs()
->get(route('categories.edit', ['category' => $category->id]))
->assertStatus(200)
->assertSee($category->name);
}

public function testItShouldUpdateCategory()
{
$request = $this->getCategoryRequest();

$category = Category::create($request);

$request['name'] = $this->faker->text(15);

$this->loginAs()
->patch(route('categories.update', $category->id), $request)
->assertStatus(302)
->assertRedirect(route('categories.index'));

$this->assertFlashLevel('success');
}

public function testItShouldDeleteCategory()
{
$category = Category::create($this->getCategoryRequest());

$this->loginAs()
->delete(route('categories.destroy', $category->id))
->assertStatus(302)
->assertRedirect(route('categories.index'));

$this->assertFlashLevel('success');
}

private function getCategoryRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'type' => 'other',
'color' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0
];
}
}
83 changes: 83 additions & 0 deletions tests/Feature/Settings/CurrenciesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Tests\Feature\Settings;

use App\Models\Setting\Currency;
use Tests\Feature\FeatureTestCase;

class CurrenciesTest extends FeatureTestCase
{

public function testItShouldSeeCurrencyListPage()
{
$this->loginAs()
->get(route('currencies.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.currencies', 2));
}

public function testItShouldSeeCurrencyCreatePage()
{
$this->loginAs()
->get(route('currencies.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.currencies', 1)]));
}

public function testItShouldCreateCurrency()
{
$this->loginAs()
->post(route('currencies.store'), $this->getCurrencyRequest())
->assertStatus(302)
->assertRedirect(route('currencies.index'));

$this->assertFlashLevel('success');
}

public function testItShouldUpdateCurrency()
{
$request = $this->getCurrencyRequest();

$currency = Currency::create($request);

$request['name'] = $this->faker->text(15);

$this->loginAs()
->patch(route('currencies.update', $currency->id), $request)
->assertStatus(302)
->assertRedirect(route('currencies.index'));

$this->assertFlashLevel('success');
}

public function testItShouldDeleteCurrency()
{
$currency = Currency::create($this->getCurrencyRequest());

$this->loginAs()
->delete(route('currencies.destroy', $currency->id))
->assertStatus(302)
->assertRedirect(route('currencies.index'));

$this->assertFlashLevel('success');
}


private function getCurrencyRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'code' => $this->faker->text(strtoupper(5)),
'rate' => $this->faker->boolean(1),
'precision' => $this->faker->text(5),
'symbol' => $this->faker->text(5),
'symbol_first' => 1,
'symbol_position' => 'after_amount',
'decimal_mark' => $this->faker->text(5),
'thousands_separator' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
'default_currency' => $this->faker->boolean ? 1 : 0
];
}
}
73 changes: 73 additions & 0 deletions tests/Feature/Settings/TaxesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Tests\Feature\Settings;

use App\Models\Setting\Tax;
use Tests\Feature\FeatureTestCase;

class TaxesTest extends FeatureTestCase
{
public function testItShouldSeeTaxListPage()
{
$this->loginAs()
->get(route('taxes.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.tax_rates', 2));
}

public function testItShouldSeeTaxCreatePage()
{
$this->loginAs()
->get(route('taxes.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.taxes', 1)]));
}

public function testItShouldCreateTax()
{
$this->loginAs()
->post(route('taxes.store'), $this->getTaxRequest())
->assertStatus(302)
->assertRedirect(route('taxes.index'));

$this->assertFlashLevel('success');
}

public function testItShouldUpdateTax()
{
$request = $this->getTaxRequest();

$tax = Tax::create($request);

$request['name'] = $this->faker->text(15);

$this->loginAs()
->patch(route('taxes.update', $tax->id), $request)
->assertStatus(302)
->assertRedirect(route('taxes.index'));

$this->assertFlashLevel('success');
}

public function testItShouldDeleteTax()
{
$tax = Tax::create($this->getTaxRequest());

$this->loginAs()
->delete(route('taxes.destroy', $tax->id))
->assertStatus(302)
->assertRedirect(route('taxes.index'));

$this->assertFlashLevel('success');
}

private function getTaxRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'rate' => $this->faker->randomFloat(2, 10, 20),
'enabled' => $this->faker->boolean ? 1 : 0
];
}
}

0 comments on commit 1be4cc7

Please sign in to comment.