Skip to content

Commit

Permalink
Merge pull request jhedstrom#628 from claudiu-cristea/use-guzzle
Browse files Browse the repository at this point in the history
Use BrowserKit with Guzzle client
  • Loading branch information
jhedstrom authored Nov 18, 2022
2 parents ecc0fc8 + 56471c0 commit af159e0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: composer self-update
run: docker-compose exec -T php composer self-update
- name: composer require
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}
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}
- name: composer install
run: docker-compose exec -T php composer install
- name: drush site-install
Expand Down
1 change: 1 addition & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ drupal:
extensions:
Drupal\MinkExtension:
base_url: http://drupal
files_path: /var/www/html/fixtures/files
Drupal\DrupalExtension:
api_driver: "drupal"
drupal:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
"behat/mink-browserkit-driver": "^2.1.0",
"behat/mink-selenium2-driver": "~1.1",
"drupal/drupal-driver": "dev-master",
"symfony/http-client": "~4.4 || ^5 || ^6"
"symfony/http-client": "~4.4 || ^5 || ^6",
"webflo/drupal-finder": "^1.2"
},
"require-dev": {
"composer/installers": "^2",
"drupal/coder": "^8.3",
"drupal/core-composer-scaffold": "^9.4 || ^10.0",
"drupal/core-recommended": "^9.4 || ^10.0",
"drupal/core": "^9.4 || ^10.0",
"drush/drush": "^11.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpspec/phpspec": "^4.0 || ^6.0 || ^7.0"
Expand Down
13 changes: 13 additions & 0 deletions features/upload.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@api
Feature: Upload test.

Scenario: Upload an image.
Given I am logged in as a user with the "administrator" role

When I go to "/node/add/article"
And I fill in "Title" with "This!"
And I attach the file "image.png" to "files[field_image_0]"
And I press "Upload"
And I fill in "field_image[0][alt]" with "Nothing"
And I press "Save"
Then I should see the heading "This!"
Binary file added fixtures/files/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drupal\MinkExtension\ServiceContainer\Driver;

use Behat\MinkExtension\ServiceContainer\Driver\BrowserKitFactory as BrowserKitFactoryOriginal;
use Behat\Mink\Driver\BrowserKitDriver;
use DrupalFinder\DrupalFinder;
use Symfony\Component\DependencyInjection\Definition;

class BrowserKitFactory extends BrowserKitFactoryOriginal
{
/**
* {@inheritdoc}
*/
public function buildDriver(array $config): Definition
{
if (!class_exists(BrowserKitDriver::class)) {
throw new \RuntimeException(
'Install behat/mink-browserkit-driver in order to use the browserkit_http driver.'
);
}

$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(getcwd());
$drupalRoot = $drupalFinder->getDrupalRoot();
require_once "$drupalRoot/core/tests/Drupal/Tests/DrupalTestBrowser.php";

if (!class_exists('Drupal\Tests\DrupalTestBrowser')) {
throw new \RuntimeException(
'Class Drupal\Tests\DrupalTestBrowser not found'
);
}

return new Definition(BrowserKitDriver::class, [
new Definition('Drupal\Tests\DrupalTestBrowser'),
'%mink.base_url%',
]);
}
}
10 changes: 10 additions & 0 deletions src/Drupal/MinkExtension/ServiceContainer/MinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\MinkExtension\ServiceContainer;

use Behat\MinkExtension\ServiceContainer\MinkExtension as BaseMinkExtension;
use Drupal\MinkExtension\ServiceContainer\Driver\BrowserKitFactory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

class MinkExtension extends BaseMinkExtension
Expand All @@ -15,6 +16,15 @@ class MinkExtension extends BaseMinkExtension
*/
const AJAX_TIMEOUT = 5;

/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct();
$this->registerDriverFactory(new BrowserKitFactory());
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit af159e0

Please sign in to comment.