Skip to content
Snippets Groups Projects

Issue #3155495 Refactor system/Kernel/Theme/ThemeTest::testThemeDataTypes

1 unresolved thread
1 unresolved thread
1 file
+ 11
8
Compare changes
  • Side-by-side
  • Inline
@@ -55,16 +55,19 @@ public function testThemeDataTypes(): void {
@@ -55,16 +55,19 @@ public function testThemeDataTypes(): void {
// theme_test_false is an implemented theme hook so \Drupal::theme() service
// theme_test_false is an implemented theme hook so \Drupal::theme() service
// should return a string or an object that implements MarkupInterface,
// should return a string or an object that implements MarkupInterface,
// even though the theme function itself can return anything.
// even though the theme function itself can return anything.
$types = ['null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => ''];
$types = ['integer' => 1, 'string' => 'foo'];
foreach ($types as $type => $example) {
foreach ($types as $type => $example) {
$output = \Drupal::theme()->render('theme_test_foo', ['foo' => $example]);
$output = \Drupal::theme()->render('theme_test_foo', ['foo' => $example]);
$this->assertTrue($output instanceof MarkupInterface || is_string($output), "\Drupal::theme() returns an object that implements MarkupInterface or a string for data type $type.");
$this->assertInstanceOf(MarkupInterface::class, $output, "\\Drupal::theme()->render() should return an object that implements MarkupInterface for data type '$type'.");
if ($output instanceof MarkupInterface) {
$this->assertEquals($example, $output);
$this->assertSame((string) $example, $output->__toString());
}
}
elseif (is_string($output)) {
// Check that a string is returned when the theme returns an empty string.
    • I had to read this a few times. At first I thought, "// Check a string is returned when the theme should return an empty string." would be better. But I think this can be even simpler.

      Suggested change
      64 // Check that a string is returned when the theme returns an empty string.
      64 // Check that a string is returned for special cases.
Please register or sign in to reply
$this->assertSame('', $output, 'A string will be return when the theme returns an empty string.');
$types = ['null' => NULL, 'false' => FALSE, 'empty_string' => ''];
}
foreach ($types as $type => $example) {
 
$output = \Drupal::theme()->render('theme_test_foo', ['foo' => $example]);
 
$this->assertIsString($output, "\\Drupal::theme()->render() should return a string for data type '$type'.");
 
$this->assertSame('', $output, "\\Drupal::theme()->render() should return an empty string for data type '$type'.");
}
}
// suggestion_not_implemented is not an implemented theme hook so
// suggestion_not_implemented is not an implemented theme hook so
Loading