Verified Commit 90632d16 authored by Dave Long's avatar Dave Long
Browse files

Issue #3402292 by mstrelan, ankithashetty, dww, smustgrave: Fix strict type...

Issue #3402292 by mstrelan, ankithashetty, dww, smustgrave: Fix strict type errors: Convert FormattableMarkup to strings (simple replacement) in core/tests/Drupal/KernelTests/*

(cherry picked from commit 7835ce45)
parent 7b063440
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\KernelTests\Core\Database;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Schema;
@@ -342,8 +341,8 @@ public function testUnsignedColumns(): void {

    // Finally, check each column and try to insert invalid values into them.
    foreach ($table_spec['fields'] as $column_name => $column_spec) {
      $this->assertTrue($this->schema->fieldExists($table_name, $column_name), new FormattableMarkup('Unsigned @type column was created.', ['@type' => $column_spec['type']]));
      $this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), new FormattableMarkup('Unsigned @type column rejected a negative value.', ['@type' => $column_spec['type']]));
      $this->assertTrue($this->schema->fieldExists($table_name, $column_name), "Unsigned {$column_spec['type']} column was created.");
      $this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), "Unsigned {$column_spec['type']} column rejected a negative value.");
    }
  }

+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\KernelTests\Core\Database;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\PagerSelectExtender;
use Drupal\Core\Database\RowCountException;
@@ -108,7 +107,7 @@ public function testGroupBy() {
    ];

    foreach ($correct_results as $task => $count) {
      $this->assertEquals($count, $records[$task], new FormattableMarkup("Correct number of '@task' records found.", ['@task' => $task]));
      $this->assertEquals($count, $records[$task], "Correct number of '$task' records found.");
    }

    $this->assertEquals(6, $num_records, 'Returned the correct number of total rows.');
@@ -143,7 +142,7 @@ public function testGroupByAndHaving() {
    ];

    foreach ($correct_results as $task => $count) {
      $this->assertEquals($count, $records[$task], new FormattableMarkup("Correct number of '@task' records found.", ['@task' => $task]));
      $this->assertEquals($count, $records[$task], "Correct number of '$task' records found.");
    }

    $this->assertEquals(1, $num_records, 'Returned the correct number of total rows.');
+5 −6
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\KernelTests\Core\Entity;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\entity_test\Entity\EntityTest;
@@ -69,25 +68,25 @@ protected function assertCRUD(string $entity_type, UserInterface $user1): void {
      ->getStorage($entity_type);

    $entities = array_values($storage->loadByProperties(['name' => 'test']));
    $this->assertEquals('test', $entities[0]->name->value, new FormattableMarkup('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type]));
    $this->assertEquals('test', $entities[1]->name->value, new FormattableMarkup('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type]));
    $this->assertEquals('test', $entities[0]->name->value, "$entity_type: Created and loaded entity");
    $this->assertEquals('test', $entities[1]->name->value, "$entity_type: Created and loaded entity");

    // Test loading a single entity.
    $loaded_entity = $storage->load($entity->id());
    $this->assertEquals($entity->id(), $loaded_entity->id(), new FormattableMarkup('%entity_type: Loaded a single entity by id.', ['%entity_type' => $entity_type]));
    $this->assertEquals($entity->id(), $loaded_entity->id(), "$entity_type: Loaded a single entity by id.");

    // Test deleting an entity.
    $entities = array_values($storage->loadByProperties(['name' => 'test2']));
    $entities[0]->delete();
    $entities = array_values($storage->loadByProperties(['name' => 'test2']));
    $this->assertEquals([], $entities, new FormattableMarkup('%entity_type: Entity deleted.', ['%entity_type' => $entity_type]));
    $this->assertEquals([], $entities, "$entity_type: Entity deleted.");

    // Test updating an entity.
    $entities = array_values($storage->loadByProperties(['name' => 'test']));
    $entities[0]->name->value = 'test3';
    $entities[0]->save();
    $entity = $storage->load($entities[0]->id());
    $this->assertEquals('test3', $entity->name->value, new FormattableMarkup('%entity_type: Entity updated.', ['%entity_type' => $entity_type]));
    $this->assertEquals('test3', $entity->name->value, "$entity_type: Entity updated.");

    // Try deleting multiple test entities by deleting all.
    $entities = $storage->loadMultiple();
+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\KernelTests\Core\Entity;

use Drupal\Component\Uuid\Uuid;
use Drupal\Component\Render\FormattableMarkup;

/**
 * Tests default values for entity fields.
@@ -52,8 +51,8 @@ protected function assertDefaultValues(string $entity_type_id): void {
      ->create();
    $definition = $this->entityTypeManager->getDefinition($entity_type_id);
    $langcode_key = $definition->getKey('langcode');
    $this->assertEquals('en', $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Default language', ['%entity_type' => $entity_type_id]));
    $this->assertTrue(Uuid::isValid($entity->uuid->value), new FormattableMarkup('%entity_type: Default UUID', ['%entity_type' => $entity_type_id]));
    $this->assertEquals('en', $entity->{$langcode_key}->value, "$entity_type_id: Default language");
    $this->assertTrue(Uuid::isValid($entity->uuid->value), "$entity_type_id: Default UUID");
    $this->assertEquals([], $entity->name->getValue(), 'Field has one empty value by default.');
  }

+102 −103

File changed.

Preview size limit exceeded, changes collapsed.

Loading