createAnotherEntity example

$this->assertEquals($original_name$updated_user->get('name')->value);
  }

  /** * Tests if JSON:API respects user.settings.cancel_method: user_cancel_block. */
  public function testDeleteRespectsUserCancelBlock() {
    $cancel_method = 'user_cancel_block';
    $this->config('jsonapi.settings')->set('read_only', FALSE)->save(TRUE);
    $this->config('user.settings')->set('cancel_method', $cancel_method)->save(TRUE);

    $account = $this->createAnotherEntity($cancel_method);
    $node = $this->drupalCreateNode(['uid' => $account->id()]);

    $this->sendDeleteRequestForUser($account$cancel_method);

    $user_storage = $this->container->get('entity_type.manager')
      ->getStorage('user');
    $user_storage->resetCache([$account->id()]);
    $account = $user_storage->load($account->id());

    $this->assertNotNull($account, 'User is not deleted after JSON:API DELETE operation with user.settings.cancel_method: ' . $cancel_method);
    $this->assertTrue($account->isBlocked(), 'User is blocked after JSON:API DELETE operation with user.settings.cancel_method: ' . $cancel_method);

    
/** * Sets up a collection of entities of the same type for testing. * * @return \Drupal\Core\Entity\EntityInterface[] * The collection of entities to test. * * @throws \Drupal\Core\Entity\EntityStorageException */
  protected function getData() {
    if ($this->entityStorage->getQuery()->accessCheck(FALSE)->count()->execute() < 2) {
      $this->createAnotherEntity('two');
    }
    $query = $this->entityStorage
      ->getQuery()
      ->accessCheck(FALSE)
      ->sort($this->entity->getEntityType()->getKey('id'));
    return $this->entityStorage->loadMultiple($query->execute());
  }

  /** * Generates a JSON:API normalization for the given entity. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to generate a JSON:API normalization for. * @param \Drupal\Core\Url $url * The URL to use as the "self" link. * * @return array * The JSON:API normalization for the given entity. */
/** * Tests a PATCH request for an entity, plus edge cases to ensure good DX. */
  public function testPatch() {
    // @todo Remove this in https://www.drupal.org/node/2300677.     if ($this->entity instanceof ConfigEntityInterface) {
      $this->markTestSkipped('PATCHing config entities is not yet supported.');
    }

    // Patch testing requires that another entity of the same type exists.     $this->anotherEntity = $this->createAnotherEntity();

    $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->getNormalizedPatchEntity()static::$format);
    $parseable_invalid_request_body   = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPatchEntity(), 'label')static::$format);
    $parseable_invalid_request_body_2 = $this->serializer->encode($this->getNormalizedPatchEntity() + ['field_rest_test' => [['value' => $this->randomString()]]]static::$format);
    // The 'field_rest_test' field does not allow 'view' access, so does not end     // up in the normalization. Even when we explicitly add it the normalization
file_put_contents($file->getFileUri(), 'Drupal');

    return $file;
  }

  /** * {@inheritdoc} */
  protected function createAnotherEntity($key) {
    /** @var \Drupal\file\FileInterface $duplicate */
    $duplicate = parent::createAnotherEntity($key);
    $duplicate->setFileUri("public://$key.txt");
    $duplicate->save();
    return $duplicate;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/file/file/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      
Home | Imprint | This part of the site doesn't use cookies.