|
| 1 | +<?php |
| 2 | + |
| 3 | +use Mockery as m; |
| 4 | +use Jql\Project; |
| 5 | +use Jql\Http\Controllers\ProjectsController; |
| 6 | + |
| 7 | +class JqlControllerAdditionsTest extends JqlTestCase |
| 8 | +{ |
| 9 | + public function setUp() |
| 10 | + { |
| 11 | + parent::setUp(); |
| 12 | + Route::resource('projects', 'ProjectsController'); |
| 13 | + View::addLocation(__DIR__.'/fixtures/resources/views'); |
| 14 | + |
| 15 | + $this->controller = new ProjectsController; |
| 16 | + } |
| 17 | + |
| 18 | + public function testRenderMethodWithDefaultLayout() |
| 19 | + { |
| 20 | + // New Project |
| 21 | + $project = new Project; |
| 22 | + $project->id = 2; |
| 23 | + $project->exists = true; |
| 24 | + $project->name = 'Project 2'; |
| 25 | + $project->priority = 'low'; |
| 26 | + |
| 27 | + $mock = $this->mockProject($project); |
| 28 | + $response = $this->controller->callAction('index', [$mock]); |
| 29 | + |
| 30 | + $expectDefaultLayout = '<title>jQuery-Laravel with default layout</title>'; |
| 31 | + $expectProjectName = 'Project 2'; |
| 32 | + |
| 33 | + $this->assertContains($expectDefaultLayout, $response->getContent()); |
| 34 | + $this->assertNotContains($expectDefaultLayout.' foo', $response->getContent()); |
| 35 | + $this->assertContains($expectProjectName, $response->getContent()); |
| 36 | + $this->assertNotContains($expectProjectName.' foo', $response->getContent()); |
| 37 | + } |
| 38 | + |
| 39 | + public function testRenderMethodWithCustomLayout() |
| 40 | + { |
| 41 | + // New Project |
| 42 | + $project = new Project; |
| 43 | + $project->id = 3; |
| 44 | + $project->exists = true; |
| 45 | + $project->name = 'Project 3'; |
| 46 | + $project->priority = 'high'; |
| 47 | + |
| 48 | + $mock = $this->mockProject($project); |
| 49 | + $response = $this->controller->callAction('index', [$mock, 'app2']); |
| 50 | + |
| 51 | + $expectDefaultLayout = '<title>jQuery-Laravel with custom layout</title>'; |
| 52 | + $expectProjectName = 'Project 3'; |
| 53 | + |
| 54 | + $this->assertContains($expectDefaultLayout, $response->getContent()); |
| 55 | + $this->assertNotContains($expectDefaultLayout.' foo', $response->getContent()); |
| 56 | + $this->assertContains($expectProjectName, $response->getContent()); |
| 57 | + $this->assertNotContains($expectProjectName.' foo', $response->getContent()); |
| 58 | + } |
| 59 | + |
| 60 | + public function testRenderMethodWithoutLayout() |
| 61 | + { |
| 62 | + // New Project |
| 63 | + $project = new Project; |
| 64 | + $project->id = 4; |
| 65 | + $project->exists = true; |
| 66 | + $project->name = 'Project 4'; |
| 67 | + $project->priority = 'low'; |
| 68 | + |
| 69 | + $mock = $this->mockProject($project); |
| 70 | + $response = $this->controller->callAction('index', [$mock, false]); |
| 71 | + |
| 72 | + $expectDefaultLayout = '<title>jQuery-Laravel without layout</title>'; |
| 73 | + $expectProjectName = 'Project 4'; |
| 74 | + |
| 75 | + $this->assertContains($expectDefaultLayout, $response->getContent()); |
| 76 | + $this->assertContains($expectProjectName, $response->getContent()); |
| 77 | + $this->assertNotContains($expectProjectName.' foo', $response->getContent()); |
| 78 | + } |
| 79 | + |
| 80 | + public function testRenderMethodWithJSRequest() |
| 81 | + { |
| 82 | + // New Project |
| 83 | + $project = new Project; |
| 84 | + $project->id = 5; |
| 85 | + $project->exists = true; |
| 86 | + $project->name = 'Project 5'; |
| 87 | + $project->priority = 'low'; |
| 88 | + |
| 89 | + $mock = $this->mockProject($project); |
| 90 | + $response = $this->controller->callAction('index', [$mock, null, 'js']); |
| 91 | + |
| 92 | + $expectDefaultLayout = '<title>jQuery-Laravel tests</title>'; |
| 93 | + $expectProjectJson = json_encode($project); |
| 94 | + |
| 95 | + $this->assertNotContains($expectDefaultLayout, $response->getContent()); |
| 96 | + $this->assertContains($expectProjectJson, $response->getContent()); |
| 97 | + $this->assertNotContains($expectProjectJson.' foo', $response->getContent()); |
| 98 | + } |
| 99 | + |
| 100 | + protected function mockProject($project) |
| 101 | + { |
| 102 | + $mock = m::mock(Project::class); |
| 103 | + $mock->shouldReceive('all')->andReturn([$project]); |
| 104 | + |
| 105 | + return $mock; |
| 106 | + } |
| 107 | +} |
0 commit comments