Skip to content

Commit

Permalink
Merge pull request #211 from mglaman/functional-tests-default-theme
Browse files Browse the repository at this point in the history
New rector: Add $defaultTheme property if missing on BrowserTestBase
  • Loading branch information
bbrala authored Nov 21, 2023
2 parents 4f18bd5 + 96f556a commit 907a929
Show file tree
Hide file tree
Showing 40 changed files with 430 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config/drupal-8/drupal-8.8-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DrupalRector\Drupal8\Rector\Deprecation\DrupalServiceRenameRector;
use DrupalRector\Drupal8\Rector\Deprecation\FileDefaultSchemeRector;
use DrupalRector\Drupal8\Rector\Deprecation\FunctionalTestDefaultThemePropertyRector;
use DrupalRector\Drupal8\Rector\ValueObject\DrupalServiceRenameConfiguration;
use DrupalRector\Rector\Deprecation\FunctionToServiceRector;
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
Expand Down Expand Up @@ -44,4 +45,7 @@
// https://www.drupal.org/node/3075567
new MethodToMethodWithCheckConfiguration('Drupal\Core\Entity\EntityTypeInterface', 'getLowercaseLabel', 'getSingularLabel'),
]);

// https://www.drupal.org/node/3083055
$rectorConfig->rule(FunctionalTestDefaultThemePropertyRector::class);
};
18 changes: 16 additions & 2 deletions docs/rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 49 Rules Overview
# 50 Rules Overview

<br>

## Categories

- [Drupal10](#drupal10) (1)

- [Drupal8](#drupal8) (18)
- [Drupal8](#drupal8) (19)

- [Drupal9](#drupal9) (26)

Expand Down Expand Up @@ -243,6 +243,20 @@ Fixes deprecated file_default_scheme calls

<br>

### FunctionalTestDefaultThemePropertyRector

Adds `$defaultTheme` property to Functional and FunctionalJavascript tests which do not have them.

- class: [`DrupalRector\Drupal8\Rector\Deprecation\FunctionalTestDefaultThemePropertyRector`](../src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php)

```diff
class SomeClassTest {
+ protected $defaultTheme = 'stark'
}
```

<br>

### GetMockRector

Fixes deprecated `getMock()` calls
Expand Down
3 changes: 1 addition & 2 deletions fixtures/d8/rector_examples_updated/db_query.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Drupal\core\Database\Database;
/**
* This demonstrates the deprecated static calls that might be called from procedural code like `.module` files.
*/
Expand All @@ -27,7 +26,7 @@ function placeholder() {
* An example using arguments and options.
*/
function arguments_and_options() {
Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [
\Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [
'fetch' => \PDO::FETCH_OBJ,
'return' => Database::RETURN_STATEMENT,
'throw_exception' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class BrowserTestBaseGetMock extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* A simple example using the class property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertCacheTagTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testAssertCacheTag() {
$this->drupalGet('');
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:block_list');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertElementPresentTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testAssertElementPresent() {
$this->assertSession()->elementExists('css', '.region-content-message.region-empty');
$this->assertSession()->elementNotExists('css', '.region-content-message.region-empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertEqualTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertEquals('Actual', 'Expected', 'Message');
$this->assertNotEquals('Actual', 'Expected', 'Message');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertEscapedTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testAssertElementPresent() {
$this->assertSession()->assertEscaped('Demonstrate block regions (<"Cat" & \'Mouse\'>)');
$this->assertSession()->assertNoEscaped('<div class="escaped">');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertFieldByIdTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testFieldById() {
$this->assertSession()->fieldExists('edit-name');
$this->assertSession()->fieldValueEquals('edit-name', 'Test name');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertFieldByNameTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testFieldByName() {
$this->assertSession()->fieldValueEquals('field_name', 'expected_value');
$this->assertSession()->fieldValueEquals("field_name[0][value][date]", '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertFieldCheckedTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testFieldChecked() {
$this->assertSession()->checkboxChecked('edit-settings-view-mode', 'default');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertFieldTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testField() {
// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
// Change assertion to buttonExists() if checking for a button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertHeaderTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->responseHeaderEquals('Foo', 'Bar');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertIdenticalObjectTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertEquals('Actual', 'Expected', 'Message');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertIdenticalTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSame('Actual', 'Expected', 'Message');
$this->assertNotSame('Actual', 'Expected', 'Message');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertLinkByHrefTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testLinkByHref() {
$this->assertSession()->linkByHrefExists('user/1/translations');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertLinkTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testLink() {
$this->assertSession()->linkExists('Anonymous comment title');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertOptionTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->optionExists('edit-settings-view-mode', 'default');
$this->assertSession()->optionNotExists('edit-settings-view-mode', 'default');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertPatternTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->responseMatches('|<h4[^>]*></h4>|', 'No empty H4 element found.');
$this->assertSession()->responseNotMatches('|<h4[^>]*></h4>|', 'No empty H4 element found.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertRawTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->responseContains('bartik/logo.svg');
$this->assertSession()->responseNotContains('bartik/logo.svg');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertResponseTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->statusCodeEquals(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$foo = TRUE;
$this->assertTrue($foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertTextTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testAssertText() {
$current_content = $this->randomMachineName();
$this->drupalGet('test-page');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertTitleTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->titleEquals('Block layout | Drupal');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertUniqueTextTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testAssertText() {
$this->assertSession()->pageTextContainsOnce('Color set');
$page_text = $this->getSession()->getPage()->getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class AssertUrlTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->assertSession()->addressEquals('myrootuser');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class BuildXpathQueryTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$xpath = $this->assertSession()->buildXPathQuery('//select[@name=:name]', [':name' => $name]);
$fields = $this->xpath($xpath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class ConstructFieldXpathTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->drupalGet('/form-test/select');
$this->getSession()->getPage()->findField('edit-preferred-admin-langcode');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class DrupalPostFormTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* A simple example using the class property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class GetAllOptionsTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

public function testExample() {
$this->drupalGet('/form-test/select');
$this->assertCount(6, $this->cssSelect('select[name="opt_groups"]')[0]->findAll('xpath', '//option'));
Expand Down
Loading

0 comments on commit 907a929

Please sign in to comment.