You are here

public function EntityResourceTest::testDeleteIndividualConfig in JSON:API Extras 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi_extras\Kernel\Controller\EntityResourceTest::testDeleteIndividualConfig()

@covers ::deleteIndividual

File

tests/src/Kernel/Controller/EntityResourceTest.php, line 174

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @covers \Drupal\jsonapi_extras\Normalizer\ConfigEntityNormalizer @group jsonapi_extras @group legacy

Namespace

Drupal\Tests\jsonapi_extras\Kernel\Controller

Code

public function testDeleteIndividualConfig() {
  $node_type = NodeType::create([
    'type' => 'test',
    'name' => 'Test Type',
    'description' => 'Lorem ipsum',
  ]);
  $id = $node_type
    ->id();
  $node_type
    ->save();
  Role::load(Role::ANONYMOUS_ID)
    ->grantPermission('administer content types')
    ->save();
  $resource_type = new ResourceType('node', 'article', NULL);
  $entity_resource = new EntityResource($resource_type, $this->container
    ->get('entity_type.manager'), $this->container
    ->get('entity_field.manager'), $this->container
    ->get('plugin.manager.field.field_type'), $this->container
    ->get('jsonapi.link_manager'), $this->container
    ->get('jsonapi.resource_type.repository'), $this->container
    ->get('renderer'));
  $response = $entity_resource
    ->deleteIndividual($node_type, new Request());

  // As a side effect, the node will also be deleted.
  $count = $this->container
    ->get('entity_type.manager')
    ->getStorage('node_type')
    ->getQuery()
    ->condition('type', $id)
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $count);
  $this
    ->assertNull($response
    ->getResponseData());
  $this
    ->assertEquals(204, $response
    ->getStatusCode());
}