-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from FriendsOfCake/issue-310
Don't override user provided "data-url".
- Loading branch information
Showing
3 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace CrudView\Test\Fixture; | ||
|
||
use Cake\TestSuite\Fixture\TestFixture; | ||
|
||
class BlogsFixture extends TestFixture | ||
{ | ||
public $fields = [ | ||
'id' => ['type' => 'integer'], | ||
'is_active' => ['type' => 'boolean', 'default' => true, 'null' => false], | ||
'name' => ['type' => 'string', 'length' => 255, 'null' => false], | ||
'body' => ['type' => 'text', 'null' => false], | ||
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], | ||
]; | ||
|
||
public $records = [ | ||
['name' => '1st post', 'body' => '1st post body'], | ||
['name' => '2nd post', 'body' => '2nd post body'], | ||
['name' => '3rd post', 'body' => '3rd post body'], | ||
['name' => '4th post', 'body' => '4th post body'], | ||
['name' => '5th post', 'body' => '5th post body'], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace CrudView\Test\TestCase\Listener; | ||
|
||
use Cake\Controller\Controller; | ||
use Cake\Http\ServerRequest; | ||
use Cake\Routing\Route\DashedRoute; | ||
use Cake\Routing\Router; | ||
use Cake\TestSuite\TestCase; | ||
use CrudView\Listener\ViewSearchListener; | ||
|
||
/** | ||
* Test case for ViewSearchListener. | ||
*/ | ||
class ViewSearchListenerTest extends TestCase | ||
{ | ||
protected $fixtures = ['plugin.CrudView.Blogs']; | ||
|
||
/** | ||
* @var \Cake\Controller\Controller; | ||
*/ | ||
protected $controller; | ||
|
||
/** | ||
* @var \CrudView\Listener\ViewSearchListener | ||
*/ | ||
protected $listener; | ||
|
||
public function setUp(): void | ||
{ | ||
$routesBuilder = Router::createRouteBuilder('/'); | ||
$routesBuilder->setRouteClass(DashedRoute::class); | ||
$routesBuilder->connect('/{controller}/{action}/*', []) | ||
->setExtensions(['json']); | ||
|
||
$request = new ServerRequest([ | ||
'url' => '/blogs/index', | ||
'params' => ['controller' => 'Blogs', 'action' => 'index', 'plugin' => null, '_ext' => null], | ||
]); | ||
|
||
$this->controller = new Controller($request, null, 'Blogs'); | ||
|
||
$this->listener = new ViewSearchListener($this->controller); | ||
|
||
Router::setRequest($request); | ||
} | ||
|
||
public function testFields() | ||
{ | ||
$this->listener->setConfig(['fields' => ['category_id']]); | ||
|
||
$fields = $this->listener->fields(); | ||
$expected = [ | ||
'category_id' => [ | ||
'required' => false, | ||
'type' => 'select', | ||
'value' => null, | ||
'class' => 'autocomplete', | ||
'data-url' => '/blogs/lookup.json?id=category_id&value=category_id', | ||
], | ||
]; | ||
$this->assertEquals($expected, $fields); | ||
|
||
$this->listener->setConfig([ | ||
'fields' => ['category_id' => ['data-url' => '/custom']], | ||
], null, true); | ||
|
||
$fields = $this->listener->fields(); | ||
$expected['category_id']['data-url'] = '/custom'; | ||
$this->assertEquals($expected, $fields); | ||
} | ||
} |