Unverified Commit 7f0e8169 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3463524 editor_post_update_sanitize_image_upload_settings fails on missing text format

By: sboden
By: catch
By: quietone
parent b6e7550e
Loading
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -125,7 +125,14 @@ public function label() {
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Create a dependency on the associated FilterFormat.
    $this->addDependency('config', $this->getFilterFormat()->getConfigDependencyName());
    $text_format = $this->getFilterFormat();
    if ($text_format) {
      $this->addDependency('config', $text_format->getConfigDependencyName());
    }
    else {
      trigger_error("The editor {$this->id()} is configured for text format {$this->id()} which does not exist. Review whether it is still needed and delete if not.", E_USER_WARNING);
    }

    // @todo use EntityWithPluginCollectionInterface so configuration between
    //   config entity and dependency on provider is managed automatically.
    $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
+50 −0
Original line number Diff line number Diff line
@@ -135,4 +135,54 @@ public function testCalculateDependencies(): void {
    $this->assertContains('filter.format.test', $dependencies['config']);
  }

  /**
   * @covers ::calculateDependencies
   *
   * @group legacy
   */
  public function testCalculateDependenciesWithNull(): void {
    $format_id = 'filter.format.test';
    $values = ['editor' => $this->editorId, 'format' => $format_id];

    $plugin = $this->getMockBuilder('Drupal\editor\Plugin\EditorPluginInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $plugin->expects($this->never())
      ->method('getPluginDefinition')
      ->willReturn(['provider' => 'test_module']);
    $plugin->expects($this->once())
      ->method('getDefaultSettings')
      ->willReturn([]);

    $this->editorPluginManager->expects($this->once())
      ->method('createInstance')
      ->with($this->editorId)
      ->willReturn($plugin);

    $entity = new Editor($values, $this->entityTypeId);

    $filter_format = $this->createMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
    $storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');

    $filter_format->expects($this->never())
      ->method('getConfigDependencyName')
      ->willReturn('filter.format.test');

    $storage->expects($this->once())
      ->method('load')
      ->with($format_id)
      ->willReturn(NULL);

    $this->entityTypeManager->expects($this->once())
      ->method('getStorage')
      ->with('filter_format')
      ->willReturn($storage);

    $this->expectWarning();
    $this->expectWarningMessage('The editor filter.format.test is configured for text format filter.format.test which does not exist. Review whether it is still needed and delete if not.');
    $dependencies = $entity->calculateDependencies()->getDependencies();
    $this->assertContains('test_module', $dependencies['module']);
    $this->assertArrayNotHasKey('config', $dependencies);
  }

}