ViewsBulkEditActionTest.php in Views Bulk Edit 8.2
File
tests/src/Kernel/ViewsBulkEditActionTest.php
View source
<?php
namespace Drupal\Tests\views_bulk_edit\Kernel;
use Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase;
use Drupal\node\NodeInterface;
class ViewsBulkEditActionTest extends ViewsBulkOperationsKernelTestBase {
public static $modules = [
'views_bulk_edit',
];
public function setUp() {
parent::setUp();
$this
->createTestNodes([
'page' => [
'count' => 10,
],
]);
}
public function testModifyEntityValues() {
$vbo_data = [
'view_id' => 'views_bulk_operations_test',
'action_id' => 'views_bulk_edit',
'configuration' => [
'node' => [
'page' => [
'values' => [
'status' => [
[
'value' => 0,
],
],
],
'change_method' => [
'status' => 'replace',
],
],
],
],
];
$selection = [
0,
3,
6,
8,
];
$vbo_data['list'] = $this
->getResultsList($vbo_data, $selection);
$results = $this
->executeAction($vbo_data);
$nodeStorage = $this->container
->get('entity_type.manager')
->getStorage('node');
$statuses = [];
foreach ($this->testNodesData as $id => $lang_data) {
$node = $nodeStorage
->load($id);
$status = intval($node->status->value);
foreach ($vbo_data['list'] as $item) {
if ($item[3] == $id) {
$this
->assertEquals(NodeInterface::NOT_PUBLISHED, $status);
break 2;
}
}
$this
->assertEquals(NodeInterface::PUBLISHED, $status);
}
}
}