RestExportNestedTest.php in REST Export Nested 8
File
tests/src/Functional/RestExportNestedTest.php
View source
<?php
namespace Drupal\Tests\rest_export_nested\Functional;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class RestExportNestedTest extends ViewTestBase {
protected $view;
public static $modules = [
'rest_nested_test',
'node',
'rest',
'serialization',
'user',
'views',
'rest_export_nested',
];
public static $testViews = [
'nested_data',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->createContentType([
'type' => 'page',
]);
$this
->createNode([
'status' => TRUE,
'type' => 'page',
'title' => 'test page',
]);
ViewTestData::createTestViews(static::class, [
'rest_nested_test',
]);
$this->view = Views::getView('nested_data');
$this->view
->setDisplay('rest_export_nested_1');
}
public function testViewExportNested() {
$actual_json = $this
->drupalGet('nested-data', [
'query' => [
'_format' => 'json',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$expected = '[{"nothing":[{"title":"Article","body":"Body"}]}]';
$this
->assertSame($actual_json, $expected);
}
public function testViewExport() {
$actual_json = $this
->drupalGet('not-nested-data', [
'query' => [
'_format' => 'json',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$expected = '[{"nothing":[{"title":"Article","body":"Body"}]}]';
$this
->assertNotSame($actual_json, $expected);
}
}