|
| 1 | +<?php |
| 2 | + |
| 3 | +use Mockery as m; |
| 4 | + |
| 5 | +class JqlBladeExtensionsTest extends JqlTestCase |
| 6 | +{ |
| 7 | + public function testContentTag() |
| 8 | + { |
| 9 | + $contentTag = <<<EOT |
| 10 | +@content_tag('div') |
| 11 | +text |
| 12 | +@endcontent_tag('div') |
| 13 | +
|
| 14 | +EOT; |
| 15 | + $expect = <<<EOT |
| 16 | +<?php echo '<'.'div'.app('html')->attributes([]).'>'; |
| 17 | + ?>text |
| 18 | +<?php echo '</'.'div'.'>'; |
| 19 | + ?> |
| 20 | +EOT; |
| 21 | + $view = Blade::compileString($contentTag); |
| 22 | + $this->assertEquals($expect, $view); |
| 23 | + |
| 24 | + $expect2 = <<<EOT |
| 25 | +<?php echo '<'.'div'.app('html')->attributes([]).'>'; ?>text2 <?php echo '</'.'div'.'>'; |
| 26 | + ?> |
| 27 | +EOT; |
| 28 | + $this->assertNotEquals($expect2, $view); |
| 29 | + |
| 30 | + $contentTag2 = <<<EOT |
| 31 | +@content_tag('div') text2 @end_content_tag('div') |
| 32 | +
|
| 33 | +EOT; |
| 34 | + $view2 = Blade::compileString($contentTag2); |
| 35 | + $this->assertEquals($expect2, $view2); |
| 36 | + } |
| 37 | + |
| 38 | + public function testContentTagWithAttributes() |
| 39 | + { |
| 40 | + $contentTag = <<<EOT |
| 41 | +@content_tag('div', ['class' => 'div-tag-class']) |
| 42 | +text |
| 43 | +@endcontent_tag('div') |
| 44 | +
|
| 45 | +EOT; |
| 46 | + $expect = <<<EOT |
| 47 | +<?php echo '<'.'div'.app('html')->attributes(['class' => 'div-tag-class']).'>'; |
| 48 | + ?>text |
| 49 | +<?php echo '</'.'div'.'>'; |
| 50 | + ?> |
| 51 | +EOT; |
| 52 | + $view = Blade::compileString($contentTag); |
| 53 | + $this->assertEquals($expect, $view); |
| 54 | + |
| 55 | + $expect2 = <<<EOT |
| 56 | +<?php echo '<'.'div'.app('html')->attributes(['id' => 'div_tag_id']).'>'; ?>text2 <?php echo '</'.'div'.'>'; |
| 57 | + ?> |
| 58 | +EOT; |
| 59 | + $this->assertNotEquals($expect2, $view); |
| 60 | + |
| 61 | + $contentTag2 = <<<EOT |
| 62 | +@content_tag('div', ['id' => 'div_tag_id']) text2 @end_content_tag('div') |
| 63 | +
|
| 64 | +EOT; |
| 65 | + $view2 = Blade::compileString($contentTag2); |
| 66 | + $this->assertEquals($expect2, $view2); |
| 67 | + } |
| 68 | + |
| 69 | + public function testContentTagFor() |
| 70 | + { |
| 71 | + // Existing Project |
| 72 | + $project = new Jql\Project; |
| 73 | + $project->id = 3; |
| 74 | + $project->exists = true; |
| 75 | + |
| 76 | + $contentTagFor = <<<EOT |
| 77 | +@content_tag_for('div', \$project) |
| 78 | +text |
| 79 | +@endcontent_tag_for('div') |
| 80 | +
|
| 81 | +EOT; |
| 82 | + $expect = <<<EOT |
| 83 | +<?php |
| 84 | + \$projectRecord = \$project; |
| 85 | + if (! is_a(\$projectRecord, "\Illuminate\Support\Collection")) { |
| 86 | + \$projectRecord = new \Illuminate\Support\Collection([\$projectRecord]); |
| 87 | + } |
| 88 | + \$projectIndex = -1;// -1 because we increment index at the beginnning of the loop |
| 89 | + \$projectRecord->each(function(\$project) use(\$__env, &\$projectIndex){ |
| 90 | + \$projectIndex++; |
| 91 | + \$options = (array) []; |
| 92 | + \$options['class'] = implode(" ", |
| 93 | + array_filter([dom_class(\$project, null), array_get(\$options, 'class')]) |
| 94 | + ); |
| 95 | + \$options['id'] = dom_id(\$project, null); |
| 96 | + echo '<'.'div'.app('html')->attributes(\$options).'>'; |
| 97 | +?>text |
| 98 | +<?php |
| 99 | + echo '</'.'div'.'>'; |
| 100 | +
|
| 101 | + }); |
| 102 | +?> |
| 103 | +EOT; |
| 104 | + $view = Blade::compileString($contentTagFor); |
| 105 | + $this->assertEquals($expect, $view); |
| 106 | + } |
| 107 | + |
| 108 | + public function testContentTagForWithOptions() |
| 109 | + { |
| 110 | + // Existing Project |
| 111 | + $project = new Jql\Project; |
| 112 | + $project->id = 3; |
| 113 | + $project->exists = true; |
| 114 | + |
| 115 | + $contentTagFor = <<<EOT |
| 116 | +@content_tag_for('div', \$project, 'edit_prefix', ['remote' => 'true']) |
| 117 | +text |
| 118 | +@endcontent_tag_for('div') |
| 119 | +
|
| 120 | +EOT; |
| 121 | + $expect = <<<EOT |
| 122 | +<?php |
| 123 | + \$projectRecord = \$project; |
| 124 | + if (! is_a(\$projectRecord, "\Illuminate\Support\Collection")) { |
| 125 | + \$projectRecord = new \Illuminate\Support\Collection([\$projectRecord]); |
| 126 | + } |
| 127 | + \$projectIndex = -1;// -1 because we increment index at the beginnning of the loop |
| 128 | + \$projectRecord->each(function(\$project) use(\$__env, &\$projectIndex){ |
| 129 | + \$projectIndex++; |
| 130 | + \$options = (array) ['remote' => 'true']; |
| 131 | + \$options['class'] = implode(" ", |
| 132 | + array_filter([dom_class(\$project, 'edit_prefix'), array_get(\$options, 'class')]) |
| 133 | + ); |
| 134 | + \$options['id'] = dom_id(\$project, 'edit_prefix'); |
| 135 | + echo '<'.'div'.app('html')->attributes(\$options).'>'; |
| 136 | +?>text |
| 137 | +<?php |
| 138 | + echo '</'.'div'.'>'; |
| 139 | +
|
| 140 | + }); |
| 141 | +?> |
| 142 | +EOT; |
| 143 | + $view = Blade::compileString($contentTagFor); |
| 144 | + $this->assertEquals($expect, $view); |
| 145 | + } |
| 146 | + |
| 147 | + |
| 148 | + public function testDivTag() |
| 149 | + { |
| 150 | + $divTag = <<<EOT |
| 151 | +@div_tag |
| 152 | +text |
| 153 | +@enddiv_tag |
| 154 | +
|
| 155 | +EOT; |
| 156 | + $expect = <<<EOT |
| 157 | +<?php echo '<'."div".app('html')->attributes([]).'>'; |
| 158 | + ?>text |
| 159 | +<?php echo '</'."div".'>'; |
| 160 | + ?> |
| 161 | +EOT; |
| 162 | + $view = Blade::compileString($divTag); |
| 163 | + $this->assertEquals($expect, $view); |
| 164 | + |
| 165 | + $expect2 = <<<EOT |
| 166 | +<?php echo '<'."div".app('html')->attributes([]).'>'; ?>text2 <?php echo '</'."div".'>'; |
| 167 | + ?> |
| 168 | +EOT; |
| 169 | + $this->assertNotEquals($expect2, $view); |
| 170 | + |
| 171 | + $divTag2 = <<<EOT |
| 172 | +@div_tag text2 @end_div_tag |
| 173 | +
|
| 174 | +EOT; |
| 175 | + $view2 = Blade::compileString($divTag2); |
| 176 | + $this->assertEquals($expect2, $view2); |
| 177 | + } |
| 178 | + |
| 179 | + public function testDivTagWithAttributes() |
| 180 | + { |
| 181 | + $divTag = <<<EOT |
| 182 | +@div_tag(['class' => 'div-tag-class']) |
| 183 | +text |
| 184 | +@enddiv_tag |
| 185 | +
|
| 186 | +EOT; |
| 187 | + $expect = <<<EOT |
| 188 | +<?php echo '<'."div".app('html')->attributes(['class' => 'div-tag-class']).'>'; |
| 189 | + ?>text |
| 190 | +<?php echo '</'."div".'>'; |
| 191 | + ?> |
| 192 | +EOT; |
| 193 | + $view = Blade::compileString($divTag); |
| 194 | + $this->assertEquals($expect, $view); |
| 195 | + |
| 196 | + $expect2 = <<<EOT |
| 197 | +<?php echo '<'."div".app('html')->attributes(['id' => 'div_tag_id']).'>'; ?>text2 <?php echo '</'."div".'>'; |
| 198 | + ?> |
| 199 | +EOT; |
| 200 | + $this->assertNotEquals($expect2, $view); |
| 201 | + |
| 202 | + $divTag2 = <<<EOT |
| 203 | +@div_tag(['id' => 'div_tag_id']) text2 @end_div_tag |
| 204 | +
|
| 205 | +EOT; |
| 206 | + $view2 = Blade::compileString($divTag2); |
| 207 | + $this->assertEquals($expect2, $view2); |
| 208 | + } |
| 209 | +} |
0 commit comments