Skip to content

Commit

Permalink
Merge pull request #601 from raul338/missing-traits
Browse files Browse the repository at this point in the history
Add SerializeTrait to View and Edit Actions
  • Loading branch information
ADmad committed Sep 29, 2018
2 parents 2d21b63 + 5a8f1a9 commit 8129e24
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Action/EditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Crud\Traits\FindMethodTrait;
use Crud\Traits\RedirectTrait;
use Crud\Traits\SaveMethodTrait;
use Crud\Traits\SerializeTrait;
use Crud\Traits\ViewTrait;
use Crud\Traits\ViewVarTrait;

Expand All @@ -21,6 +22,7 @@ class EditAction extends BaseAction
use FindMethodTrait;
use RedirectTrait;
use SaveMethodTrait;
use SerializeTrait;
use ViewTrait;
use ViewVarTrait;

Expand Down
2 changes: 2 additions & 0 deletions src/Action/ViewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Crud\Action;

use Crud\Traits\FindMethodTrait;
use Crud\Traits\SerializeTrait;
use Crud\Traits\ViewTrait;
use Crud\Traits\ViewVarTrait;

Expand All @@ -15,6 +16,7 @@ class ViewAction extends BaseAction
{

use FindMethodTrait;
use SerializeTrait;
use ViewTrait;
use ViewVarTrait;

Expand Down
76 changes: 76 additions & 0 deletions tests/TestCase/Listener/ApiListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,82 @@ public function testEnsureSerializeWithViewVar()
$this->callProtectedMethod('_ensureSerialize', [], $listener);
}

/**
* Data provider for testExpandPath
*
* @return array
*/
public function dataSerializeTraitActions()
{
return [
'View Action' => ['\Crud\Action\ViewAction'],
'Index Action' => ['\Crud\Action\IndexAction'],
'Edit Action' => ['\Crud\Action\EditAction'],
'Add Action' => ['\Crud\Action\AddAction'],
];
}

/**
* Test SerializeTrait
*
* @dataProvider dataSerializeTraitActions
* @return void
*/
public function testEnsureSerializeWithSerializeTrait($action)
{
$listener = $this
->getMockBuilder('\Crud\Listener\ApiListener')
->setMethods(['_action', '_controller'])
->disableOriginalConstructor()
->getMock();

$action = $this
->getMockBuilder($action)
->setMethods(['setConfig', 'getConfig', 'viewVar'])
->disableOriginalConstructor()
->getMock();

$controller = $this
->getMockBuilder('\Cake\Controller\Controller')
->setMethods(['set'])
->disableOriginalConstructor()
->getMock();

$i = 0;
$listener
->expects($this->at($i++))
->method('_controller')
->will($this->returnValue($controller));
$listener
->expects($this->at($i++))
->method('_action')
->will($this->returnValue($action));
$i = 0;
$action
->expects($this->at($i++))
->method('setConfig')
->with('serialize', ['something']);
$action
->expects($this->at($i++))
->method('viewVar')
->will($this->returnValue(null));
$action
->expects($this->once())
->method('getConfig')
->with('serialize')
->will($this->returnValue(['something']));
$controller
->expects($this->once())
->method('set')
->with('_serialize', ['success', 'something', 'data' => null]);

$this->setReflectionClassInstance($action);
$this->callProtectedMethod('serialize', [['something']], $action);

$this->setReflectionClassInstance($listener);
$this->callProtectedMethod('_ensureSerialize', [], $listener);
}

/**
* testEnsureSerializeAlreadySet
*
Expand Down

0 comments on commit 8129e24

Please sign in to comment.