You are here

DateFormatTest.php in JSON:API 8

Same filename and directory in other branches
  1. 8.2 tests/src/Functional/DateFormatTest.php

File

tests/src/Functional/DateFormatTest.php
View source
<?php

namespace Drupal\Tests\jsonapi\Functional;

use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Url;

/**
 * JSON API integration test for the "DateFormat" config entity type.
 *
 * @group jsonapi
 */
class DateFormatTest extends ResourceTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [];

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

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

  /**
   * {@inheritdoc}
   *
   * @var \Drupal\Core\Datetime\DateFormatInterface
   */
  protected $entity;

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

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

    // Create a date format.
    $date_format = DateFormat::create([
      'id' => 'llama',
      'label' => 'Llama',
      'pattern' => 'F d, Y',
    ]);
    $date_format
      ->save();
    return $date_format;
  }

  /**
   * {@inheritdoc}
   */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/date_format/date_format/' . $this->entity
      ->uuid())
      ->setAbsolute()
      ->toString(TRUE)
      ->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => 'http://jsonapi.org/format/1.0/',
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => $self_url,
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'date_format--date_format',
        'links' => [
          'self' => $self_url,
        ],
        'attributes' => [
          'dependencies' => [],
          'id' => 'llama',
          'label' => 'Llama',
          'langcode' => 'en',
          'locked' => FALSE,
          'pattern' => 'F d, Y',
          'status' => TRUE,
          'uuid' => $this->entity
            ->uuid(),
        ],
      ],
    ];
  }

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

    // @todo Update in https://www.drupal.org/node/2300677.
  }

}

Classes

Namesort descending Description
DateFormatTest JSON API integration test for the "DateFormat" config entity type.