getModifiedEntityForPostTesting example

$uuid = $second_created_entity->uuid();
      // @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.       $location = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName)['entity' => $uuid]);
      /* $location = $this->entityStorage->load(static::$secondCreatedEntityId)->toUrl('jsonapi')->setAbsolute(TRUE)->toString(); */
      if (static::$resourceTypeIsVersionable) {
        assert($created_entity instanceof RevisionableInterface);
        $location->setOption('query', ['resourceVersion' => 'id:' . $second_created_entity->getRevisionId()]);
      }
      $this->assertSame([$location->setAbsolute()->toString()]$response->getHeader('Location'));

      // 500 when creating an entity with a duplicate UUID.       $doc = $this->getModifiedEntityForPostTesting();
      $doc['data']['id'] = $uuid;
      $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName;
      if (isset($label_field)) {
        $doc['data']['attributes'][$label_field] = [['value' => $this->randomMachineName()]];
      }
      $request_options[RequestOptions::BODY] = Json::encode($doc);

      $response = $this->request('POST', $url$request_options);
      $this->assertResourceErrorResponse(409, 'Conflict: Entity already exists.', $url$response, FALSE);

      // 201 when successfully creating an entity with a new UUID.
    if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) {
      // Assert that the entity was indeed created, and that the response body       // contains the serialized created entity.       $created_entity = $this->entityStorage->loadUnchanged(static::$firstCreatedEntityId);
      $created_entity_normalization = $this->serializer->normalize($created_entitystatic::$format['account' => $this->account]);
      $this->assertSame($created_entity_normalization$this->serializer->decode((string) $response->getBody()static::$format));
      $this->assertStoredEntityMatchesSentNormalization($this->getNormalizedPostEntity()$created_entity);
    }

    if ($this->entity->getEntityType()->getStorageClass() !== ContentEntityNullStorage::class && $this->entity->getEntityType()->hasKey('uuid')) {
      // 500 when creating an entity with a duplicate UUID.       $normalized_entity = $this->getModifiedEntityForPostTesting();
      $normalized_entity[$created_entity->getEntityType()->getKey('uuid')] = [['value' => $created_entity->uuid()]];
      if ($label_field) {
        $normalized_entity[$label_field] = [['value' => $this->randomMachineName()]];
      }
      $request_options[RequestOptions::BODY] = $this->serializer->encode($normalized_entitystatic::$format);

      $response = $this->request('POST', $url$request_options);
      $this->assertSame(500, $response->getStatusCode());
      $this->assertStringContainsString('Internal Server Error', (string) $response->getBody());

      // 201 when successfully creating an entity with a new UUID.
$this->assertNull($account, 'User is deleted after JSON:API DELETE operation with user.settings.cancel_method: ' . $cancel_method);

    $node_storage->resetCache([$node->id()]);
    $test_node = $node_storage->load($node->id());
    $this->assertNull($test_node, 'Node of the user is deleted.');
  }

  /** * {@inheritdoc} */
  protected function getModifiedEntityForPostTesting() {
    $modified = parent::getModifiedEntityForPostTesting();
    $modified['data']['attributes']['name'] = $this->randomMachineName();
    return $modified;
  }

  /** * {@inheritdoc} */
  protected function makeNormalizationInvalid(array $document$entity_key) {
    if ($entity_key === 'label') {
      $document['data']['attributes']['name'] = [
        0 => $document['data']['attributes']['name'],
        
Home | Imprint | This part of the site doesn't use cookies.