You are here

public function ApidocEntityTest::testEntity in Apigee API Catalog 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/ApidocEntityTest.php \Drupal\Tests\apigee_api_catalog\Kernel\ApidocEntityTest::testEntity()

Basic CRUD operations on a ApiDoc node entity.

File

tests/src/Kernel/ApidocEntityTest.php, line 84

Class

ApidocEntityTest
Test basic CRUD operations for ApiDoc.

Namespace

Drupal\Tests\apigee_api_catalog\Kernel

Code

public function testEntity() {
  $entity = $this->nodeStorage
    ->create([
    'type' => 'apidoc',
    'title' => 'API 1',
    'body' => [
      'value' => 'Test API 1',
      'format' => 'basic_html',
    ],
    'field_apidoc_spec' => NULL,
  ]);
  $this
    ->assertNotNull($entity);
  $this
    ->assertEquals(SAVED_NEW, $entity
    ->save());
  $this
    ->assertEquals(SAVED_UPDATED, $entity
    ->set('title', 'API 1a')
    ->save());
  $entity_id = $entity
    ->id();
  $this
    ->assertNotEmpty($entity_id);

  // Test path alias.
  // This needs to run before the alias can be picked up?
  $entity
    ->toUrl()
    ->toString();
  $alias = \Drupal::service('path_alias.manager')
    ->getAliasByPath('/node/' . $entity
    ->id(), $entity
    ->language()
    ->getId());
  $this
    ->assertEqual($alias, '/api/' . $entity
    ->id());
  $entity
    ->delete();
  $this
    ->assertNull($this->nodeStorage
    ->load($entity_id));
}