I've got the following tests written for /core/modules/migrate_drupal_ui/src/Controller/MigrateController.php
with
a new test file /core/modules/migrate_drupal_ui/tests/src/Functional/MigrateControllerTest.php
.
<?php
namespace Drupal\Tests\migrate_drupal_ui\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Provides a base class for testing the Migrate Controller.
*/
abstract class MigrateControllerTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate_drupal_ui', 'views'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$account = $this->drupalCreateUser(['administer views']);
$this->drupalLogin($account);
}
public function testRedirectDestination() {
$this->drupalGet('admin/reports/upgrade');
$this->assertUrl('admin/reports/dblog?type%5B%5D=migrate_drupal_ui');
}
public function testRedirectDestinationWithoutView() {
// Delete the watchdog view
$this->drupalGet('admin/structure/views/view/watchdog/delete');
$this->assertResponse(200);
$this->submitForm([], 'Delete');
$this->assertResponse(200);
$this->testRedirectDestination();
}
}
Following https://www.drupal.org/docs/8/phpunit/phpunit-browser-test-tutorial, an existing test runs as expected with ../vendor/bin/phpunit --filter testMigrateUpgradeReviewPage modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeFormStepsTest.php
.
However, when I do the same for my above test -- ../vendor/bin/phpunit --filter testRedirectDestination modules/migrate_drupal_ui/tests/src/Functional/MigrateControllerTest.php
-- I get
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'modules/migrate_drupal_ui/tests/src/Functional/MigrateControllerTest' could not be found in '/Users/MrWeiner/Sites/DockerSites/testing/web/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateControllerTest.php'. in /Users/MrWeiner/Sites/DockerSites/testing/web/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:102
It looks like a namespace issue but I do not understand why it'd be looking for Class 'modules/migrate_drupal_ui/tests/src/Functional/MigrateControllerTest'
instead of Class 'Drupal\Tests\migrate_drupal_ui\Functional\MigrateControllerTest'
. Do I need to register my test somewhere or do something else to ensure that it's autodiscovered?
Original Question: We've got https://www.drupal.org/files/issues/2019-04-12/adding-custom-access-2904546-24.patch posted in https://www.drupal.org/project/drupal/issues/2904546 with the request "for a functional test with and without that view enabled". The patch itself is very simple so I'd assume that the test would be very simple as well. I just don't have any experience writing tests so I don't really understand what I'd be testing for/asserting here or how to test for both the view existing and not existing.