Skip to content
Snippets Groups Projects

Tests only, do not merge.

Open Youri van Koppen requested to merge issue/markdown-3450532:3450532-tests_only into 3.0.x
2 files
+ 121
0
Compare changes
  • Side-by-side
  • Inline
Files
2
<?php
namespace Drupal\Tests\markdown\Unit;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\markdown\Unit\MarkdownUnitTestBase;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterInterface;
use Drupal\markdown\PluginManager\ParserManagerInterface;
use Drupal\markdown\Plugin\Filter\FilterMarkdown;
use Drupal\markdown\Plugin\Markdown\ParserInterface;
use Drupal\markdown\Render\ParsedMarkdownInterface;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\markdown\Plugin\Filter\FilterMarkdown
* @group markdown
*/
class FilterMarkdownTest extends MarkdownUnitTestBase {
/**
* The Element Info Manager service.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Render\ElementInfoManagerInterface
*/
protected $elementInfo;
/**
* The Markdown Parser Plugin Manager service.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\markdown\PluginManager\ParserManagerInterface
*/
protected $parserManager;
/**
* The Markdown Parser Plugin Manager service.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\markdown\Plugin\Markdown\ParserInterface
*/
protected $parser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->elementInfo = $this->prophesize(ElementInfoManagerInterface::class);
$this->parserManager = $this->prophesize(ParserManagerInterface::class);
$this->parser = $this->prophesize(ParserInterface::class);
$this->parser->getPluginId()
->willReturn('foo');
$this->parser->parse(Argument::type('string'), NULL)
->willReturn($this->createMock(ParsedMarkdownInterface::class));
$this->parser->getConfiguration()
->willReturn([]);
$container = new ContainerBuilder();
$config_factory = $this->prophesize(ConfigFactoryInterface::class);
$config_factory->get('markdown.parser.foo')
->willReturn($this->createMock(ImmutableConfig::class));
$container->set('config.factory', $config_factory->reveal());
\Drupal::setContainer($container);
}
/**
* Returns a new FilterMarkdown instance to test with.
*
* @param array $configuration
* (optional) The configuration for the filter.
*
* @return \Drupal\markdown\Plugin\Filter\FilterMarkdown
* A FilterMarkdown instance.
*/
protected function getInstance(array $configuration = []): FilterMarkdown {
$plugin_definition = [
'description' => new TranslatableMarkup('Allows content to be submitted using Markdown, a simple plain-text syntax that is filtered into valid HTML.'),
'weight' => -15,
'status' => TRUE,
'settings' => [],
'id' => 'markdown',
'title' => new TranslatableMarkup('Markdown'),
'type' => FilterInterface::TYPE_MARKUP_LANGUAGE,
'class' => FilterMarkdown::class,
'provider' => 'markdown',
];
return new FilterMarkdown($configuration, 'markdown', $plugin_definition, $this->elementInfo->reveal(), $this->parserManager->reveal());
}
/**
* @covers ::process
*/
public function testProcess() {
$this->parserManager->getDefaultParser()
->willReturn($this->parser->reveal());
$this->parserManager->createInstance('foo', Argument::type('array'))
->willReturn($this->parser->reveal());
$filter = $this->getInstance();
$result = $filter->process('foo');
$this->assertInstanceof(FilterProcessResult::class, $result);
$this->assertIsString($result->getProcessedText());
}
}
Loading