Skip to content

Commit af159e0

Browse files
authored
Merge pull request #628 from claudiu-cristea/use-guzzle
Use BrowserKit with Guzzle client
2 parents ecc0fc8 + 56471c0 commit af159e0

File tree

7 files changed

+67
-3
lines changed

7 files changed

+67
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: composer self-update
2828
run: docker-compose exec -T php composer self-update
2929
- name: composer require
30-
run: docker-compose exec -u ${DOCKER_USER_ID} -T php composer require --no-interaction --dev --no-update drupal/core-recommended:^${DRUPAL_VERSION} drupal/core-composer-scaffold:^${DRUPAL_VERSION}
30+
run: docker-compose exec -u ${DOCKER_USER_ID} -T php composer require --no-interaction --dev --no-update drupal/core:^${DRUPAL_VERSION} drupal/core-composer-scaffold:^${DRUPAL_VERSION}
3131
- name: composer install
3232
run: docker-compose exec -T php composer install
3333
- name: drush site-install

behat.yml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ drupal:
4646
extensions:
4747
Drupal\MinkExtension:
4848
base_url: http://drupal
49+
files_path: /var/www/html/fixtures/files
4950
Drupal\DrupalExtension:
5051
api_driver: "drupal"
5152
drupal:

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
"behat/mink-browserkit-driver": "^2.1.0",
2828
"behat/mink-selenium2-driver": "~1.1",
2929
"drupal/drupal-driver": "dev-master",
30-
"symfony/http-client": "~4.4 || ^5 || ^6"
30+
"symfony/http-client": "~4.4 || ^5 || ^6",
31+
"webflo/drupal-finder": "^1.2"
3132
},
3233
"require-dev": {
3334
"composer/installers": "^2",
3435
"drupal/coder": "^8.3",
3536
"drupal/core-composer-scaffold": "^9.4 || ^10.0",
36-
"drupal/core-recommended": "^9.4 || ^10.0",
37+
"drupal/core": "^9.4 || ^10.0",
3738
"drush/drush": "^11.0",
3839
"php-parallel-lint/php-parallel-lint": "^1.3",
3940
"phpspec/phpspec": "^4.0 || ^6.0 || ^7.0"

features/upload.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@api
2+
Feature: Upload test.
3+
4+
Scenario: Upload an image.
5+
Given I am logged in as a user with the "administrator" role
6+
7+
When I go to "/node/add/article"
8+
And I fill in "Title" with "This!"
9+
And I attach the file "image.png" to "files[field_image_0]"
10+
And I press "Upload"
11+
And I fill in "field_image[0][alt]" with "Nothing"
12+
And I press "Save"
13+
Then I should see the heading "This!"

fixtures/files/image.png

67 Bytes
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Drupal\MinkExtension\ServiceContainer\Driver;
4+
5+
use Behat\MinkExtension\ServiceContainer\Driver\BrowserKitFactory as BrowserKitFactoryOriginal;
6+
use Behat\Mink\Driver\BrowserKitDriver;
7+
use DrupalFinder\DrupalFinder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
10+
class BrowserKitFactory extends BrowserKitFactoryOriginal
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function buildDriver(array $config): Definition
16+
{
17+
if (!class_exists(BrowserKitDriver::class)) {
18+
throw new \RuntimeException(
19+
'Install behat/mink-browserkit-driver in order to use the browserkit_http driver.'
20+
);
21+
}
22+
23+
$drupalFinder = new DrupalFinder();
24+
$drupalFinder->locateRoot(getcwd());
25+
$drupalRoot = $drupalFinder->getDrupalRoot();
26+
require_once "$drupalRoot/core/tests/Drupal/Tests/DrupalTestBrowser.php";
27+
28+
if (!class_exists('Drupal\Tests\DrupalTestBrowser')) {
29+
throw new \RuntimeException(
30+
'Class Drupal\Tests\DrupalTestBrowser not found'
31+
);
32+
}
33+
34+
return new Definition(BrowserKitDriver::class, [
35+
new Definition('Drupal\Tests\DrupalTestBrowser'),
36+
'%mink.base_url%',
37+
]);
38+
}
39+
}

src/Drupal/MinkExtension/ServiceContainer/MinkExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\MinkExtension\ServiceContainer;
44

55
use Behat\MinkExtension\ServiceContainer\MinkExtension as BaseMinkExtension;
6+
use Drupal\MinkExtension\ServiceContainer\Driver\BrowserKitFactory;
67
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
78

89
class MinkExtension extends BaseMinkExtension
@@ -15,6 +16,15 @@ class MinkExtension extends BaseMinkExtension
1516
*/
1617
const AJAX_TIMEOUT = 5;
1718

19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public function __construct()
23+
{
24+
parent::__construct();
25+
$this->registerDriverFactory(new BrowserKitFactory());
26+
}
27+
1828
/**
1929
* {@inheritdoc}
2030
*/

0 commit comments

Comments
 (0)