provisionResource example

protected function provisionEntityResource($single_format = FALSE) {
    if ($existing = $this->resourceConfigStorage->load(static::$resourceConfigId)) {
      $existing->delete();
    }

    $format = $single_format
      ? [static::$format]
      : [static::$format, 'foobar'];
    // It's possible to not have any authentication providers enabled, when     // testing public (anonymous) usage of a REST resource.     $auth = isset(static::$auth) ? [static::$auth] : [];
    $this->provisionResource($format$auth);
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Calculate REST Resource config entity ID.     static::$resourceConfigId = 'entity.' . static::$entityTypeId;

    
$page->checkField('settings[label_display]');
    $page->pressButton('Add block');
    $page->pressButton('Save layout');
    $assert_session->pageTextContains('This is an override');

    $this->nodeStorage = $this->container->get('entity_type.manager')->getStorage('node');
    $this->node = $this->nodeStorage->load($this->node->id());

    $this->drupalLogout();
    $this->setUpAuthorization('ALL');

    $this->provisionResource([static::$format]['basic_auth']);
  }

  /** * {@inheritdoc} */
  protected function request($method, Url $url, array $request_options = []) {
    $request_options[RequestOptions::HEADERS] = [
      'Content-Type' => static::$mimeType,
    ];
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions($method));
    $request_options[RequestOptions::QUERY] = ['_format' => static::$format];
    
->save();

    $this->refreshTestStateAfterRestConfigChange();
  }

  /** * Tests using the file upload POST route. */
  public function testPostFileUpload() {
    $this->initAuthentication();

    $this->provisionResource([static::$format]static::$auth ? [static::$auth] : []['POST']);

    $uri = Url::fromUri('base:' . static::$postUri);

    // DX: 403 when unauthorized.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST')$response);

    $this->setUpAuthorization('POST');

    // 404 when the field name is invalid.     $invalid_uri = Url::fromUri('base:file/upload/entity_test/entity_test/field_rest_file_test_invalid');
    

  protected static $entityTypeId = '';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $auth = isset(static::$auth) ? [static::$auth] : [];
    $this->provisionResource([static::$format]$auth);
  }

  /** * Writes a log messages and retrieves it via the REST API. */
  public function testWatchdog(): void {
    // Write a log message to the DB.     $this->container->get('logger.channel.rest')->notice('Test message');
    // Get the ID of the written message.     $id = Database::getConnection()->select('watchdog', 'w')
      ->fields('w', ['wid'])
      
const USER_EMAIL_DOMAIN = '@example.com';

  const TEST_EMAIL_DOMAIN = 'simpletest@example.com';

  /** * {@inheritdoc} */
  public function setUp(): void {
    parent::setUp();

    $auth = isset(static::$auth) ? [static::$auth] : [];
    $this->provisionResource([static::$format]$auth);

    $this->setUpAuthorization('POST');
  }

  /** * Tests that only anonymous users can register users. */
  public function testRegisterUser() {
    $config = $this->config('user.settings');

    // Test out different setting User Registration and Email Verification.
->save();
  }

  /** * Deploying a REST resource using api_json format results in 400 responses. * * @see \Drupal\jsonapi\EventSubscriber\JsonApiRequestValidator::validateQueryParams() */
  public function testApiJsonNotSupportedInRest() {
    $this->assertSame(['json', 'xml']$this->container->getParameter('serializer.formats'));

    $this->provisionResource(['api_json'][]);
    $this->setUpAuthorization('GET');

    $url = Node::load(1)->toUrl()
      ->setOption('query', ['_format' => 'api_json']);
    $request_options = [];

    $response = $this->request('GET', $url$request_options);
    $this->assertResourceErrorResponse(
      400,
      FALSE,
      $response,
      [
Home | Imprint | This part of the site doesn't use cookies.