You are here

public function EntityResourceTest::testDeleteIndividual in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testDeleteIndividual()

@covers ::deleteIndividual

File

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

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testDeleteIndividual() {
  $node = Node::create([
    'type' => 'article',
    'title' => 'Lorem ipsum',
  ]);
  $nid = $node
    ->id();
  $node
    ->save();
  Role::load(Role::ANONYMOUS_ID)
    ->grantPermission('delete own article content')
    ->save();
  $entity_resource = $this
    ->buildEntityResource('node', 'article');
  $response = $entity_resource
    ->deleteIndividual($node, new Request());

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