Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/DateFormatTest.php \Drupal\Tests\jsonapi\Functional\DateFormatTest
  2. 10 core/modules/system/tests/src/FunctionalJavascript/System/DateFormatTest.php \Drupal\Tests\system\FunctionalJavascript\System\DateFormatTest
Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/DateFormatTest.php \Drupal\Tests\jsonapi\Functional\DateFormatTest
  2. 9 core/modules/jsonapi/tests/src/Functional/DateFormatTest.php \Drupal\Tests\jsonapi\Functional\DateFormatTest

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

@group jsonapi @group #slow

Hierarchy

Expanded class hierarchy of DateFormatTest

File

core/modules/jsonapi/tests/src/Functional/DateFormatTest.php, line 16

Namespace

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

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

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

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

  /**
   * {@inheritdoc}
   */
  protected static $anonymousUsersCanViewLabels = TRUE;

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

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

  /**
   * {@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' => [
              'href' => 'http://jsonapi.org/format/1.0/',
            ],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'data' => [
        'id' => $this->entity
          ->uuid(),
        'type' => 'date_format--date_format',
        'links' => [
          'self' => [
            'href' => $self_url,
          ],
        ],
        'attributes' => [
          'dependencies' => [],
          'label' => 'Llama',
          'langcode' => 'en',
          'locked' => FALSE,
          'pattern' => 'F d, Y',
          'status' => TRUE,
          'drupal_internal__id' => 'llama',
        ],
      ],
    ];
  }

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigEntityResourceTestBase::setUp public function
ConfigEntityResourceTestBase::SKIP_METHODS constant A list of test methods to skip.
DateFormatTest::$anonymousUsersCanViewLabels protected static property
DateFormatTest::$defaultTheme protected property
DateFormatTest::$entity protected property
DateFormatTest::$entityTypeId protected static property
DateFormatTest::$modules protected static property
DateFormatTest::$resourceTypeName protected static property
DateFormatTest::createEntity protected function
DateFormatTest::getExpectedDocument protected function
DateFormatTest::getPostDocument protected function
DateFormatTest::setUpAuthorization protected function