refreshTestStateAfterRestConfigChange example

if (str_starts_with($header, 'X-Drupal-Assertion-') || in_array($header$ignored_headers)) {
          unset($headers[$header]);
        }
      }
      return $headers;
    };
    $get_headers = $header_cleaner($get_headers);
    $head_headers = $header_cleaner($head_headers);
    $this->assertSame($get_headers$head_headers);

    $this->resourceConfigStorage->load(static::$resourceConfigId)->disable()->save();
    $this->refreshTestStateAfterRestConfigChange();

    // DX: upon disabling a resource, it's immediately no longer available.     $this->assertResourceNotAvailable($url$request_options);

    $this->resourceConfigStorage->load(static::$resourceConfigId)->enable()->save();
    $this->refreshTestStateAfterRestConfigChange();

    // DX: upon re-enabling a resource, immediate 200.     $response = $this->request('GET', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response$this->getExpectedCacheTags()$this->getExpectedCacheContexts()static::$auth ? FALSE : 'MISS', $is_cacheable_by_dynamic_page_cache ? 'MISS' : 'UNCACHEABLE');

    
// Enable the 'file_upload' REST resource for the current format + auth.     $this->resourceConfigStorage->create([
      'id' => 'file.upload',
      'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
      'configuration' => [
        'methods' => ['POST'],
        'formats' => [static::$format],
        'authentication' => isset(static::$auth) ? [static::$auth] : [],
      ],
      'status' => TRUE,
    ])->save();
    $this->refreshTestStateAfterRestConfigChange();

    $this->initAuthentication();

    // POST to create a File entity.     $url = Url::fromUri('base:file/upload/media/camelids/field_media_file');
    $url->setOption('query', ['_format' => static::$format]);
    $request_options = [];
    $request_options[RequestOptions::HEADERS] = [
      // Set the required (and only accepted) content type for the request.       'Content-Type' => 'application/octet-stream',
      // Set the required Content-Disposition header for the file name.
    $this->resourceConfigStorage->create([
      'id' => 'entity.file',
      'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
      'configuration' => [
        'methods' => ['GET'],
        'formats' => [static::$format],
        'authentication' => isset(static::$auth) ? [static::$auth] : [],
      ],
      'status' => TRUE,
    ])->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);

    

    else {
      // Otherwise, also create an account, so that any test involving User       // entities will have the same user IDs regardless of authentication.       $this->createUser();
    }

    $this->resourceConfigStorage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config');

    // Ensure there's a clean slate: delete all REST resource config entities.     $this->resourceConfigStorage->delete($this->resourceConfigStorage->loadMultiple());
    $this->refreshTestStateAfterRestConfigChange();
  }

  /** * Provisions the REST resource under test. * * @param string[] $formats * The allowed formats for this resource. * @param string[] $authentication * The allowed authentication providers for this resource. * @param string[] $methods * The allowed methods for this resource. */
Home | Imprint | This part of the site doesn't use cookies.