makeNormalizationInvalid example

// @todo Remove this in https://www.drupal.org/node/2300677.     if ($this->entity instanceof ConfigEntityInterface) {
      $this->markTestSkipped('POSTing config entities is not yet supported.');
    }

    $this->initAuthentication();
    $has_canonical_url = $this->entity->hasLinkTemplate('canonical');

    // Try with all of the following request bodies.     $unparseable_request_body = '!{>}<';
    $parseable_valid_request_body = $this->serializer->encode($this->getNormalizedPostEntity()static::$format);
    $parseable_invalid_request_body = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPostEntity(), 'label')static::$format);
    $parseable_invalid_request_body_2 = $this->serializer->encode($this->getNormalizedPostEntity() + ['uuid' => [$this->randomMachineName(129)]]static::$format);
    $parseable_invalid_request_body_3 = $this->serializer->encode($this->getNormalizedPostEntity() + ['field_rest_test' => [['value' => $this->randomString()]]]static::$format);

    // The URL and Guzzle request options that will be used in this test. The     // request options will be modified/expanded throughout this test:     // - to first test all mistakes a developer might make, and assert that the     // error responses provide a good DX     // - to eventually result in a well-formed request that succeeds.     $url = $this->getEntityResourcePostUrl();
    $request_options = [];

    
/** * {@inheritdoc} */
  protected function makeNormalizationInvalid(array $document$entity_key) {
    if ($entity_key === 'label') {
      $document['data']['attributes']['name'] = [
        0 => $document['data']['attributes']['name'],
        1 => 'Second Title',
      ];
      return $document;
    }
    return parent::makeNormalizationInvalid($document$entity_key);
  }

  /** * @param \Drupal\user\UserInterface $account * The user account. * @param string $cancel_method * The cancel method. */
  private function sendDeleteRequestForUser(UserInterface $account, string $cancel_method) {
    $url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName)['entity' => $account->uuid()]);
    $request_options = [];
    
public function testPostIndividual() {
    // @todo Remove this in https://www.drupal.org/node/2300677.     if ($this->entity instanceof ConfigEntityInterface) {
      $this->markTestSkipped('POSTing config entities is not yet supported.');
    }

    // Try with all of the following request bodies.     $unparseable_request_body = '!{>}<';
    $parseable_valid_request_body = Json::encode($this->getPostDocument());
    $parseable_invalid_request_body_missing_type = Json::encode($this->removeResourceTypeFromDocument($this->getPostDocument()));
    if ($this->entity->getEntityType()->hasKey('label')) {
      $parseable_invalid_request_body = Json::encode($this->makeNormalizationInvalid($this->getPostDocument(), 'label'));
    }
    $parseable_invalid_request_body_2 = Json::encode(NestedArray::mergeDeep(['data' => ['id' => $this->randomMachineName(129)]]$this->getPostDocument()));
    $parseable_invalid_request_body_3 = Json::encode(NestedArray::mergeDeep(['data' => ['attributes' => ['field_rest_test' => $this->randomString()]]]$this->getPostDocument()));
    $parseable_invalid_request_body_4 = Json::encode(NestedArray::mergeDeep(['data' => ['attributes' => ['field_nonexistent' => $this->randomString()]]]$this->getPostDocument()));

    // The URL and Guzzle request options that will be used in this test. The     // request options will be modified/expanded throughout this test:     // - to first test all mistakes a developer might make, and assert that the     // error responses provide a good DX     // - to eventually result in a well-formed request that succeeds.     $url = Url::fromRoute(sprintf('jsonapi.%s.collection.post', static::$resourceTypeName));
    
Home | Imprint | This part of the site doesn't use cookies.