|
| 1 | +<?php |
| 2 | + |
| 3 | +use Mockery as m; |
| 4 | + |
| 5 | +class JqlHelpersTest extends JqlTestCase |
| 6 | +{ |
| 7 | + public function testdomId() |
| 8 | + { |
| 9 | + // New Project |
| 10 | + $project = new Jql\Project; |
| 11 | + |
| 12 | + $domId = dom_id($project); |
| 13 | + $expect = 'create_project'; |
| 14 | + $this->assertEquals($expect, $domId); |
| 15 | + |
| 16 | + $expect2 = 'project_2'; |
| 17 | + $this->assertNotEquals($expect2, $domId); |
| 18 | + |
| 19 | + // Existing Project |
| 20 | + $project2 = clone $project; |
| 21 | + $project2->id = 2; |
| 22 | + $project2->exists = true; |
| 23 | + |
| 24 | + $domId2 = dom_id($project2); |
| 25 | + $this->assertEquals($expect2, $domId2); |
| 26 | + } |
| 27 | + |
| 28 | + public function testFormId() |
| 29 | + { |
| 30 | + // New Project |
| 31 | + $project = new Jql\Project; |
| 32 | + |
| 33 | + $formId = form_id($project); |
| 34 | + $expect = 'create_project'; |
| 35 | + $this->assertEquals($expect, $formId); |
| 36 | + |
| 37 | + $expect2 = 'edit_project_3'; |
| 38 | + $this->assertNotEquals($expect2, $formId); |
| 39 | + |
| 40 | + // Existing Project |
| 41 | + $project2 = clone $project; |
| 42 | + $project2->id = 3; |
| 43 | + $project2->exists = true; |
| 44 | + |
| 45 | + $formId2 = form_id($project2); |
| 46 | + $this->assertEquals($expect2, $formId2); |
| 47 | + } |
| 48 | + |
| 49 | + public function testFormFor() |
| 50 | + { |
| 51 | + Route::resource('projects', 'ProjectsController'); |
| 52 | + |
| 53 | + // New Project |
| 54 | + $project = new Jql\Project; |
| 55 | + |
| 56 | + $form = form_for($project); |
| 57 | + $expect = '<form method="POST" action="http://localhost/projects" accept-charset="UTF-8" id="create_project" class="create_project">'. |
| 58 | + '<input name="_token" type="hidden">'; |
| 59 | + $this->assertEquals($expect, $form); |
| 60 | + |
| 61 | + $expect2 = '<form method="POST" action="http://localhost/projects/3" accept-charset="UTF-8" id="edit_project_3" class="edit_project">'. |
| 62 | + '<input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden">'; |
| 63 | + $this->assertNotEquals($expect2, $form); |
| 64 | + |
| 65 | + // Existing Project |
| 66 | + $project2 = clone $project; |
| 67 | + $project2->id = 3; |
| 68 | + $project2->exists = true; |
| 69 | + |
| 70 | + $form2 = form_for($project2); |
| 71 | + $this->assertEquals($expect2, $form2); |
| 72 | + } |
| 73 | + |
| 74 | + public function testFormerFor() |
| 75 | + { |
| 76 | + Route::resource('projects', 'ProjectsController'); |
| 77 | + $this->createSession(); |
| 78 | + |
| 79 | + // New Project |
| 80 | + $project = new Jql\Project; |
| 81 | + |
| 82 | + $former = former_for($project); |
| 83 | + $expect = '<form accept-charset="utf-8" class="form-horizontal create_project" id="create_project" method="POST" action="http://localhost/projects">'; |
| 84 | + $this->assertEquals($expect, $former); |
| 85 | + |
| 86 | + $expect2 = '<form accept-charset="utf-8" class="form-horizontal edit_project" id="edit_project_3" method="POST" action="http://localhost/projects/3">'. |
| 87 | + '<input class="form-control" type="hidden" name="_method" value="PATCH">'; |
| 88 | + $this->assertNotEquals($expect2, $former); |
| 89 | + |
| 90 | + // Existing Project |
| 91 | + $project2 = clone $project; |
| 92 | + $project2->id = 3; |
| 93 | + $project2->exists = true; |
| 94 | + |
| 95 | + $former2 = (string) former_for($project2); |
| 96 | + $this->assertEquals($expect2, $former2); |
| 97 | + } |
| 98 | + |
| 99 | + public function testButtonTo() |
| 100 | + { |
| 101 | + Route::resource('projects', 'ProjectsController'); |
| 102 | + |
| 103 | + // Create button |
| 104 | + $form = button_to('Create', ['action' => 'ProjectsController@create']); |
| 105 | + $expect = '<form method="POST" action="http://localhost/projects/create" accept-charset="UTF-8" class="button_to">'. |
| 106 | + '<input name="_token" type="hidden">'. |
| 107 | + '<div><input type="submit" value="Create"></div></form>'; |
| 108 | + $this->assertEquals($expect, $form); |
| 109 | + |
| 110 | + $expect2 = '<form method="POST" action="http://www.example.com" accept-charset="UTF-8" class="button_to" data-remote="true"><input name="_method" type="hidden" value="DELETE">'. |
| 111 | + '<input name="_token" type="hidden">'. |
| 112 | + '<div><input data-confirm="Are you sure?" data-disable-with="loading..." type="submit" value="Destroy"></div></form>'; |
| 113 | + $this->assertNotEquals($expect2, $form); |
| 114 | + |
| 115 | + // Destroy Button |
| 116 | + $form2 = button_to( |
| 117 | + 'Destroy', |
| 118 | + [ |
| 119 | + 'url' => 'http://www.example.com', |
| 120 | + 'method' => 'delete', |
| 121 | + 'data-remote' => 'true', |
| 122 | + 'data-confirm' => 'Are you sure?', |
| 123 | + 'data-disable-with' => 'loading...' |
| 124 | + ] |
| 125 | + ); |
| 126 | + $this->assertEquals($expect2, $form2); |
| 127 | + } |
| 128 | +} |
0 commit comments