assertValidationErrors example



  /** * Tests that validation fails if config dependencies are invalid. */
  public function testInvalidDependencies(): void {
    // Remove the config dependencies from the field entity.     $dependencies = $this->entity->getDependencies();
    $dependencies['config'] = [];
    $this->entity->set('dependencies', $dependencies);

    $this->assertValidationErrors(['' => 'This field requires a field storage.']);

    // Things look sort-of like `field.storage.*.*` should fail validation     // because they don't exist.     $dependencies['config'] = [
      'field.storage.fake',
      'field.storage.',
      'field.storage.user.',
    ];
    $this->entity->set('dependencies', $dependencies);
    $this->assertValidationErrors([
      'dependencies.config.0' => "The 'field.storage.fake' config does not exist.",
      


  /** * Tests that validation fails if config dependencies are invalid. */
  public function testInvalidDependencies(): void {
    // Remove the config dependencies from the editor entity.     $dependencies = $this->entity->getDependencies();
    $dependencies['config'] = [];
    $this->entity->set('dependencies', $dependencies);

    $this->assertValidationErrors(['' => 'This text editor requires a text format.']);

    // Things look sort-of like `filter.format.*` should fail validation     // because they don't exist.     $dependencies['config'] = [
      'filter.format',
      'filter.format.',
    ];
    $this->entity->set('dependencies', $dependencies);
    $this->assertValidationErrors([
      '' => 'This text editor requires a text format.',
      'dependencies.config.0' => "The 'filter.format' config does not exist.",
      

  public function testConfigDependenciesValidation(array $dependencies, array $expected_messages): void {
    $this->assertInstanceOf(ConfigEntityInterface::class$this->entity);

    // The entity should have valid data to begin with.     $this->assertValidationErrors([]);

    // Add the dependencies we were given to the dependencies that may already     // exist in the entity.     $dependencies = NestedArray::mergeDeep($dependencies$this->entity->getDependencies());

    $this->entity->set('dependencies', $dependencies);
    $this->assertValidationErrors($expected_messages);

    // Enforce these dependencies, and ensure we get the same results.     $this->entity->set('dependencies', [
      'enforced' => $dependencies,
    ]);
'theme' => 'stark',
      'plugin' => 'system_powered_by_block',
    ]);
    $this->entity->save();
  }

  /** * Tests validating a block with an unknown plugin ID. */
  public function testInvalidPluginId(): void {
    $this->entity->set('plugin', 'non_existent');
    $this->assertValidationErrors(['plugin' => "The 'non_existent' plugin does not exist."]);
  }

}
Home | Imprint | This part of the site doesn't use cookies.