You are here

class ViewTest in Drupal 10

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/ViewTest.php \Drupal\Tests\jsonapi\Functional\ViewTest
  2. 10 core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php \Drupal\Tests\views\Unit\Plugin\area\ViewTest
Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ViewTest.php \Drupal\Tests\jsonapi\Functional\ViewTest
  2. 9 core/modules/jsonapi/tests/src/Functional/ViewTest.php \Drupal\Tests\jsonapi\Functional\ViewTest

JSON:API integration test for the "View" config entity type.

@group jsonapi

Hierarchy

Expanded class hierarchy of ViewTest

File

core/modules/jsonapi/tests/src/Functional/ViewTest.php, line 13

Namespace

Drupal\Tests\jsonapi\Functional
View source
class ViewTest extends ConfigEntityResourceTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'views',
    'views_ui',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $entityTypeId = 'view';

  /**
   * {@inheritdoc}
   */
  protected static $resourceTypeName = 'view--view';

  /**
   * {@inheritdoc}
   *
   * @var \Drupal\views\ViewEntityInterface
   */
  protected $entity;

  /**
   * {@inheritdoc}
   */
  protected function setUpAuthorization($method) {
    $this
      ->grantPermissionsToTestedRole([
      'administer views',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function createEntity() {
    $view = View::create([
      'id' => 'test_rest',
      'label' => 'Test REST',
    ]);
    $view
      ->save();
    return $view;
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/view/view/' . $this->entity
      ->uuid())
      ->setAbsolute()
      ->toString(TRUE)
      ->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => [
              'href' => 'http://jsonapi.org/format/1.0/',
            ],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'view--view',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'base_field' => 'nid',
          'base_table' => 'node',
          'dependencies' => [],
          'description' => '',
          'display' => [
            'default' => [
              'display_plugin' => 'default',
              'id' => 'default',
              'display_title' => 'Default',
              'position' => 0,
              'display_options' => [
                'display_extenders' => [],
              ],
              'cache_metadata' => [
                'max-age' => -1,
                'contexts' => [
                  'languages:language_interface',
                  'url.query_args',
                ],
                'tags' => [],
              ],
            ],
          ],
          'label' => 'Test REST',
          'langcode' => 'en',
          'module' => 'views',
          'status' => TRUE,
          'tag' => '',
          'drupal_internal__id' => 'test_rest',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getPostDocument() {

    // @todo Update in https://www.drupal.org/node/2300677.
    return [];
  }

}

Members