-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
230 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Run module tests | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
RUN: [1, 2, 3] | ||
include: | ||
- RUN: 1 | ||
DRUPAL_TESTING_COMPOSER_PROJECT: 'drupal/recommended-project' | ||
DRUPAL_TESTING_DRUPAL_VERSION: '~8.7.0' | ||
- RUN: 2 | ||
DRUPAL_TESTING_COMPOSER_PROJECT: 'drupal/recommended-project' | ||
DRUPAL_TESTING_DRUPAL_VERSION: '*' | ||
- RUN: 3 | ||
DRUPAL_TESTING_COMPOSER_PROJECT: 'thunder/thunder-project' | ||
DRUPAL_TESTING_DRUPAL_VERSION: '~8.8.0' | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- uses: shivammathur/setup-php@master | ||
with: | ||
coverage: none | ||
php-version: '7.3' | ||
|
||
- name: Cache composer dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.composer/cache | ||
key: ${{ runner.os }}-composer-cache-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer-cache- | ||
|
||
- name: Cache NPM dependencies | ||
id: npm-cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-npm-cache | ||
restore-keys: ${{ runner.os }}-npm-cache | ||
|
||
- name: Setup environment variables | ||
run: | | ||
echo "::add-path::$HOME/.composer/vendor/bin" | ||
echo "::add-path::$GITHUB_WORKSPACE/vendor/bin" | ||
echo "::add-path::$GITHUB_WORKSPACE/bin" | ||
- name: Run tests | ||
run: test-drupal-project | ||
env: | ||
DRUPAL_TESTING_TEST_CODING_STYLES: false | ||
DRUPAL_TESTING_PROJECT_BASEDIR: ${{ github.workspace }}/tests/module | ||
DRUPAL_TESTING_COMPOSER_PROJECT: ${{ matrix.DRUPAL_TESTING_COMPOSER_PROJECT }} | ||
DRUPAL_TESTING_DRUPAL_VERSION: ${{ matrix.DRUPAL_TESTING_DRUPAL_VERSION }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "thunder/module", | ||
"description": "Drupal module with all sorts of tests, to test capabilities of the drupal-testing package.", | ||
"type": "drupal-module", | ||
"license": "GPL-2.0-or-later", | ||
"require": { | ||
"php": ">=7.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: Module | ||
type: module | ||
description: Drupal module with all sorts of tests, to test capabilities of the drupal-testing package. | ||
package: Drupal Testing | ||
core: 8.x | ||
core_version_requirement: ^8 || ^9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.example: | ||
path: '/module/controller' | ||
defaults: | ||
_title: 'Example' | ||
_controller: '\Drupal\module\Controller\ModuleController::build' | ||
requirements: | ||
_permission: 'access content' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
module.service: | ||
class: Drupal\module\Service | ||
arguments: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Drupal\module\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
|
||
/** | ||
* Returns responses for module routes. | ||
*/ | ||
class ModuleController extends ControllerBase { | ||
|
||
/** | ||
* Builds the response. | ||
*/ | ||
public function build() { | ||
|
||
$build['content'] = [ | ||
'#type' => 'item', | ||
'#markup' => $this->t('It works!'), | ||
]; | ||
|
||
return $build; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Drupal\module; | ||
|
||
/** | ||
* The Service class. | ||
* | ||
* @package Drupal\module | ||
*/ | ||
class Service { | ||
|
||
/** | ||
* Serve the service. | ||
* | ||
* @param int $number | ||
* A number we do things with. | ||
* | ||
* @return string | ||
* Information based on the given number. | ||
*/ | ||
public function serve(int $number): string { | ||
return 'You have been served a ' . $number; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
tests/module/tests/FunctionalJavascript/ModuleControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\module\FunctionalJavascript; | ||
|
||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase; | ||
|
||
/** | ||
* Class ModuleControllerTest. | ||
* | ||
* Javascript tests. | ||
* | ||
* @group module | ||
*/ | ||
class ModuleControllerTest extends WebDriverTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = ['module']; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->drupalLogin($this->drupalCreateUser([ | ||
'access content', | ||
])); | ||
} | ||
|
||
/** | ||
* Test enhanced entity revision routes access. | ||
*/ | ||
public function testControllerRoute(): void { | ||
$this->drupalGet('/module/controller'); | ||
$this->assertSession()->pageTextContains('It works!'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\module\Unit; | ||
|
||
use Drupal\module\Service; | ||
use Drupal\Tests\UnitTestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Drupal\module\Service | ||
* @group module | ||
*/ | ||
class ModuleServiceTest extends UnitTestCase { | ||
/** | ||
* The entity permission provider. | ||
* | ||
* @var \Drupal\module\Service | ||
*/ | ||
protected $service; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->service = new Service(); | ||
} | ||
|
||
/** | ||
* @covers ::serve | ||
* | ||
* @dataProvider numberProvider | ||
*/ | ||
public function testServe($number, $serving): void { | ||
$this->assertEquals($serving, $this->service->serve($number)); | ||
} | ||
|
||
/** | ||
* Data provider for testServe(). | ||
* | ||
* @return array | ||
* A list of number and the servings they generate. | ||
*/ | ||
public function numberProvider(): array { | ||
return [ | ||
[1, 'You have been served a 1'], | ||
]; | ||
} | ||
|
||
} |