Skip to content
Snippets Groups Projects
Commit ee6fe3d4 authored by Youri van Koppen's avatar Youri van Koppen
Browse files

Merge branch '3135359-temp' into '3.0.x'

Draft: Resolve #3135359 "Temp"

See merge request !50
parents 03bf7454 1a41041b
No related branches found
No related tags found
No related merge requests found
Pipeline #468093 failed
Showing
with 592 additions and 0 deletions
......@@ -32,3 +32,18 @@ variables:
OPT_IN_TEST_CURRENT: '0'
# Enable D10 testing.
OPT_IN_TEST_PREVIOUS_MAJOR: '1'
composer (commonmark 1):
extends: .composer-base
before_script:
- composer require --dev league/commonmark:^1.6 --no-update
variables:
PHP_VERSION: "8.1"
PHP_IMAGE_VARIANT: "apache"
DRUPAL_CORE: "10.4.6"
IGNORE_PROJECT_DRUPAL_CORE_VERSION: 1
phpunit (commonmark 1):
extends: phpunit (previous major)
needs:
- "composer (commonmark 1)"
......@@ -25,6 +25,12 @@
"php": ">=5.5.9",
"composer/semver": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"league/commonmark": "^1.6 || ^2.0",
"erusev/parsedown": "^1.7",
"erusev/parsedown-extra": "^0.8.1",
"michelf/php-markdown": "^2.0"
},
"suggest": {
"league/commonmark": "The PHP CommonMark parser is a robust, highly-extensible Markdown parser for PHP based on the CommonMark and Github-Flavored Markdown specifications."
},
......
name: 'Markdown test no parsers'
type: module
description: 'Simulates the situation where no additional libraries are installed.'
package: Testing
dependencies:
- markdown:markdown
<?php
/**
* @file
* Hook implementations.
*/
/**
* Implements hook_markdown_parser_info_alter().
*
* Makes all available markdown parser plugins unavailable.
*/
function markdown_test_no_parsers_markdown_parser_info_alter(array &$info) {
foreach ($info as $key => $value) {
if ($key == '_missing_parser') {
continue;
}
// Add a fake requirement violation for the parser and for each library.
$info[$key]->requirementViolations['requires'] = t('Requires library');
foreach ($info[$key]->libraries as $key => $library) {
$library->version = NULL;
$library->requirementViolations['requires'] = t('Requires library');
}
}
}
......@@ -60,4 +60,33 @@ class FilterAdminTest extends MarkdownBrowserTestBase {
$this->assertTrue($markdown->isEnabled());
}
/**
* Tests enabling markdown when there are no parsers available.
*/
public function testEnableMarkdownFilterWithoutParsers() {
// Simulate the situation of no parsers being available.
$this->container->get('module_installer')->install(['markdown_test_no_parsers']);
// Add text format.
$this->drupalGet('admin/config/content/formats/add');
$format_id = $this->randomMachineName();
$name = $this->randomMachineName();
$edit = [
'format' => $format_id,
'name' => $name,
'filters[markdown][status]' => 1,
];
$this->submitForm($edit, 'Save configuration');
// Check that the filter has been created.
$format = FilterFormat::load($format_id);
$this->assertInstanceof(FilterFormatInterface::class, $format);
// And check that markdown filter is enabled.
$markdown = $format->filters()->get('markdown');
$this->assertInstanceof(FilterMarkdownInterface::class, $markdown);
$this->assertTrue($markdown->isEnabled());
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the CommonMark GFM parser.
*
* @group markdown
*/
class CommonMarkGfmTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'commonmark-gfm';
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the CommonMark parser.
*
* @group markdown
*/
class CommonMarkTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'commonmark';
}
/**
* Tests enable the external links extension.
*/
public function testEnableExternalLinks() {
$this->loginAsMarkdownAdmin();
$this->drupalGet($this->getConfigurePath());
$edit = [
'extensions[commonmark-external-links][enabled]' => 1,
];
$this->submitForm($edit, 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
// Check that the external links extension has been enabled.
$config = $this->container->get('config.factory')
->get('markdown.parser.commonmark');
// Find the index number for the 'commonmark-external-links' extension.
$extensions_config = $config->get('extensions');
$ids = array_column($extensions_config, 'id');
$key = array_search('commonmark-external-links', $ids);
$this->assertTrue($extensions_config[$key]['enabled']);
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
use Drupal\Tests\markdown\Functional\MarkdownBrowserTestBase;
use Drupal\filter\Entity\FilterFormat;
use Drupal\filter\FilterFormatInterface;
use Drupal\markdown\Plugin\Filter\FilterMarkdownInterface;
use Drupal\user\UserInterface;
/**
* Base class for MarkdownParser plugin tests.
*/
abstract class MarkdownParserTestBase extends MarkdownBrowserTestBase {
/**
* Tests that the settings form can be submitted.
*/
public function testConfigure() {
$this->loginAsMarkdownAdmin();
$this->drupalGet($this->getConfigurePath());
$this->submitForm([], 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
}
/**
* Tests creating a text format with markdown filter enabled.
*/
public function testEnableMarkdownFilter() {
$this->loginAsFilterAdmin();
// Add text format.
$this->drupalGet('admin/config/content/formats/add');
$format_id = $this->randomMachineName();
$name = $this->randomMachineName();
$edit = [
'format' => $format_id,
'name' => $name,
'filters[markdown][status]' => 1,
'filters[markdown][settings][id]' => $this->getPluginId(),
];
$this->submitForm($edit, 'Save configuration');
// Check that the filter has been created.
$format = FilterFormat::load($format_id);
$this->assertInstanceof(FilterFormatInterface::class, $format);
// And check that the markdown filter is enabled.
$markdown = $format->filters()->get('markdown');
$this->assertInstanceof(FilterMarkdownInterface::class, $markdown);
$this->assertTrue($markdown->isEnabled());
// And with the expected parser.
$config = $markdown->getConfiguration();
$this->assertEquals($this->getPluginId(), $config['settings']['id']);
$this->assertTrue($config['settings']['enabled']);
}
/**
* Returns the ID of the parser to test.
*
* @return string
* The parser ID to test.
*/
abstract protected function getPluginId(): string;
/**
* Returns the path on where the parser can be configured.
*
* @return string
* The path where the parser can be configured.
*/
protected function getConfigurePath(): string {
return '/admin/config/content/markdown/' . $this->getPluginId();
}
/**
* Creates an user who may administer filters and logs in as this user.
*
* @return \Drupal\user\UserInterface
* The created admin user.
*/
protected function loginAsFilterAdmin(): UserInterface {
$admin_user = $this->drupalCreateUser([
'administer filters',
'access site reports',
]);
$this->drupalLogin($admin_user);
return $admin_user;
}
/**
* Creates an user who may administer markdown and logs in as this user.
*
* @return \Drupal\user\UserInterface
* The created admin user.
*/
protected function loginAsMarkdownAdmin(): UserInterface {
$admin_user = $this->drupalCreateUser([
'administer markdown',
]);
$this->drupalLogin($admin_user);
return $admin_user;
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the Parsedown Extra parser.
*
* @group markdown
*/
class ParsedownExtraTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'parsedown-extra';
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the Parsedown parser.
*
* @group markdown
*/
class ParsedownTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'parsedown';
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the PHP Markdown Extra parser.
*
* @group markdown
*/
class PhpMarkdownExtraTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'php-markdown-extra';
}
}
<?php
namespace Drupal\Tests\markdown\Functional\Plugin\Markdown;
/**
* Tests the PHP Markdown parser.
*
* @group markdown
*/
class PhpMarkdownTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function getPluginId(): string {
return 'php-markdown';
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the CommonMark PECL parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\Pecl\Cmark
* @group markdown
*/
class CmarkTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('commonmark-pecl');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
/**
* @covers ::parse
* @dataProvider parseDataProvider
*/
public function testParse(string $expected_html, string $input) {
$this->markTestIncomplete('The test requires the PECL extension "ext-cmark".');
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the CommonMark GFM parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\CommonMark\CommonMarkGfm
* @group markdown
*/
class CommonMarkGfmTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('commonmark-gfm');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the CommonMark parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\CommonMark\CommonMark
* @group markdown
*/
class CommonMarkTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('commonmark');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\Tests\markdown\Kernel\MarkdownKernelTestBase;
use Drupal\markdown\Plugin\Markdown\ParserInterface;
use Drupal\markdown\Render\ParsedMarkdownInterface;
/**
* Base class for MarkdownParser plugin tests.
*/
abstract class MarkdownParserTestBase extends MarkdownKernelTestBase {
/**
* An instance of the markdown parser to test.
*
* @var \Drupal\markdown\Plugin\Markdown\ParserInterface
*/
protected ParserInterface $parser;
/**
* @covers ::parse
* @dataProvider parseDataProvider
*/
public function testParse(string $expected_html, string $input) {
$result = $this->parser->parse($input);
$this->assertInstanceof(ParsedMarkdownInterface::class, $result);
$this->assertEquals($expected_html, $result->getHtml());
}
/**
* Data provider for testParse().
*/
public static function parseDataProvider(): array {
$cases = [
'bold' => [
'expected_html' => '<p><strong>Bold</strong></p>',
'input' => '**Bold**',
],
'italic' => [
'expected_html' => '<p><em>Italic</em></p>',
'input' => '*Italic*',
],
'link' => [
'expected_html' => '<p><a href="https://example.com">Example link</a></p>',
'input' => '[Example link](https://example.com)',
],
];
return $cases;
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the Parsedown Extra parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\Parsedown\ParsedownExtra
* @group markdown
*/
class ParsedownExtraTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('parsedown-extra');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the Parsedown parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\Parsedown\Parsedown
* @group markdown
*/
class ParsedownTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('parsedown');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the PHP Markdown Extra parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\PhpMarkdown\PhpMarkdownExtra
* @group markdown
*/
class PhpMarkdownExtraTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('php-markdown-extra');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
<?php
namespace Drupal\Tests\markdown\Kernel\Plugin\Markdown;
use Drupal\markdown\Plugin\Markdown\RenderStrategyInterface;
/**
* Tests rendering text using the PHP Markdown parser.
*
* @coversDefaultClass \Drupal\markdown\Plugin\Markdown\PhpMarkdown\PhpMarkdown
* @group markdown
*/
class PhpMarkdownTest extends MarkdownParserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->parser = $this->container->get('plugin.manager.markdown.parser')
->createInstance('php-markdown');
$config = $this->parser->getConfiguration();
$config['render_strategy']['type'] = RenderStrategyInterface::NONE;
$this->parser->setConfiguration($config);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment