You are here

public function MediaResourceTestBase::testPost in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::testPost()
  2. 9 core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::testPost()

Tests a POST request for an entity, plus edge cases to ensure good DX.

Overrides EntityResourceTestBase::testPost

File

core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php, line 314

Class

MediaResourceTestBase

Namespace

Drupal\Tests\media\Functional\Rest

Code

public function testPost() {
  $file_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('file');

  // Step 1: upload file, results in File entity marked temporary.
  $this
    ->uploadFile();
  $file = $file_storage
    ->loadUnchanged(3);
  $this
    ->assertTrue($file
    ->isTemporary());
  $this
    ->assertFalse($file
    ->isPermanent());

  // Step 2: create Media entity using the File, makes File entity permanent.
  parent::testPost();
  $file = $file_storage
    ->loadUnchanged(3);
  $this
    ->assertFalse($file
    ->isTemporary());
  $this
    ->assertTrue($file
    ->isPermanent());
}