Skip to content

Commit 8f5179e

Browse files
authored
Merge pull request #4821 from Laravel-Backpack/add-even-more-tests-and-fix-color
Add more tests, attempt to fix coverage color
2 parents ffbadcd + 2ff7952 commit 8f5179e

File tree

10 files changed

+270
-4
lines changed

10 files changed

+270
-4
lines changed

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ jobs:
5050
status: ${{ steps.test-coverage.outputs.coverage-rounded-display }}
5151
path: ./test-coverage.svg
5252
color: ${{ steps.test-coverage.outputs.coverage > 90 && 'green' ||
53-
steps.test-coverage.outputs.coverage > 80 && 'yellow,green' ||
54-
steps.test-coverage.outputs.coverage > 70 && 'yellow' ||
55-
steps.test-coverage.outputs.coverage > 60 && 'orange,yellow' ||
53+
steps.test-coverage.outputs.coverage > 80 && 'yellow,green, green' ||
54+
steps.test-coverage.outputs.coverage > 70 && 'yellow, green' ||
55+
steps.test-coverage.outputs.coverage > 60 && 'yellow,yellow, green' ||
5656
steps.test-coverage.outputs.coverage > 50 && 'orange' ||
5757
steps.test-coverage.outputs.coverage > 40 && 'red,orange' ||
5858
steps.test-coverage.outputs.coverage > 30 && 'red,red,orange' ||

src/app/Library/CrudPanel/CrudButton.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ public function crud()
405405
* Dump the current object to the screen,
406406
* so that the developer can see its contents.
407407
*
408+
* @codeCoverageIgnore
409+
*
408410
* @return CrudButton
409411
*/
410412
public function dump()
@@ -419,6 +421,8 @@ public function dump()
419421
* so that the developer can see its contents, then stops
420422
* the execution.
421423
*
424+
* @codeCoverageIgnore
425+
*
422426
* @return CrudButton
423427
*/
424428
public function dd()

src/app/Library/CrudPanel/CrudColumn.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public function key(string $key)
8080
}
8181

8282
$columns = $this->crud()->columns();
83+
8384
$searchKey = $this->attributes['key'];
8485
$column = $this->attributes;
8586

8687
if (isset($columns[$searchKey])) {
8788
unset($columns[$searchKey]);
8889
$column['key'] = $key;
8990
}
90-
9191
$this->attributes = $column;
9292
$this->setOperationSetting('columns', array_merge($columns, [$key => $column]));
9393

@@ -179,6 +179,8 @@ public function makeLast()
179179
* Dump the current object to the screen,
180180
* so that the developer can see its contents.
181181
*
182+
* @codeCoverageIgnore
183+
*
182184
* @return CrudColumn
183185
*/
184186
public function dump()
@@ -193,6 +195,8 @@ public function dump()
193195
* so that the developer can see its contents, then stops
194196
* the execution.
195197
*
198+
* @codeCoverageIgnore
199+
*
196200
* @return CrudColumn
197201
*/
198202
public function dd()

src/app/Library/CrudPanel/CrudField.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ private function save()
386386
* Dump the current object to the screen,
387387
* so that the developer can see its contents.
388388
*
389+
* @codeCoverageIgnore
390+
*
389391
* @return CrudField
390392
*/
391393
public function dump()
@@ -400,6 +402,8 @@ public function dump()
400402
* so that the developer can see its contents, then stops
401403
* the execution.
402404
*
405+
* @codeCoverageIgnore
406+
*
403407
* @return CrudField
404408
*/
405409
public function dd()

src/app/Library/CrudPanel/CrudFilter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ private function applyDefaultLogic($name, $operator, $input = null)
551551
* Dump the current object to the screen,
552552
* so that the developer can see its contents.
553553
*
554+
* @codeCoverageIgnore
555+
*
554556
* @return CrudFilter
555557
*/
556558
public function dump()
@@ -565,6 +567,8 @@ public function dump()
565567
* so that the developer can see its contents, then stops
566568
* the execution.
567569
*
570+
* @codeCoverageIgnore
571+
*
568572
* @return CrudFilter
569573
*/
570574
public function dd()

src/app/Library/CrudPanel/CrudPanelFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* service container as 'crud'.
1111
*/
1212
/**
13+
* @codeCoverageIgnore
1314
* Class CrudPanelFacade.
1415
*
1516
* @method static setModel($model)

tests/Unit/CrudPanel/CrudPanelButtonsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
/**
88
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Buttons
9+
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudButton
910
*/
1011
class CrudPanelButtonsTest extends BaseCrudPanelTest
1112
{
1213
private $defaultButtonNames = [];
1314

1415
private $topViewButton;
16+
1517
private $lineViewButton;
18+
1619
private $bottomViewButton;
20+
1721
private $topModelFunctionButton;
1822

1923
protected function setUp(): void

tests/Unit/CrudPanel/CrudPanelColumnsTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
44

5+
use Backpack\CRUD\app\Library\CrudPanel\CrudColumn;
56
use Backpack\CRUD\Tests\Unit\Models\User;
67

78
/**
89
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Columns
910
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\ColumnsProtectedMethods
11+
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudColumn
1012
*/
1113
class CrudPanelColumnsTest extends BaseDBCrudPanelTest
1214
{
@@ -532,4 +534,79 @@ public function testOrderColumnsMixedList()
532534

533535
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns()));
534536
}
537+
538+
public function testItCanAddAFluentColumn()
539+
{
540+
$this->crudPanel->setModel(User::class);
541+
542+
$this->crudPanel->column('my_column')->label('my_column');
543+
544+
$this->assertCount(1, $this->crudPanel->columns());
545+
546+
$this->assertEquals([
547+
'name' => 'my_column',
548+
'type' => 'text',
549+
'label' => 'my_column',
550+
'key' => 'my_column',
551+
'priority' => 0,
552+
'tableColumn' => false,
553+
'orderable' => false,
554+
'searchLogic' => false,
555+
], $this->crudPanel->columns()['my_column']);
556+
}
557+
558+
public function testItCanMakeAColumnFirstFluently()
559+
{
560+
$this->crudPanel->column('test1');
561+
$this->crudPanel->column('test2')->makeFirst();
562+
$crudColumns = $this->crudPanel->columns();
563+
$firstColumn = reset($crudColumns);
564+
$this->assertEquals($firstColumn['name'], 'test2');
565+
}
566+
567+
public function testItCanMakeAColumnLastFluently()
568+
{
569+
$this->crudPanel->column('test1');
570+
$this->crudPanel->column('test2');
571+
$this->crudPanel->column('test1')->makeLast();
572+
$crudColumns = $this->crudPanel->columns();
573+
$firstColumn = reset($crudColumns);
574+
$this->assertEquals($firstColumn['name'], 'test2');
575+
}
576+
577+
public function testItCanPlaceColumnsFluently()
578+
{
579+
$this->crudPanel->column('test1');
580+
$this->crudPanel->column('test2');
581+
$this->crudPanel->column('test3')->after('test1');
582+
583+
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name');
584+
$this->assertEquals($crudColumnsNames, ['test1', 'test3', 'test2']);
585+
586+
$this->crudPanel->column('test4')->before('test1');
587+
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name');
588+
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test3', 'test2']);
589+
}
590+
591+
public function testItCanRemoveColumnAttributesFluently()
592+
{
593+
$this->crudPanel->column('test1')->type('test');
594+
$this->assertEquals($this->crudPanel->columns()['test1']['type'], 'test');
595+
$this->crudPanel->column('test1')->forget('type');
596+
$this->assertNull($this->crudPanel->columns()['test1']['type'] ?? null);
597+
}
598+
599+
public function testItCanRemoveColumnFluently()
600+
{
601+
$this->crudPanel->column('test1')->type('test');
602+
$this->assertCount(1, $this->crudPanel->columns());
603+
$this->crudPanel->column('test1')->remove();
604+
$this->assertCount(0, $this->crudPanel->columns());
605+
}
606+
607+
public function testItCanAddAColumnToCrudFromClass()
608+
{
609+
CrudColumn::name('test');
610+
$this->assertCount(1, $this->crudPanel->columns());
611+
}
535612
}

0 commit comments

Comments
 (0)