You are here

class CsvExportTest in VBO export 8.3

@coversDefaultClass \Drupal\vbo_export\Plugin\Action\VboExportBase @group vbo_export

Hierarchy

  • class \Drupal\Tests\vbo_export\Kernel\CsvExportTest extends \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase

Expanded class hierarchy of CsvExportTest

File

tests/src/Kernel/CsvExportTest.php, line 12

Namespace

Drupal\Tests\vbo_export\Kernel
View source
class CsvExportTest extends ViewsBulkOperationsKernelTestBase {
  private const SEPARATOR = ',';

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'file',
    'vbo_export',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this
      ->installEntitySchema('file');
    $this
      ->createTestNodes([
      'page' => [
        'count' => 5,
      ],
    ]);
  }

  /**
   * Tests the bulk edit action.
   *
   * @covers ::getViewBundles
   * @covers ::execute
   */
  public function testCsvExport() {
    $vbo_data = [
      'view_id' => 'views_bulk_operations_test',
      'action_id' => 'vbo_export_generate_csv_action',
      'configuration' => [
        'separator' => self::SEPARATOR,
        'field_override' => FALSE,
        'strip_tags' => TRUE,
      ],
    ];
    $selection = [
      0,
      1,
      2,
      3,
    ];
    $vbo_data['list'] = $this
      ->getResultsList($vbo_data, $selection);

    // Execute the action.
    $this
      ->executeAction($vbo_data);
    $messenger = $this->container
      ->get('messenger');
    $messages = $messenger
      ->messagesByType($messenger::TYPE_STATUS);
    preg_match('#views_bulk_operations_test_.*\\.csv#', html_entity_decode($messages[0]), $matches);
    $file_path = Settings::get('file_public_path') . '/' . $matches[0];
    $contents = file_get_contents($file_path);
    $rows = explode(PHP_EOL, $contents);
    foreach ($this->testNodesData as $nid => $item) {
      if (in_array($nid - 1, $selection)) {
        $this
          ->assertEquals($item['en'], $rows[$nid], "Exported node title doesn't match");
      }
      else {
        $this
          ->assertTrue(empty($rows[$nid]));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CsvExportTest::$modules public static property
CsvExportTest::SEPARATOR private constant
CsvExportTest::setUp public function
CsvExportTest::testCsvExport public function Tests the bulk edit action.