Skip to content

Commit 68b067d

Browse files
authored
Merge pull request #4824 from Laravel-Backpack/we-need-more-tests
more tests
2 parents 8f7686f + ee9dd54 commit 68b067d

19 files changed

+425
-138
lines changed

phpunit.xml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<directory suffix=".php">./src/app/Models/Traits/</directory>
2424
<file>./src/app/Library/Widget.php</file>
2525
<file>./src/app/Http/Controllers/CrudController.php</file>
26+
<file>./src/ViewNamespaces.php</file>
2627
<exclude>
2728
<directory suffix=".php">./src/app/Models/Traits/SpatieTranslatable/</directory>
2829
</exclude>

src/BackpackServiceProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public function publishFiles()
163163
*/
164164
public function setupRoutes(Router $router)
165165
{
166+
if (app()->runningUnitTests()) {
167+
$this->loadRoutesFrom(__DIR__.'/routes/backpack/testing.php');
168+
169+
return;
170+
}
166171
// by default, use the routes file provided in vendor
167172
$routeFilePathInUse = __DIR__.$this->routeFilePath;
168173

src/app/Http/Controllers/CrudController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct()
3333
// It's done inside a middleware closure in order to have
3434
// the complete request inside the CrudPanel object.
3535
$this->middleware(function ($request, $next) {
36-
$this->crud = app()->make('crud');
36+
$this->crud = app('crud');
3737

3838
$this->crud->setRequest($request);
3939

@@ -96,6 +96,7 @@ protected function setupDefaults()
9696
protected function setupConfigurationForCurrentOperation()
9797
{
9898
$operationName = $this->crud->getCurrentOperation();
99+
99100
$setupClassName = 'setup'.Str::studly($operationName).'Operation';
100101

101102
/*

src/app/Library/CrudPanel/CrudFilter.php

+29-15
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@
1111
class CrudFilter
1212
{
1313
public $name; // the name of the filtered variable (db column name)
14+
1415
public $type = 'select2'; // the name of the filter view that will be loaded
16+
1517
public $key; //camelCased version of filter name to use in internal ids, js functions and css classes.
18+
1619
public $label;
20+
1721
public $placeholder;
22+
1823
public $values;
24+
1925
public $options;
26+
2027
public $logic;
28+
2129
public $fallbackLogic;
30+
2231
public $currentValue;
32+
2333
public $view;
34+
2435
public $viewNamespace = 'crud::filters';
36+
2537
public $applied = false;
2638

2739
public function __construct($options, $values, $logic, $fallbackLogic)
@@ -210,6 +222,8 @@ public function forget($attribute)
210222
* @param string $field The name of the field.
211223
* @param string $attribute The name of the attribute being removed.
212224
*
225+
* @codeCoverageIgnore
226+
*
213227
* @deprecated
214228
*/
215229
public function removeFilterAttribute($filter, $attribute)
@@ -511,21 +525,21 @@ private function applyDefaultLogic($name, $operator, $input = null)
511525
$this->crud()->addClause($operator);
512526
break;
513527

514-
// TODO:
515-
// whereBetween
516-
// whereNotBetween
517-
// whereIn
518-
// whereNotIn
519-
// whereNull
520-
// whereNotNull
521-
// whereDate
522-
// whereMonth
523-
// whereDay
524-
// whereYear
525-
// whereColumn
526-
// like
527-
528-
// sql comparison operators
528+
// TODO:
529+
// whereBetween
530+
// whereNotBetween
531+
// whereIn
532+
// whereNotIn
533+
// whereNull
534+
// whereNotNull
535+
// whereDate
536+
// whereMonth
537+
// whereDay
538+
// whereYear
539+
// whereColumn
540+
// like
541+
542+
// sql comparison operators
529543
case '=':
530544
case '<=>':
531545
case '<>':

src/app/Library/CrudPanel/CrudPanel.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ private function getSchema()
148148
* DEPRECATION NOTICE: This method is no longer used and will be removed in future versions of Backpack
149149
*
150150
* @deprecated
151+
* @codeCoverageIgnore
151152
*
152153
* @return bool
153154
*/
@@ -307,16 +308,18 @@ public function getFirstOfItsTypeInArray($type, $array)
307308
});
308309
}
309310

310-
// ------------
311-
// TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE
312-
// ------------
313-
//
314-
// TODO:
315-
// - figure out if they are really needed
316-
// - comments inside the function to explain how they work
317-
// - write docblock for them
318-
// - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION)
319-
311+
/**
312+
* TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE.
313+
*
314+
* TODO:
315+
* - figure out if they are really needed
316+
* - comments inside the function to explain how they work
317+
* - write docblock for them
318+
* - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION)
319+
*
320+
* @deprecated
321+
* @codeCoverageIgnore
322+
*/
320323
public function sync($type, $fields, $attributes)
321324
{
322325
if (! empty($this->{$type})) {

src/app/Library/CrudPanel/Traits/HasViewNamespaces.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Backpack\CRUD\ViewNamespaces;
66

7+
/**
8+
* @codeCoverageIgnore
9+
*/
710
trait HasViewNamespaces
811
{
912
/**

src/app/Library/CrudPanel/Traits/SaveActions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function orderSaveActions(array $saveActions)
212212
/**
213213
* Return the ordered save actions to use in the crud panel.
214214
*
215-
* @return void
215+
* @return array
216216
*/
217217
public function getOrderedSaveActions()
218218
{
@@ -228,7 +228,7 @@ public function getOrderedSaveActions()
228228
/**
229229
* Returns the save actions that passed the visible callback.
230230
*
231-
* @return void
231+
* @return array
232232
*/
233233
public function getVisibleSaveActions()
234234
{

src/routes/backpack/testing.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Backpack Testing Routes
8+
|--------------------------------------------------------------------------
9+
| This routes are loaded only when running unit tests.
10+
|
11+
*/
12+
13+
Route::group([
14+
(array) config('backpack.base.web_middleware', 'web'),
15+
(array) config('backpack.base.middleware_key', 'admin'),
16+
'prefix' => config('backpack.base.route_prefix', 'admin'),
17+
],
18+
function () {
19+
Route::crud('users', 'Backpack\CRUD\Tests\Unit\Http\Controllers\UserCrudController');
20+
}
21+
);

0 commit comments

Comments
 (0)