Issue #3422383 by longwave, mondrake: Convert remaining data providers to static methods

(cherry picked from commit 96ab747a7c)
merge-requests/7879/head
catch 2024-05-01 17:42:39 +01:00
parent 60b7fbf05a
commit 51d40866c9
12 changed files with 47 additions and 47 deletions

View File

@ -166,7 +166,7 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase {
*/
public function getBlockTests() {
$blocks = [];
foreach ($this->getTestThemes() as $theme) {
foreach (static::getTestThemes() as $theme) {
$blocks += [
"$theme: block-powered" => [
'theme' => $theme,
@ -233,7 +233,7 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase {
*/
public function testEditModeEnableDisable() {
$this->markTestSkipped("Skipped due to frequent random test failures. See https://www.drupal.org/project/drupal/issues/3317520");
foreach ($this->getTestThemes() as $theme) {
foreach (static::getTestThemes() as $theme) {
$this->enableTheme($theme);
$block = $this->placeBlock('system_powered_by_block');
foreach (['contextual_link', 'toolbar_link'] as $enable_option) {
@ -270,7 +270,7 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase {
public function testValidationMessages() {
$page = $this->getSession()->getPage();
$web_assert = $this->assertSession();
foreach ($this->getTestThemes() as $theme) {
foreach (static::getTestThemes() as $theme) {
$this->enableTheme($theme);
$block = $this->placeBlock('settings_tray_test_validation');
$this->drupalGet('user');

View File

@ -156,7 +156,7 @@ class SettingsTrayTestBase extends OffCanvasTestBase {
/**
* {@inheritdoc}
*/
protected function getTestThemes() {
protected static function getTestThemes() {
// Remove 'claro' theme. Settings Tray "Edit Mode" will not work with this
// theme because it removes all contextual links.
return array_filter(parent::getTestThemes(), function ($theme) {

View File

@ -125,7 +125,7 @@ class OffCanvasTest extends OffCanvasTestBase {
$web_assert = $this->assertSession();
// Test the same functionality on multiple themes.
foreach ($this->getTestThemes() as $theme) {
foreach (static::getTestThemes() as $theme) {
$this->enableTheme($theme);
// Testing at the wider width.
$this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);

View File

@ -107,7 +107,7 @@ abstract class OffCanvasTestBase extends WebDriverTestBase {
* @return string[]
* Theme names to test.
*/
protected function getTestThemes() {
protected static function getTestThemes() {
return ['claro', 'olivero', 'stable9', 'stark'];
}
@ -130,8 +130,8 @@ abstract class OffCanvasTestBase extends WebDriverTestBase {
/**
* Data provider that returns theme name as the sole argument.
*/
public function themeDataProvider() {
$themes = $this->getTestThemes();
public static function themeDataProvider() {
$themes = static::getTestThemes();
$data = [];
foreach ($themes as $theme) {
$data[$theme] = [

View File

@ -89,7 +89,7 @@ trait UpdateSemverTestSecurityAvailabilityTrait {
* - 8.0.1 Insecure
* - 8.0.0 Insecure
*/
public function securityUpdateAvailabilityProvider() {
public static function securityUpdateAvailabilityProvider() {
$test_cases = [
// Security release available for site minor release 0.
// No releases for next minor.

View File

@ -87,7 +87,7 @@ class UpdateCalculateProjectDataTest extends KernelTestBase {
* @return array[]
* Test data.
*/
public function providerProjectStatus(): array {
public static function providerProjectStatus(): array {
return [
'revoked' => [
'fixture' => '/../../fixtures/release-history/drupal.project_status.revoked.0.2.xml',

View File

@ -44,7 +44,7 @@ class NumericFilterTest extends UnitTestCase {
* @return array[]
* The test cases.
*/
public function provideAcceptExposedInput(): array {
public static function provideAcceptExposedInput(): array {
// [$options, $value, $expected]
return [
// Not exposed by default. Bypass parsing and return true.

View File

@ -236,7 +236,7 @@ class ElementTest extends UnitTestCase {
);
}
public function dataProviderIsRenderArray() {
public static function dataProviderIsRenderArray() {
return [
'valid markup render array' => [['#markup' => 'hello world'], TRUE],
'invalid "foo" string' => [['foo', '#markup' => 'hello world'], FALSE],

View File

@ -44,7 +44,7 @@ class RendererTest extends RendererTestBase {
public function testRenderBasic($build, $expected, callable $setup_code = NULL) {
if (isset($setup_code)) {
$setup_code = $setup_code->bindTo($this);
$setup_code();
$setup_code($this->themeManager);
}
if (isset($build['#markup'])) {
@ -63,7 +63,7 @@ class RendererTest extends RendererTestBase {
*
* @return array
*/
public function providerTestRenderBasic() {
public static function providerTestRenderBasic() {
$data = [];
// Part 1: the most simplistic render arrays possible, none using #theme.
@ -266,10 +266,10 @@ class RendererTest extends RendererTestBase {
'#theme_wrappers' => ['container'],
'#attributes' => ['class' => ['baz']],
];
$setup_code_type_link = function () {
$this->themeManager->expects($this->exactly(2))
$setup_code_type_link = function ($themeManager) {
$themeManager->expects(static::exactly(2))
->method('render')
->with($this->logicalOr('common_test_foo', 'container'))
->with(static::logicalOr('common_test_foo', 'container'))
->willReturnCallback(function ($theme, $vars) {
if ($theme == 'container') {
return '<div' . (string) (new Attribute($vars['#attributes'])) . '>' . $vars['#children'] . "</div>\n";
@ -293,10 +293,10 @@ class RendererTest extends RendererTestBase {
'#url' => 'https://www.drupal.org',
'#title' => 'bar',
];
$setup_code_type_link = function () {
$this->themeManager->expects($this->exactly(2))
$setup_code_type_link = function ($themeManager) {
$themeManager->expects(static::exactly(2))
->method('render')
->with($this->logicalOr('link', 'container'))
->with(static::logicalOr('link', 'container'))
->willReturnCallback(function ($theme, $vars) {
if ($theme == 'container') {
return '<div' . (string) (new Attribute($vars['#attributes'])) . '>' . $vars['#children'] . "</div>\n";
@ -332,8 +332,8 @@ class RendererTest extends RendererTestBase {
'container',
],
];
$setup_code = function () {
$this->themeManager->expects($this->exactly(2))
$setup_code = function ($themeManager) {
$themeManager->expects(static::exactly(2))
->method('render')
->with('container')
->willReturnCallback(function ($theme, $vars) {
@ -347,8 +347,8 @@ class RendererTest extends RendererTestBase {
'#theme_wrappers' => [['container']],
'#attributes' => ['class' => ['foo']],
];
$setup_code = function () {
$this->themeManager->expects($this->once())
$setup_code = function ($themeManager) {
$themeManager->expects(static::once())
->method('render')
->with(['container'])
->willReturnCallback(function ($theme, $vars) {
@ -364,10 +364,10 @@ class RendererTest extends RendererTestBase {
'#theme' => ['suggestion_not_implemented'],
'#markup' => 'foo',
];
$setup_code = function () {
$this->themeManager->expects($this->once())
$setup_code = function ($themeManager) {
$themeManager->expects(static::once())
->method('render')
->with(['suggestion_not_implemented'], $this->anything())
->with(['suggestion_not_implemented'], static::anything())
->willReturn(FALSE);
};
$data[] = [$build, 'foo', $setup_code];
@ -379,10 +379,10 @@ class RendererTest extends RendererTestBase {
'#markup' => 'foo',
],
];
$setup_code = function () {
$this->themeManager->expects($this->once())
$setup_code = function ($themeManager) {
$themeManager->expects(static::once())
->method('render')
->with(['suggestion_not_implemented'], $this->anything())
->with(['suggestion_not_implemented'], static::anything())
->willReturn(FALSE);
};
$data[] = [$build, 'foo', $setup_code];
@ -392,11 +392,11 @@ class RendererTest extends RendererTestBase {
'#theme' => ['common_test_empty'],
'#markup' => 'foo',
];
$theme_function_output = $this->randomContextValue();
$setup_code = function () use ($theme_function_output) {
$this->themeManager->expects($this->once())
$theme_function_output = static::randomContextValue();
$setup_code = function ($themeManager) use ($theme_function_output) {
$themeManager->expects(static::once())
->method('render')
->with(['common_test_empty'], $this->anything())
->with(['common_test_empty'], static::anything())
->willReturn($theme_function_output);
};
$data[] = [$build, $theme_function_output, $setup_code];
@ -420,10 +420,10 @@ class RendererTest extends RendererTestBase {
'#children' => 'baz',
'child' => ['#markup' => 'boo'],
];
$setup_code = function () {
$this->themeManager->expects($this->once())
$setup_code = function ($themeManager) {
$themeManager->expects(static::once())
->method('render')
->with('common_test_foo', $this->anything())
->with('common_test_foo', static::anything())
->willReturn('foobar');
};
$data[] = [$build, 'foobar', $setup_code];
@ -439,8 +439,8 @@ class RendererTest extends RendererTestBase {
'#markup' => 'boo',
],
];
$setup_code = function () {
$this->themeManager->expects($this->never())
$setup_code = function ($themeManager) {
$themeManager->expects(static::never())
->method('render');
};
$data[] = [$build, 'boo', $setup_code];
@ -455,8 +455,8 @@ class RendererTest extends RendererTestBase {
'#markup' => 'boo',
],
];
$setup_code = function () {
$this->themeManager->expects($this->never())
$setup_code = function ($themeManager) {
$themeManager->expects(static::never())
->method('render');
};
$data[] = [$build, 'baz', $setup_code];
@ -474,8 +474,8 @@ class RendererTest extends RendererTestBase {
'#markup' => 'kitten',
],
];
$setup_code = function () {
$this->themeManager->expects($this->never())
$setup_code = function ($themeManager) {
$themeManager->expects(static::never())
->method('render');
};
$data[] = [$build, 'kitten', $setup_code];

View File

@ -86,7 +86,7 @@ class SuperUserAccessPolicyTest extends UnitTestCase {
* @return array
* A list of test scenarios.
*/
public function calculatePermissionsProvider(): array {
public static function calculatePermissionsProvider(): array {
$cases['is-super-user'] = [1, TRUE];
$cases['is-normal-user'] = [2, FALSE];
return $cases;
@ -122,7 +122,7 @@ class SuperUserAccessPolicyTest extends UnitTestCase {
* @return array
* A list of test scenarios.
*/
public function alterPermissionsProvider(): array {
public static function alterPermissionsProvider(): array {
$cases['is-super-user'] = [1];
$cases['is-normal-user'] = [2];
return $cases;

View File

@ -124,7 +124,7 @@ class UserRolesAccessPolicyTest extends UnitTestCase {
* @return array
* A list of test scenarios.
*/
public function calculatePermissionsProvider(): array {
public static function calculatePermissionsProvider(): array {
$cases['no-roles'] = [
'roles' => [],
'expect_admin_rights' => FALSE,

View File

@ -41,7 +41,7 @@ final class OliveroHexToHslTest extends UnitTestCase {
* @return array[]
* The test data.
*/
public function hexCodes(): array {
public static function hexCodes(): array {
return [
'Blue Lagoon' => ['#1b9ae4', [202, 79, 50]],
'Firehouse' => ['#a30f0f', [0, 83, 35]],