Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Guzzle request options configurable #655

Merged
merged 8 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ jobs:
fail-fast: false
matrix:
php_version: ["7.4", "8.0", "8.1", "8.2"]
drupal_version: ["9", "10"]
drupal_version: ["9", "10.0", "10.1"]
exclude:
- php_version: "7.4"
drupal_version: "10"
drupal_version: "10.0"
- php_version: "7.4"
drupal_version: "10.1"
- php_version: "8.0"
drupal_version: "10.0"
- php_version: "8.0"
drupal_version: "10"
drupal_version: "10.1"
- php_version: "8.2"
drupal_version: "9"
env:
Expand All @@ -37,7 +41,7 @@ jobs:
- name: copy fixtures
run: docker-compose exec -T php cp -r fixtures/drupal/modules/behat_test drupal/modules
- name: drush pmu page_cache
run: docker-compose exec -T php ./vendor/bin/drush --yes --root=drupal pmu page_cache
run: docker-compose exec -T php ./vendor/bin/drush --yes --root=drupal pmu page_cache,big_pipe
- name: drush en behat_test
run: docker-compose exec -T php ./vendor/bin/drush --yes --root=drupal en behat_test
- name: npm test
Expand All @@ -46,5 +50,12 @@ jobs:
run: docker-compose exec -T php composer test
- name: behat --profile=blackbox
run: docker-compose exec -T php vendor/bin/behat -fprogress --strict
- name: behat --profile=drupal
run: docker-compose exec -T php cat && docker-compose exec -T php vendor/bin/behat -fprogress --profile=drupal --strict
- name: behat --profile=drupal9
if: "${{ matrix.drupal_version == '9'}}"
run: docker-compose exec -T php cat && docker-compose exec -T php vendor/bin/behat -fprogress --profile=drupal9 --strict
- name: behat --profile=drupal10
if: "${{ matrix.drupal_version != '9'}}"
run: docker-compose exec -T php cat && docker-compose exec -T php vendor/bin/behat -fprogress --profile=drupal10 --strict
- name: behat --profile=drupal_https
if: "${{ matrix.drupal_version != '9'}}"
run: docker-compose exec -T php cat && docker-compose exec -T php vendor/bin/behat -fprogress --profile=drupal_https --strict
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
* [#655](https://github.com/jhedstrom/drupalextension/pull/655) Configure Guzzle request options
## [5.0.0 rc1]
### Fixed
* [#629](https://github.com/jhedstrom/drupalextension/pull/629) Fix upstream Drupal getText issue.
Expand Down
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ the [Full documentation](https://behat-drupal-extension.readthedocs.org)
minimal configuration. Many more options are covered in the
[Full documentation](https://behat-drupal-extension.readthedocs.org)

``` yaml
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
extensions:
Drupal\MinkExtension:
browserkit_http: ~
base_url: http://example.org/ # Replace with your site's URL
Drupal\DrupalExtension:
blackbox: ~
``` yaml
default:
suites:
default:
contexts:
- Drupal\DrupalExtension\Context\DrupalContext
extensions:
Drupal\MinkExtension:
# Guzzle is used as HTTP client. You can configure the Guzzle request
# options by setting `browserkit_http.guzzle_request_options`. For
# instance the following configuration will disable SSL peer verification:
# browserkit_http:
# guzzle_request_options:
# verify: false
# See \GuzzleHttp\RequestOptions for all built-in Guzzle request options
browserkit_http: ~
base_url: http://example.org/ # Replace with your site's URL
Drupal\DrupalExtension:
blackbox: ~
```

1. In the projectdir, run
Expand Down
53 changes: 50 additions & 3 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default:
success_message_selector: '.messages.status'
warning_message_selector: '.messages.warning'

drupal:
drupal9:
suites:
default:
contexts:
Expand All @@ -42,10 +42,10 @@ drupal:
- Drupal\DrupalExtension\Context\MailContext
- Drupal\DrupalExtension\Context\RandomContext
filters:
tags: "~@blackbox&&~@wip"
tags: "~@blackbox&&~@wip&&~@d10"
extensions:
Drupal\MinkExtension:
base_url: http://drupal
base_url: http://proxy
files_path: /var/www/html/fixtures/files
Drupal\DrupalExtension:
api_driver: "drupal"
Expand All @@ -55,3 +55,50 @@ drupal:
main content: "#main"
selectors:
error_message_selector: '.messages--error'

drupal10:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\ConfigContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MarkupContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\MailContext
- Drupal\DrupalExtension\Context\RandomContext
filters:
tags: "~@blackbox&&~@wip&&~@d9"
extensions:
Drupal\MinkExtension:
base_url: http://proxy
files_path: /var/www/html/fixtures/files
Drupal\DrupalExtension:
api_driver: "drupal"
drupal:
drupal_root: "/var/www/html/drupal"
region_map:
main content: "#main"
selectors:
error_message_selector: '.messages--error'

drupal_https:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
filters:
tags: "@https"
extensions:
Drupal\MinkExtension:
base_url: https://proxy
browserkit_http:
guzzle_request_options:
verify: false
Drupal\DrupalExtension:
api_driver: "drupal"
drupal:
drupal_root: "/var/www/html/drupal"
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"require-dev": {
"composer/installers": "^2",
"drupal/coder": "^8.3",
"drupal/core": "^9.4 || ^10.0",
"drupal/core-composer-scaffold": "^9.4 || ^10.0",
"drush/drush": "^11.0",
"drupal/core": "^10",
"drupal/core-composer-scaffold": "^10",
"drush/drush": "^11.6.0 || ^12.4",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpspec/phpspec": "^4.0 || ^6.0 || ^7.0"
},
Expand Down
46 changes: 36 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,58 @@ services:
PHP_IDE_CONFIG: "serverName=drupalextension"
volumes:
- ./:/var/www/html
labels:
- "traefik.enable=false"
depends_on:
- proxy

proxy:
image: traefik:v2.10
command:
- "--api.insecure=true"
- "--providers.docker"
- "--entrypoints.http-80.address=:80"
- "--entrypoints.http-443.address=:443"
ports:
- "80:80"
- "443:443"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=false"

drupal:
image: wodby/nginx:1.16-5.11.3
image: wodby/nginx
depends_on:
- php
environment:
NGINX_STATIC_OPEN_FILE_CACHE: "off"
NGINX_ERROR_LOG_LEVEL: debug
NGINX_BACKEND_HOST: php
NGINX_SERVER_ROOT: /var/www/html/drupal
NGINX_VHOST_PRESET: drupal9
NGINX_VHOST_PRESET: drupal10
volumes:
- ./:/var/www/html
ports:
- "8080:80"
labels:
- "traefik.http.routers.drupal.rule=Host(`proxy`)"
- "traefik.http.routers.drupal.entrypoints=http-80"
- "traefik.http.routers.drupal-secure.rule=Host(`proxy`)"
- "traefik.http.routers.drupal-secure.tls=true"
- "traefik.http.routers.drupal-secure.entrypoints=http-443"

blackbox:
image: wodby/nginx:1.16-5.11.3
image: wodby/nginx
environment:
NGINX_STATIC_OPEN_FILE_CACHE: "off"
NGINX_ERROR_LOG_LEVEL: debug
NGINX_SERVER_ROOT: /var/www/html/fixtures/blackbox
NGINX_VHOST_PRESET: html
volumes:
- ./:/var/www/html
ports:
- "8081:80"
labels:
- "traefik.enable=false"

db:
image: wodby/mariadb:10.3-3.8.4
Expand All @@ -56,6 +81,8 @@ services:
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
labels:
- "traefik.enable=false"

node:
image: node:latest
Expand All @@ -67,6 +94,5 @@ services:
volumes:
- ./:/home/node/app
command: "sleep infinity"

volumes:
codebase:
labels:
- "traefik.enable=false"
12 changes: 11 additions & 1 deletion features/d8.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ Feature: DrupalContext
As a developer
I need to use the step definitions of this context

Scenario: Target links within table rows
@d9
Scenario: Target links within table rows (Drupal 9)
Given I am logged in as a user with the "administrator" role
When I am at "admin/structure/types"
And I click "Manage fields" in the "Article" row
Then I should be on "admin/structure/types/manage/article/fields"
And I should see the link "Add field"

@d10
@https
Scenario: Target links within table rows (Drupal 10)
Given I am logged in as a user with the "administrator" role
When I am at "admin/structure/types"
And I click "Manage fields" in the "Article" row
Then I should be on "admin/structure/types/manage/article/fields"
And I should see the link "Create a new field"

Scenario: Create users with roles
Given users:
| name | mail | roles |
Expand Down
11 changes: 10 additions & 1 deletion features/i18n/es/d8.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ Característica: DrupalContext
Cuando hago click en "My account"
Entonces debo ver el texto "Member for"

Escenario: Enlaces dentro de filas de tablas
@d9
Escenario: Enlaces dentro de filas de tablas (Drupal 9)
Dado que estoy conectado como un "administrator"
Cuando estoy en la URL "admin/structure/types"
Y hago click en el enlace "Manage fields" de la fila "Article"
Entonces debo estar en "admin/structure/types/manage/article/fields"
Y debo ver el enlace "Add field"

@d10
Escenario: Enlaces dentro de filas de tablas (Drupal 10)
Dado que estoy conectado como un "administrator"
Cuando estoy en la URL "admin/structure/types"
Y hago click en el enlace "Manage fields" de la fila "Article"
Entonces debo estar en "admin/structure/types/manage/article/fields"
Y debo ver el enlace "Create a new field"

Escenario: Cear usuarios con roles
Dados usuarios:
| name | mail | roles |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Behat\MinkExtension\ServiceContainer\Driver\BrowserKitFactory as BrowserKitFactoryOriginal;
use Behat\Mink\Driver\BrowserKitDriver;
use DrupalFinder\DrupalFinder;
use GuzzleHttp\Client;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;

class BrowserKitFactory extends BrowserKitFactoryOriginal
Expand All @@ -31,9 +33,32 @@ public function buildDriver(array $config): Definition
);
}

$guzzleRequestOptions = $config['guzzle_request_options'] ?? [
'allow_redirects' => false,
'cookies' => true,
];

$guzzleClientService = new Definition(Client::class, [$guzzleRequestOptions]);
$testBrowserService = (new Definition('Drupal\Tests\DrupalTestBrowser'))
->addMethodCall('setClient', [$guzzleClientService]);

return new Definition(BrowserKitDriver::class, [
new Definition('Drupal\Tests\DrupalTestBrowser'),
$testBrowserService,
'%mink.base_url%',
]);
}

/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder): void
{
$builder->
children()->
arrayNode('guzzle_request_options')->
prototype('variable')->end()->
info("Guzzle request options. See \\GuzzleHttp\\RequestOptions. Defaults to ['allow_redirects' => false, 'cookies' => true].")->
end()->
end();
}
}