Skip to content

Commit

Permalink
Merge pull request #1511 from openeuropa/EWPP-4796
Browse files Browse the repository at this point in the history
EWPP-4796: Fix unit test regarding gallery item value object and TwigExtensionTest::testSmartTrimFilter. Fix phpunit extention class \Drupal\Tests\oe_theme\EnsurePHPUnitBatchingTestExtension.
  • Loading branch information
22Alexandra authored Sep 30, 2024
2 parents f7e2ece + 632ff62 commit 7441d37
Show file tree
Hide file tree
Showing 74 changed files with 141 additions and 115 deletions.
4 changes: 2 additions & 2 deletions modules/oe_theme_contact_forms/oe_theme_contact_forms.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

declare(strict_types=1);

use Drupal\contact\Entity\ContactForm;
use Drupal\contact\MessageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\contact\Entity\ContactForm;
use Drupal\contact\MessageInterface;

/**
* Implements hook_form_FORM_ID_alter() for contact_message_form().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DetailsExtraField extends EventExtraFieldBase {
* @param \Drupal\Core\Render\RendererInterface|null $renderer
* The renderer service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, RendererInterface $renderer = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, ?RendererInterface $renderer = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
$this->entityRepository = $entity_repository;
// Load service statically to provide backward compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function create(ContainerInterface $container, array $configuratio
* @return bool
* True if timestamp is within current day.
*/
protected function isCurrentDay(int $timestamp, string $timezone = NULL): bool {
protected function isCurrentDay(int $timestamp, ?string $timezone = NULL): bool {
$current_date = $this->dateFormatter->format($this->requestDateTime->getTimestamp(), 'custom', 'Ymd', $timezone);
$start_day = $this->dateFormatter->format($timestamp, 'custom', 'Ymd', $timezone);
return $current_date === $start_day;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Drupal\Tests\oe_theme_content_event\FunctionalJavascript;

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
* Test information disclosing for time-sensitive fields.
Expand Down
2 changes: 1 addition & 1 deletion modules/oe_theme_helper/oe_theme_helper.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

declare(strict_types=1);

use Drupal\block\Entity\Block;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\block\Entity\Block;

/**
* Show the page header block on the homepage.
Expand Down
2 changes: 1 addition & 1 deletion modules/oe_theme_helper/oe_theme_helper.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

declare(strict_types=1);

use Drupal\block\Entity\Block;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\block\Entity\Block;
use Drupal\image\Entity\ImageStyle;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SiteNavigationBlock extends SystemMenuBlock {
* @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail
* The active menu trail service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_tree, ?MenuActiveTrailInterface $menu_active_trail = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $menu_tree, $menu_active_trail);
$this->configFactory = $config_factory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Drupal\oe_theme_helper\Plugin\Field\FieldFormatter;

use CommerceGuys\Addressing\Locale;
use Drupal\Core\Render\Element;
use Drupal\address\AddressInterface;
use Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter;
use Drupal\Core\Render\Element;

/**
* Format an address with locale format but divide only with 3 lines.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Drupal\oe_theme_helper\Plugin\Field\FieldFormatter;

use Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter;

/**
* Format country inline with locale format and a configurable separator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Drupal\oe_theme_helper\Plugin\Field\FieldFormatter;

use CommerceGuys\Addressing\Locale;
use Drupal\address\AddressInterface;
use Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\address\AddressInterface;
use Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter;

/**
* Format an address inline with locale format and a configurable separator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Drupal\Tests\oe_theme_helper\Functional;

use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\filter\Entity\FilterFormat;

/**
* Tests the base metadata class for node view routes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_theme_helper\Functional;

use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\BrowserTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Drupal\Tests\oe_theme_helper\Functional\Plugin\field_group;

use Behat\Mink\Element\NodeElement;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_group\Functional\FieldGroupTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
* Test In-page navigation field group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Drupal\Tests\oe_theme_helper\Functional\Plugin\field_group;

use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_group\Functional\FieldGroupTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
* Test the pattern field group formatter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\oe_theme_helper\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait;
use Drupal\ckeditor5\Plugin\Editor\CKEditor5;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Symfony\Component\Validator\ConstraintViolation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Drupal\Tests\oe_theme_helper\FunctionalJavascript;

use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\oe_theme\PatternAssertions\InPageNavigationAssert;
use Drupal\filter\Entity\FilterFormat;

/**
* Test Inpage navigation block plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Drupal\Tests\oe_theme_helper\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Tests\oe_theme\PatternAssertions\InPageNavigationAssert;
use Drupal\filter\Entity\FilterFormat;
use Drupal\paragraphs\Entity\Paragraph;

/**
* Test Inpage navigation in the content row paragraph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Drupal\Tests\oe_theme_helper\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\ckeditor\Traits\CKEditorTestTrait;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Drupal\Tests\oe_theme_helper\Kernel;

use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Drupal\editor\EditorInterface;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;

/**
* Tests the conditions for the CKEditor 5 table plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\Tests\address\Kernel\Formatter\FormatterTestBase;
use Drupal\entity_test\Entity\EntityTestMul;

/**
* Test AddressCountryInlineFormatter plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\Tests\address\Kernel\Formatter\FormatterTestBase;
use Drupal\entity_test\Entity\EntityTestMul;

/**
* Test AddressInlineFormatter plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\Component\Utility\UrlHelper;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;

/**
* Tests the featured media formatter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\media\Entity\Media;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Symfony\Component\DomCrawler\Crawler;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\media\Entity\Media;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Drupal\media\Entity\Media;

/**
* Base class for formatters rendering media thumbnail URLs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Drupal\Tests\oe_theme_helper\Kernel\Plugin\Field\FieldFormatter;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase;

/**
* Base test class for "Social media links" field formatters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_theme_helper\Kernel;

use Drupal\Tests\token\Kernel\TokenKernelTestBase;
use Drupal\Tests\Traits\Core\Image\ToolkitTestTrait;
use Drupal\Tests\token\Kernel\TokenKernelTestBase;

/**
* Tests that the Retina Scale effect upscales images appropriately.
Expand Down
10 changes: 10 additions & 0 deletions modules/oe_theme_helper/tests/src/Kernel/TwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\Tests\oe_theme_helper\Kernel;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\GeneratedLink;
use Drupal\Core\Render\Markup;
use Drupal\Core\Render\RenderContext;
Expand Down Expand Up @@ -70,6 +71,15 @@ public function testSmartTrimFilter(array $variables, array $assertions, array $
* An array of test data arrays with assertions.
*/
public function smartTrimFilterDataProvider(): array {
$cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);

$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);

return [
'Trim a string' => [
'variables' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\oe_theme_helper\Unit;

use Drupal\oe_theme_helper\Plugin\Filter\FilterEclTable;
use Drupal\Tests\UnitTestCase;
use Drupal\oe_theme_helper\Plugin\Filter\FilterEclTable;

/**
* Test FilterEclTable plugin.
Expand Down
4 changes: 2 additions & 2 deletions modules/oe_theme_helper/tests/src/Unit/TwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\Renderer;
use Drupal\Core\Template\Loader\StringLoader;
use Drupal\Tests\UnitTestCase;
use Drupal\oe_theme_helper\EuropeanUnionLanguages;
use Drupal\oe_theme_helper\ExternalLinksInterface;
use Drupal\oe_theme_helper\TwigExtension\TwigExtension;
use Drupal\Tests\UnitTestCase;
use Twig\Environment;
use Twig\Error\RuntimeError;

Expand Down Expand Up @@ -287,7 +287,7 @@ protected static function getEuropeanUnionLanguageList(): array {
* @covers ::toEclIcon
* @dataProvider toEclIconProvider
*/
public function testToEclIcon(string $icon_name, array $expected_icon_array, string $size = NULL) {
public function testToEclIcon(string $icon_name, array $expected_icon_array, ?string $size = NULL) {
$context = [
'ecl_icon_path' => '/path/to/theme/resources/icons/',
'ecl_icon_social_media_path' => '/path/to/theme/resources/social-media-icons/',
Expand Down
2 changes: 1 addition & 1 deletion oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

declare(strict_types=1);

use Drupal\block\BlockInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
Expand All @@ -20,6 +19,7 @@ use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
use Drupal\block\BlockInterface;
use Drupal\media\MediaInterface;
use Drupal\media\Plugin\media\Source\Image;
use Drupal\media\Plugin\media\Source\OEmbed;
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObject/DateValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DateValueObject extends ValueObjectBase implements DateValueObjectInterfac
* @param string|null $timezone
* Timezone string, e.g. "Europe/Brussels".
*/
private function __construct(int $start, int $end = NULL, string $timezone = NULL) {
private function __construct(int $start, ?int $end = NULL, ?string $timezone = NULL) {
$this->start = DrupalDateTime::createFromTimestamp($start, $timezone);

if ($end !== NULL) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Behat/DrupalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Behat\Testwork\Hook\Scope\AfterSuiteScope;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\oe_content\Traits\EntityLoadingTrait;
use Drupal\language\Entity\ConfigurableLanguage;

/**
* Provides Drupal-related Behat steps.
Expand Down
Loading

0 comments on commit 7441d37

Please sign in to comment.