|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Yajra\DataTables\Html\Tests; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\Test; |
| 6 | +use Yajra\DataTables\Html\Builder; |
| 7 | +use Yajra\DataTables\Html\Layout; |
| 8 | + |
| 9 | +class LayoutTest extends TestCase |
| 10 | +{ |
| 11 | + #[Test] |
| 12 | + public function it_can_set_positions(): void |
| 13 | + { |
| 14 | + $layout = new Layout; |
| 15 | + $layout->top('test'); |
| 16 | + $this->assertEquals('test', $layout->get('top')); |
| 17 | + |
| 18 | + $layout->bottom('test'); |
| 19 | + $this->assertEquals('test', $layout->get('bottom')); |
| 20 | + |
| 21 | + $layout->topStart('test'); |
| 22 | + $this->assertEquals('test', $layout->get('topStart')); |
| 23 | + |
| 24 | + $layout->topEnd('test'); |
| 25 | + $this->assertEquals('test', $layout->get('topEnd')); |
| 26 | + |
| 27 | + $layout->bottomStart('test'); |
| 28 | + $this->assertEquals('test', $layout->get('bottomStart')); |
| 29 | + |
| 30 | + $layout->bottomEnd('test'); |
| 31 | + $this->assertEquals('test', $layout->get('bottomEnd')); |
| 32 | + |
| 33 | + $layout->top('test', 1); |
| 34 | + $this->assertEquals('test', $layout->get('top1')); |
| 35 | + |
| 36 | + $layout->bottom('test', 1); |
| 37 | + $this->assertEquals('test', $layout->get('bottom1')); |
| 38 | + |
| 39 | + $layout->top('test', 1, 'Start'); |
| 40 | + $this->assertEquals('test', $layout->get('top1Start')); |
| 41 | + |
| 42 | + $layout->bottom('test', 1, 'Start'); |
| 43 | + $this->assertEquals('test', $layout->get('bottom1Start')); |
| 44 | + |
| 45 | + $layout->top('test', 1, 'End'); |
| 46 | + $this->assertEquals('test', $layout->get('top1End')); |
| 47 | + |
| 48 | + $layout->bottom('test', 1, 'End'); |
| 49 | + $this->assertEquals('test', $layout->get('bottom1End')); |
| 50 | + } |
| 51 | + |
| 52 | + #[Test] |
| 53 | + public function it_can_be_used_in_builder(): void |
| 54 | + { |
| 55 | + $builder = resolve(Builder::class); |
| 56 | + $builder->layout(function (Layout $layout) { |
| 57 | + $layout->top('test'); |
| 58 | + $layout->bottom('test'); |
| 59 | + $layout->topStart('test'); |
| 60 | + $layout->topEnd('test'); |
| 61 | + $layout->bottomStart('test'); |
| 62 | + $layout->bottomEnd('test'); |
| 63 | + $layout->top('test', 1); |
| 64 | + $layout->bottom('test', 1); |
| 65 | + $layout->top('test', 1, 'Start'); |
| 66 | + $layout->bottom('test', 1, 'Start'); |
| 67 | + $layout->top('test', 1, 'End'); |
| 68 | + $layout->bottom('test', 1, 'End'); |
| 69 | + }); |
| 70 | + |
| 71 | + $this->assertArrayHasKey('layout', $builder->getAttributes()); |
| 72 | + $this->assertArrayHasKey('top', $builder->getAttributes()['layout']); |
| 73 | + $this->assertArrayHasKey('bottom', $builder->getAttributes()['layout']); |
| 74 | + $this->assertArrayHasKey('topStart', $builder->getAttributes()['layout']); |
| 75 | + $this->assertArrayHasKey('topEnd', $builder->getAttributes()['layout']); |
| 76 | + $this->assertArrayHasKey('bottomStart', $builder->getAttributes()['layout']); |
| 77 | + $this->assertArrayHasKey('bottomEnd', $builder->getAttributes()['layout']); |
| 78 | + $this->assertArrayHasKey('top1', $builder->getAttributes()['layout']); |
| 79 | + $this->assertArrayHasKey('bottom1', $builder->getAttributes()['layout']); |
| 80 | + $this->assertArrayHasKey('top1Start', $builder->getAttributes()['layout']); |
| 81 | + $this->assertArrayHasKey('bottom1Start', $builder->getAttributes()['layout']); |
| 82 | + $this->assertArrayHasKey('top1End', $builder->getAttributes()['layout']); |
| 83 | + $this->assertArrayHasKey('bottom1End', $builder->getAttributes()['layout']); |
| 84 | + } |
| 85 | + |
| 86 | + #[Test] |
| 87 | + public function it_has_factory_method(): void |
| 88 | + { |
| 89 | + $layout = Layout::make(); |
| 90 | + $this->assertInstanceOf(Layout::class, $layout); |
| 91 | + |
| 92 | + $builder = resolve(Builder::class); |
| 93 | + $builder->layout(Layout::make()); |
| 94 | + |
| 95 | + $this->assertArrayHasKey('layout', $builder->getAttributes()); |
| 96 | + } |
| 97 | + |
| 98 | + #[Test] |
| 99 | + public function it_can_be_macroable(): void |
| 100 | + { |
| 101 | + Layout::macro('test', fn () => 'test'); |
| 102 | + |
| 103 | + $layout = new Layout; |
| 104 | + $this->assertEquals('test', $layout->test()); |
| 105 | + } |
| 106 | + |
| 107 | + #[Test] |
| 108 | + public function it_can_accept_array(): void |
| 109 | + { |
| 110 | + $layout = new Layout(['top' => 'test']); |
| 111 | + $this->assertEquals('test', $layout->get('top')); |
| 112 | + } |
| 113 | + |
| 114 | + #[Test] |
| 115 | + public function it_can_accept_array_as_parameter(): void |
| 116 | + { |
| 117 | + $layout = Layout::make(['top' => 'test']); |
| 118 | + $this->assertEquals('test', $layout->get('top')); |
| 119 | + } |
| 120 | + |
| 121 | + #[Test] |
| 122 | + public function it_can_accept_array_as_parameter_in_builder(): void |
| 123 | + { |
| 124 | + $builder = resolve(Builder::class); |
| 125 | + $builder->layout(['top' => 'test']); |
| 126 | + |
| 127 | + $this->assertArrayHasKey('layout', $builder->getAttributes()); |
| 128 | + $this->assertArrayHasKey('top', $builder->getAttributes()['layout']); |
| 129 | + } |
| 130 | +} |
0 commit comments