|
| 1 | +<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration; |
| 2 | + |
| 3 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
| 4 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; |
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; |
| 6 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; |
| 7 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; |
| 8 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
| 9 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; |
| 10 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; |
| 11 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; |
| 12 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; |
| 13 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; |
| 14 | +use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; |
| 15 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 16 | + |
| 17 | +/** |
| 18 | +* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
| 19 | +* @SuppressWarnings(PHPMD.TooManyMethods) |
| 20 | + */ |
| 21 | +class CachedBuilderPaginationTest extends IntegrationTestCase |
| 22 | +{ |
| 23 | + use RefreshDatabase; |
| 24 | + |
| 25 | + public function testPaginationIsCached() |
| 26 | + { |
| 27 | + $authors = (new Author) |
| 28 | + ->paginate(3); |
| 29 | + |
| 30 | + $key = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1'); |
| 31 | + $tags = [ |
| 32 | + 'genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor', |
| 33 | + ]; |
| 34 | + |
| 35 | + $cachedResults = $this->cache() |
| 36 | + ->tags($tags) |
| 37 | + ->get($key)['value']; |
| 38 | + $liveResults = (new UncachedAuthor) |
| 39 | + ->paginate(3); |
| 40 | + |
| 41 | + $this->assertEquals($cachedResults->toArray(), $authors->toArray()); |
| 42 | + $this->assertEquals($liveResults->toArray(), $authors->toArray()); |
| 43 | + } |
| 44 | + |
| 45 | + public function testPaginationReturnsCorrectLinks() |
| 46 | + { |
| 47 | + $booksPage1 = (new Book) |
| 48 | + ->paginate(2); |
| 49 | + $booksPage2 = (new Book) |
| 50 | + ->paginate(2, ['*'], null, 2); |
| 51 | + $booksPage24 = (new Book) |
| 52 | + ->paginate(2, ['*'], null, 24); |
| 53 | + |
| 54 | + $this->assertCount(2, $booksPage1); |
| 55 | + $this->assertCount(2, $booksPage2); |
| 56 | + $this->assertCount(2, $booksPage24); |
| 57 | + $this->assertContains( |
| 58 | + '<li class="page-item active"><span class="page-link">1</span></li>', |
| 59 | + (string) $booksPage1->links() |
| 60 | + ); |
| 61 | + $this->assertContains( |
| 62 | + '<li class="page-item active"><span class="page-link">2</span></li>', |
| 63 | + (string) $booksPage2->links() |
| 64 | + ); |
| 65 | + $this->assertContains( |
| 66 | + '<li class="page-item active"><span class="page-link">24</span></li>', |
| 67 | + (string) $booksPage24->links() |
| 68 | + ); |
| 69 | + } |
| 70 | +} |
0 commit comments