Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from jkniest/feature-error-bag
Browse files Browse the repository at this point in the history
Tests to ensure that the error bag is not empty
  • Loading branch information
jkniest authored Nov 21, 2017
2 parents 20c3b3b + dc1bdcb commit fd41dd2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased
### Changed
- Sites are not going to be cached if they do not have a 200 status code
- Sites are not being cached if they do not have a 200 status code
- Sites are not being cached if there is a validation error

## [1.0.1] - 2017-09-03
### Added
Expand Down
5 changes: 5 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ protected function setUp()
Route::get('/error', function () {
return response('Error: ' . request('test'), 500);
});
Route::get('/validation', function () {
request()->validate([
'name' => 'required'
]);
});
});
}

Expand Down
48 changes: 48 additions & 0 deletions tests/Feature/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,52 @@ public function it_will_ignore_routes_that_are_not_returning_a_200_status_code()
// Also: The cache key should not have been generated (or at least with the null content)
$this->assertNull(cache('test_error_en'));
}

/** @test */
public function it_will_not_cache_any_pages_if_the_error_bag_is_not_empty()
{
// Given: The user was earlier on the example page
session()->setPreviousUrl(url('/example'));

// When: The user sends a GET request to a page which will throw an validation exception
$response = $this->get('/validation');

// Then: The session should have an validation error
$response->assertSessionHasErrors(['name']);

// And: The user should be redirected to the example page again
$response->assertRedirect('/example');

// And: The cache key should not have been generated (or at least with the null content)
$this->assertNull(cache('test_example_en'));
}

/** @test */
public function it_will_not_load_the_cache_of_a_page_if_the_error_bag_is_not_empty()
{
// Given: The user visited the example before
$response = $this->get('/example?test=Hello');

// And: This page was being cached
$this->assertNotNull(cache('test_example_en'));

// Also: The user should see Hello
$response->assertSee('Hello');

// Given: The user was earlier on the example page
session()->setPreviousUrl(url('/example'));

// When: The user sends a GET request to a page which will throw an validation exception
$response = $this->get('/validation');

// Then: The session should have an validation error
$response->assertSessionHasErrors(['name']);

// And: The user should be redirected to the example page again
$response->assertRedirect('/example');

// And: The user should not see the Hello
$response->assertDontSee('Hello');
}

}

0 comments on commit fd41dd2

Please sign in to comment.