-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ae28d1
commit ae64cba
Showing
2 changed files
with
139 additions
and
0 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,134 @@ | ||
<?php | ||
namespace Crud\Test\TestCase\Action\Bulk; | ||
|
||
use Cake\Routing\DispatcherFactory; | ||
use Cake\Routing\Router; | ||
use Crud\TestSuite\IntegrationTestCase; | ||
|
||
/** | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
*/ | ||
class SetValueActionTest extends IntegrationTestCase | ||
{ | ||
|
||
/** | ||
* fixtures property | ||
* | ||
* @var array | ||
*/ | ||
public $fixtures = ['plugin.crud.blogs']; | ||
|
||
/** | ||
* Table class to mock on | ||
* | ||
* @var string | ||
*/ | ||
public $tableClass = 'Crud\Test\App\Model\Table\BlogsTable'; | ||
|
||
/** | ||
* Data provider with all HTTP verbs | ||
* | ||
* @return array | ||
*/ | ||
public function allHttpMethodProvider() | ||
{ | ||
return [ | ||
['post'], | ||
['put'], | ||
]; | ||
} | ||
|
||
/** | ||
* Test the normal HTTP flow for all HTTP verbs | ||
* | ||
* @dataProvider allHttpMethodProvider | ||
* @return void | ||
*/ | ||
public function testAllRequestMethods($method) | ||
{ | ||
$this->_eventManager->attach( | ||
function ($event) { | ||
$this->_controller->Flash = $this->getMock( | ||
'Cake\Controller\Component\Flash', | ||
['set'] | ||
); | ||
|
||
$this->_controller->Flash | ||
->expects($this->once()) | ||
->method('set') | ||
->with( | ||
'Set value successfully', | ||
[ | ||
'element' => 'default', | ||
'params' => ['class' => 'message success', 'original' => 'Set value successfully'], | ||
'key' => 'flash' | ||
] | ||
); | ||
|
||
$this->_subscribeToEvents($this->_controller); | ||
}, | ||
'Dispatcher.beforeDispatch', | ||
['priority' => 1000] | ||
); | ||
|
||
$this->{$method}('/blogs/activateAll', [ | ||
'id' => [ | ||
1 => 1, | ||
2 => 2, | ||
], | ||
]); | ||
|
||
$this->assertEvents(['beforeBulk', 'afterBulk', 'setFlash', 'beforeRedirect']); | ||
$this->assertTrue($this->_subject->success); | ||
$this->assertRedirect('/blogs'); | ||
} | ||
|
||
/** | ||
* Test the flow when the beforeDelete event is stopped | ||
* | ||
* @return void | ||
*/ | ||
public function testStopDelete() | ||
{ | ||
$this->_eventManager->attach( | ||
function ($event) { | ||
$this->_controller->Flash = $this->getMock( | ||
'Cake\Controller\Component\Flash', | ||
['set'] | ||
); | ||
|
||
$this->_controller->Flash | ||
->expects($this->once()) | ||
->method('set') | ||
->with( | ||
'Could not set value', | ||
[ | ||
'element' => 'default', | ||
'params' => ['class' => 'message error', 'original' => 'Could not set value'], | ||
'key' => 'flash' | ||
] | ||
); | ||
|
||
$this->_subscribeToEvents($this->_controller); | ||
|
||
$this->_controller->Crud->on('beforeBulk', function ($event) { | ||
$event->stopPropagation(); | ||
}); | ||
}, | ||
'Dispatcher.beforeDispatch', | ||
['priority' => 1000] | ||
); | ||
|
||
$this->post('/blogs/activateAll', [ | ||
'id' => [ | ||
1 => 1, | ||
2 => 2, | ||
], | ||
]); | ||
|
||
$this->assertEvents(['beforeBulk', 'setFlash', 'beforeRedirect']); | ||
$this->assertFalse($this->_subject->success); | ||
$this->assertRedirect('/blogs'); | ||
} | ||
} |