Commit 609e7442 authored by catch's avatar catch
Browse files

Issue #3353658 by mondrake, smustgrave: [PHPUnit 10] Provide a static...

Issue #3353658 by mondrake, smustgrave: [PHPUnit 10] Provide a static alternative to randomMachineName() and implement in data providers
parent 19d08d31
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\RendererInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\TestTools\Random;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -84,7 +85,7 @@ public function testHtmlResponse(array $attachments) {
    $this->assertEquals('processed', $processed_big_pipe_response->getContent(), 'Content of returned (processed) response object MUST be changed.');
  }

  public function attachmentsProvider() {
  public static function attachmentsProvider() {
    $typical_cases = [
      'no attachments' => [[]],
      'libraries' => [['library' => ['core/drupal']]],
@@ -94,16 +95,16 @@ public function attachmentsProvider() {
    $official_attachment_types = ['html_head', 'feed', 'html_head_link', 'http_header', 'library', 'placeholders', 'drupalSettings', 'html_response_attachment_placeholders'];
    $official_attachments_with_random_values = [];
    foreach ($official_attachment_types as $type) {
      $official_attachments_with_random_values[$type] = $this->randomMachineName();
      $official_attachments_with_random_values[$type] = Random::machineName();
    }
    $random_attachments = ['random' . $this->randomMachineName() => $this->randomMachineName()];
    $random_attachments = ['random' . Random::machineName() => Random::machineName()];
    $edge_cases = [
      'all official attachment types, with random assigned values, even if technically not valid, to prove BigPipeResponseAttachmentsProcessor is a perfect decorator' => [$official_attachments_with_random_values],
      'random attachment type (unofficial), with random assigned value, to prove BigPipeResponseAttachmentsProcessor is a perfect decorator' => [$random_attachments],
    ];

    $big_pipe_placeholder_attachments = ['big_pipe_placeholders' => [$this->randomMachineName()]];
    $big_pipe_nojs_placeholder_attachments = ['big_pipe_nojs_placeholders' => [$this->randomMachineName()]];
    $big_pipe_placeholder_attachments = ['big_pipe_placeholders' => [Random::machineName()]];
    $big_pipe_nojs_placeholder_attachments = ['big_pipe_nojs_placeholders' => [Random::machineName()]];
    $big_pipe_cases = [
      'only big_pipe_placeholders' => [$big_pipe_placeholder_attachments],
      'only big_pipe_nojs_placeholders' => [$big_pipe_nojs_placeholder_attachments],
+1 −1
Original line number Diff line number Diff line
@@ -638,7 +638,7 @@ public function testAdminBookNodeListing() {

    // Saving a book page not as the current version shouldn't effect the book.
    $old_title = $nodes[1]->getTitle();
    $new_title = $this->randomGenerator->name();
    $new_title = $this->getRandomGenerator()->name();
    $nodes[1]->isDefaultRevision(FALSE);
    $nodes[1]->setNewRevision(TRUE);
    $nodes[1]->setTitle($new_title);
+3 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
use Drupal\KernelTests\KernelTestBase;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\TestTools\Random;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
@@ -1046,8 +1047,8 @@ public function testProvidedElementsInvalidElementSubset(array $configured_subse
   * @return array
   *   Test scenarios.
   */
  public function providerProvidedElementsInvalidElementSubset(): array {
    $random_tag_name = strtolower($this->randomMachineName());
  public static function providerProvidedElementsInvalidElementSubset(): array {
    $random_tag_name = strtolower(Random::machineName());
    $random_tag = "<$random_tag_name>";
    return [
      'superset: random tag not listed in the plugin definition' => [
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\TestTools\Random;
use Symfony\Component\Yaml\Yaml;

/**
@@ -96,8 +97,8 @@ public function test(string $drupal_langcode, string $cke5_langcode, bool $is_mi
   *
   * @return string[][]
   */
  public function provider(): array {
    $random_langcode = $this->randomMachineName();
  public static function provider(): array {
    $random_langcode = Random::machineName();
    return [
      'Language code transformed from browser mappings' => [
        'drupal_langcode' => 'pt-pt',
+7 −6
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\UnitTestCase;
use Drupal\TestTools\Random;

/**
 * @coversDefaultClass \Drupal\language\Entity\ContentLanguageSettings
@@ -148,8 +149,8 @@ public function testDefaultLangcode(ContentLanguageSettings $config, $expected)
    $this->assertSame($expected, $config->getDefaultLangcode());
  }

  public function providerDefaultLangcode() {
    $langcode = $this->randomMachineName();
  public static function providerDefaultLangcode() {
    $langcode = Random::machineName();
    $config = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_bundle',
@@ -211,7 +212,7 @@ public function testIsDefaultConfiguration(ContentLanguageSettings $config, $exp
    $this->assertSame($expected, $config->isDefaultConfiguration());
  }

  public function providerIsDefaultConfiguration() {
  public static function providerIsDefaultConfiguration() {
    $alteredLanguage = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_bundle',
@@ -222,7 +223,7 @@ public function providerIsDefaultConfiguration() {
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_fixed_language_bundle',
    ], 'language_content_settings');
    $alteredDefaultLangcode->setDefaultLangcode($this->randomMachineName());
    $alteredDefaultLangcode->setDefaultLangcode(Random::machineName());

    $defaultConfig = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
@@ -278,14 +279,14 @@ public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $
    $this->assertSame($expected_language_alterable, $config->isLanguageAlterable());
  }

  public function providerLoadByEntityTypeBundle() {
  public static function providerLoadByEntityTypeBundle() {
    $alteredLanguage = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_bundle',
    ], 'language_content_settings');
    $alteredLanguage->setLanguageAlterable(TRUE);

    $langcode = $this->randomMachineName();
    $langcode = Random::machineName();
    $alteredDefaultLangcode = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_fixed_language_bundle',
Loading