From 338c96bc29887131e09c67a1db7e723480bd5598 Mon Sep 17 00:00:00 2001 From: David McGregor Date: Wed, 8 Jul 2020 16:40:14 +1000 Subject: [PATCH 1/5] Allow file upload for file fields in YAML. Allow setting am image alt tag in YAML --- src/Driver/Cores/Drupal8.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Driver/Cores/Drupal8.php b/src/Driver/Cores/Drupal8.php index 00e0f09..13d8ac1 100644 --- a/src/Driver/Cores/Drupal8.php +++ b/src/Driver/Cores/Drupal8.php @@ -245,6 +245,11 @@ public function entityCreate($entity_type, $values, $save = TRUE) { break; case 'image': + $image_data = explode(';', $value); + $entity->{$name}->setValue(['target_id' => $this->saveFile($image_data[0])->id(), 'alt' => @$image_data[1]]); + break; + + case 'file': $entity->{$name}->setValue(['target_id' => $this->saveFile($value)->id()]); break; } From 3d1bcdbfd08d04a88c8b035fb7ebd63eb244719b Mon Sep 17 00:00:00 2001 From: David McGregor Date: Wed, 2 Dec 2020 05:01:05 +0000 Subject: [PATCH 2/5] Add link type --- src/Driver/Cores/Drupal8.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Driver/Cores/Drupal8.php b/src/Driver/Cores/Drupal8.php index 13d8ac1..5a29ba2 100644 --- a/src/Driver/Cores/Drupal8.php +++ b/src/Driver/Cores/Drupal8.php @@ -252,6 +252,11 @@ public function entityCreate($entity_type, $values, $save = TRUE) { case 'file': $entity->{$name}->setValue(['target_id' => $this->saveFile($value)->id()]); break; + + case 'link': + $link_data = explode(';', $value); + $entity->{$name}->setValue(['uri' => $link_data[0], 'title' => @$link_data[1]]); + break; } } From 94841f519f3bb94446bb73d0e7778284d9796d7a Mon Sep 17 00:00:00 2001 From: Eduardo Morales Date: Mon, 7 Mar 2022 11:45:16 +0100 Subject: [PATCH 3/5] Issue #59: Allow any type of entity on step add translation to content entity --- src/DrupalExtension/Context/ContentContext.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/DrupalExtension/Context/ContentContext.php b/src/DrupalExtension/Context/ContentContext.php index aac9c8a..9c3dc70 100644 --- a/src/DrupalExtension/Context/ContentContext.php +++ b/src/DrupalExtension/Context/ContentContext.php @@ -192,15 +192,18 @@ public function assertContent(PyStringNode $string) { * The title to identify the content by. * @param \Behat\Gherkin\Node\PyStringNode $string * The text in yaml format that represents the translation. + * @param string $type + * Type of entity, by default is node. * * @Given the following translation for :content_type content :title: + * @Given the following translation for :type :content_type content :title: */ - public function assertTranslation($content_type, $title, PyStringNode $string) { + public function assertTranslation($content_type, $title, PyStringNode $string, $type = 'node') { $values = $this->getYamlParser()->parse($string); Assert::keyExists($values, 'langcode', __METHOD__ . ": Required field 'langcode' not found."); - $nid = $this->getCore()->getEntityIdByLabel('node', $content_type, $title); - $source = $this->getCore()->entityLoad('node', $nid); + $entity_id = $this->getCore()->getEntityIdByLabel($type, $content_type, $title); + $source = $this->getCore()->entityLoad($type, $entity_id); $this->getCore()->entityAddTranslation($source, $values['langcode'], $values); } From d37cb2260176093ab0640c728469356c123fe6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Andor?= Date: Tue, 11 Jul 2023 14:47:25 +0200 Subject: [PATCH 4/5] Issue #49 - Disable access checking when querying for entities --- src/Driver/Cores/Drupal8.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Driver/Cores/Drupal8.php b/src/Driver/Cores/Drupal8.php index 498048b..fdc07d0 100644 --- a/src/Driver/Cores/Drupal8.php +++ b/src/Driver/Cores/Drupal8.php @@ -58,6 +58,7 @@ public function convertLabelToTermTypeId($type) { */ public function loadNodeByName($title) { $result = \Drupal::entityQuery('node') + ->accessCheck(FALSE) ->condition('title', $title) ->condition('status', NodeInterface::PUBLISHED) ->range(0, 1) @@ -148,6 +149,7 @@ public function getNodeId($node) { */ public function loadTaxonomyTermByName($type, $name) { $result = \Drupal::entityQuery('taxonomy_term') + ->accessCheck(FALSE) ->condition('name', $name) ->condition('vid', $type) ->range(0, 1) From 1e9636645a43ea14051f916a43339e107d8c098f Mon Sep 17 00:00:00 2001 From: Eduardo Morales Date: Tue, 31 Oct 2023 11:23:42 +0100 Subject: [PATCH 5/5] Cover symfony mailer --- src/Driver/Cores/CoreInterface.php | 16 ++++++++ src/Driver/Cores/Drupal8.php | 16 ++++++++ src/DrupalExtension/Context/EmailContext.php | 43 ++++++++++++++++---- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/Driver/Cores/CoreInterface.php b/src/Driver/Cores/CoreInterface.php index b225728..cb9ad4d 100644 --- a/src/Driver/Cores/CoreInterface.php +++ b/src/Driver/Cores/CoreInterface.php @@ -229,4 +229,20 @@ public function state(); */ public function getEditableConfig($name); + /** + * Enable module. + * + * @param string $name + * The name of the module to enable. + */ + public function enableModule(string $name); + + /** + * Disable module. + * + * @param string $name + * The name of the module to disable. + */ + public function disableModule(string $name); + } diff --git a/src/Driver/Cores/Drupal8.php b/src/Driver/Cores/Drupal8.php index 8a039c1..aa3ac93 100644 --- a/src/Driver/Cores/Drupal8.php +++ b/src/Driver/Cores/Drupal8.php @@ -450,4 +450,20 @@ protected function saveFile($source) { return $file; } + /** + * {@inheritdoc} + */ + public function enableModule(string $name) { + $installer = \Drupal::service('module_installer'); + $installer->install([$name]); + } + + /** + * {@inheritdoc} + */ + public function disableModule(string $name) { + $installer = \Drupal::service('module_installer'); + $installer->uninstall([$name]); + } + } diff --git a/src/DrupalExtension/Context/EmailContext.php b/src/DrupalExtension/Context/EmailContext.php index 9dab43a..69b272b 100644 --- a/src/DrupalExtension/Context/EmailContext.php +++ b/src/DrupalExtension/Context/EmailContext.php @@ -17,13 +17,13 @@ class EmailContext extends RawDrupalContext { /** * Current mailsystem settings. * - * @var string + * @var array * Email address. * * @see FeatureContext::beforeScenarioEmail() * @see FeatureContext::afterScenarioEmail() */ - protected $mailsystem = ''; + protected $mailsystem = []; /** * Current contact settings. @@ -49,8 +49,11 @@ class EmailContext extends RawDrupalContext { */ public function assertEmailSentToRecipient($recipient) { $last_mail = $this->getLastEmail(); - if ($last_mail['to'] != $recipient) { - throw new \Exception("Unexpected recipient: " . $last_mail['to']); + $recipients = []; + $recipients = $last_mail['to'] ? array_merge($recipients, [$last_mail['to']]) : $recipients; + $recipients = $last_mail['params']['bcc_mail'] ? array_merge(explode(',', $last_mail['params']['bcc_mail']), $recipients) : $recipients; + if (!in_array($recipient, $recipients)) { + throw new \Exception("Unexpected recipient: " . implode(',', $recipients)); } } @@ -73,9 +76,21 @@ public function assertEmailSentWithProperties(TableNode $table) { * @BeforeScenario @email */ public function beforeScenarioEmail(BeforeScenarioScope $scope) { - $mailsystem = $this->getCore()->getEditableConfig('mailsystem.settings'); - $this->mailsystem = $mailsystem->get('defaults'); - $mailsystem->set('defaults.sender', 'test_mail_collector')->save(); + $module_list = $this->getCore()->getModuleList(); + if (in_array('symfony_mailer', $module_list)) { + $this->getCore()->enableModule('symfony_mailer_test'); + } elseif (in_array('mailsystem', $module_list)) { + $mailsystem = $this->getCore()->getEditableConfig('mailsystem.settings'); + $this->mailsystem = $mailsystem->get('defaults'); + $mailsystem->set('defaults.sender', 'test_mail_collector')->save(); + } else { + $system_mail = $this->getCore()->getEditableConfig('system.mail'); + $this->mailsystem['sender'] = $system_mail->get('interface.default'); + $system_mail + ->set('interface.default', 'test_mail_collector') + ->save(); + } + $this->getCore()->state()->set('system.test_mail_collector', []); } @@ -85,8 +100,18 @@ public function beforeScenarioEmail(BeforeScenarioScope $scope) { * @AfterScenario @email */ public function afterScenarioEmail(AfterScenarioScope $scope) { - $mailsystem = $this->getCore()->getEditableConfig('mailsystem.settings'); - $mailsystem->set('defaults.sender', $this->mailsystem['sender'])->save(); + $module_list = $this->getCore()->getModuleList(); + if (in_array('symfony_mailer', $module_list)) { + $this->getCore()->disableModule('symfony_mailer_test'); + } elseif (in_array('mailsystem', $module_list)) { + $mailsystem = $this->getCore()->getEditableConfig('mailsystem.settings'); + $mailsystem->set('defaults.sender', $this->mailsystem['sender'])->save(); + } else { + $system_mail = $this->getCore()->getEditableConfig('system.mail'); + $system_mail + ->set('interface.default', $this->mailsystem['sender']) + ->save(); + } } /**