View source
<?php
namespace Drupal\Tests\views_bulk_operations\Kernel;
class ViewsBulkOperationsActionProcessorTest extends ViewsBulkOperationsKernelTestBase {
public function setUp() {
parent::setUp();
$this
->createTestNodes([
'page' => [
'count' => 20,
],
]);
}
protected function assertNodeStatuses(array $list, $exclude = FALSE) {
$nodeStorage = $this->container
->get('entity_type.manager')
->getStorage('node');
$statuses = [];
foreach ($this->testNodesData as $id => $lang_data) {
$node = $nodeStorage
->load($id);
$statuses[$id] = $node
->isPublished();
$node
->setPublished();
$node
->save();
}
foreach ($statuses as $id => $status) {
$asserted = FALSE;
foreach ($list as $item) {
if ($item[3] == $id) {
$this
->assertEquals((bool) $exclude, $status);
$asserted = TRUE;
break;
}
}
if (!$asserted) {
$this
->assertEquals(!(bool) $exclude, $status);
}
}
}
public function testViewsbulkOperationsActionProcessor() {
$vbo_data = [
'view_id' => 'views_bulk_operations_test',
'action_id' => 'views_bulk_operations_simple_test_action',
'configuration' => [
'preconfig' => 'test',
],
];
$results = $this
->executeAction($vbo_data);
$this
->assertEquals('Processed 10 of 20 entities.', $results['messages'][0]);
$this
->assertEquals('Processed 20 of 20 entities.', $results['messages'][1]);
$this
->assertEquals(20, $results['operations']['Test']);
$vbo_data = [
'view_id' => 'views_bulk_operations_test',
'action_id' => 'views_bulk_operations_advanced_test_action',
'preconfiguration' => [
'test_preconfig' => 'test',
'test_config' => 'unpublish',
],
];
$selection = [
0,
3,
6,
8,
15,
16,
18,
];
$vbo_data['list'] = $this
->getResultsList($vbo_data, $selection);
$results = $this
->executeAction($vbo_data);
$this
->assertNodeStatuses($vbo_data['list']);
}
public function testViewsbulkOperationsActionProcessorExclude() {
$vbo_data = [
'view_id' => 'views_bulk_operations_test',
'action_id' => 'views_bulk_operations_advanced_test_action',
'exclude_mode' => TRUE,
'preconfiguration' => [
'test_preconfig' => 'test',
'test_config' => 'unpublish',
],
];
$selection = [
1,
2,
4,
18,
];
$vbo_data['list'] = $this
->getResultsList($vbo_data, $selection);
$results = $this
->executeAction($vbo_data);
$this
->assertNodeStatuses($vbo_data['list'], $vbo_data['exclude_mode']);
}
}