Commit 9a6a0595 authored by xjm's avatar xjm
Browse files

Issue #3131816 by Spokje, jungle, mondrake, xjm, longwave: Replace assertions...

Issue #3131816 by Spokje, jungle, mondrake, xjm, longwave: Replace assertions involving calls to is_array() with assertIsArray()/assertIsNotArray()

(cherry picked from commit 99cb88d6)
parent f32f77f3
......@@ -64,7 +64,7 @@ protected function assertEntity($id) {
*/
protected function assertComponent($display_id, $component_id, $type, $label, $weight) {
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIsArray($component);
$this->assertIdentical($type, $component['type']);
$this->assertIdentical($label, $component['label']);
$this->assertIdentical($weight, $component['weight']);
......
......@@ -71,7 +71,7 @@ protected function assertEntity($id, $expected_entity_type, $expected_bundle) {
*/
protected function assertComponent($display_id, $component_id, $widget_type, $weight) {
$component = EntityFormDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIsArray($component);
$this->assertIdentical($widget_type, $component['type']);
$this->assertIdentical($weight, $component['weight']);
}
......
......@@ -63,11 +63,11 @@ public function testForumMigration() {
// Tests that the taxonomy_forums entity view display component exists.
$entity_view_display = EntityViewDisplay::load('node.forum.default')->getComponent('taxonomy_forums');
$this->assertTrue(is_array($entity_view_display));
$this->assertIsArray($entity_view_display);
// Tests that the taxonomy_forums entity form display component exists.
$entity_form_display = EntityFormDisplay::load('node.forum.default')->getComponent('taxonomy_forums');
$this->assertTrue(is_array($entity_form_display));
$this->assertIsArray($entity_form_display);
// Test that the taxonomy_forums field has the right value.
$node = Node::load(19);
......
......@@ -1366,7 +1366,7 @@ protected function assert406Response(ResponseInterface $response) {
$this->assertSame(406, $response->getStatusCode());
$actual_link_header = $response->getHeader('Link');
if ($actual_link_header) {
$this->assertTrue(is_array($actual_link_header));
$this->assertIsArray($actual_link_header);
$expected_type = explode(';', static::$mimeType)[0];
$this->assertStringContainsString('?_format=' . static::$format . '>; rel="alternate"; type="' . $expected_type . '"', $actual_link_header[0]);
$this->assertStringContainsString('?_format=foobar>; rel="alternate"', $actual_link_header[0]);
......
......@@ -50,7 +50,7 @@ public function testVocabularyEntityDisplay() {
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = EntityViewDisplay::load('node.sponsor.default')->getComponent('field_type');
$this->assertTrue(is_array($field_type));
$this->assertIsArray($field_type);
}
/**
......
......@@ -55,7 +55,7 @@ public function testVocabularyEntityFormDisplay() {
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = EntityFormDisplay::load('node.sponsor.default')->getComponent('field_type');
$this->assertTrue(is_array($field_type));
$this->assertIsArray($field_type);
}
/**
......
......@@ -175,7 +175,9 @@ public function testRenderAreaToken() {
// Test the list of available tokens.
$available = $empty_handler->getAvailableGlobalTokens();
foreach (['site', 'view'] as $type) {
$this->assertTrue(!empty($available[$type]) && is_array($available[$type]));
$this->assertNotEmpty($available[$type]);
$this->assertIsArray($available[$type]);
// Test that each item exists in the list.
foreach ($available[$type] as $token => $info) {
$this->assertText("[$type:$token]");
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\views\Kernel;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\views\Views;
use Drupal\views\Plugin\views\PluginBase;
......@@ -65,12 +64,13 @@ protected function setUp($import_test_views = TRUE): void {
*/
public function testPluginData() {
// Check that we have an array of data.
$this->assertTrue(is_array($this->definitions), 'Plugin data is an array.');
$this->assertIsArray($this->definitions);
// Check all plugin types.
foreach ($this->pluginTypes as $type) {
$this->assertArrayHasKey($type, $this->definitions);
$this->assertTrue(is_array($this->definitions[$type]) && !empty($this->definitions[$type]), new FormattableMarkup('Plugin type @type has an array of plugins.', ['@type' => $type]));
$this->assertIsArray($this->definitions[$type]);
$this->assertNotEmpty($this->definitions[$type], "Plugin type '$type' should contain plugins.");
}
// Tests that the plugin list has not missed any types.
......
......@@ -170,7 +170,9 @@ protected function displayTests() {
$view->save();
$values = $this->config('views.view.test_view_storage_new_new2')->get();
$this->assertTrue(isset($values['display']['test']) && is_array($values['display']['test']), 'New display was saved.');
// Verify that the display was saved by ensuring it contains an array of
// values in the view data.
$this->assertIsArray($values['display']['test']);
}
/**
......
......@@ -432,7 +432,7 @@ public function testDynamicLibrary() {
\Drupal::state()->set('common_test.library_info_build_test', TRUE);
$library_discovery->clearCachedDefinitions();
$dynamic_library = $library_discovery->getLibraryByName('common_test', 'dynamic_library');
$this->assertTrue(is_array($dynamic_library));
$this->assertIsArray($dynamic_library);
$this->assertArrayHasKey('version', $dynamic_library);
$this->assertSame('1.0', $dynamic_library['version']);
// Make sure the dynamic library definition could be altered.
......
......@@ -541,7 +541,7 @@ public function testTypedDataMaps() {
$this->assertNull($typed_data->getValue());
$typed_data->setValue([]);
$value = $typed_data->getValue();
$this->assertTrue(isset($value) && is_array($value));
$this->assertIsArray($value);
// Test accessing invalid properties.
$typed_data->setValue($value);
......
......@@ -40,7 +40,7 @@ public function testNestedArraysWithNestedAnnotation()
$this->assertEquals(3, count($annot->foo));
$this->assertEquals(1, $annot->foo[0]);
$this->assertEquals(2, $annot->foo[1]);
$this->assertTrue(is_array($annot->foo[2]));
$this->assertIsArray($annot->foo[2]);
$nestedArray = $annot->foo[2];
$this->assertTrue(isset($nestedArray['key']));
......@@ -62,13 +62,13 @@ public function testBasicAnnotations()
$result = $parser->parse('@Name(foo={"key1" = "value1"})');
$annot = $result[0];
$this->assertNull($annot->value);
$this->assertTrue(is_array($annot->foo));
$this->assertIsArray($annot->foo);
$this->assertTrue(isset($annot->foo['key1']));
// Numerical arrays
$result = $parser->parse('@Name({2="foo", 4="bar"})');
$annot = $result[0];
$this->assertTrue(is_array($annot->value));
$this->assertIsArray($annot->value);
$this->assertEquals('foo', $annot->value[2]);
$this->assertEquals('bar', $annot->value[4]);
$this->assertFalse(isset($annot->value[0]));
......@@ -80,7 +80,7 @@ public function testBasicAnnotations()
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertTrue(is_array($annot->value));
$this->assertIsArray($annot->value);
$this->assertInstanceOf(Name::class, $annot->value[0]);
$this->assertInstanceOf(Name::class, $annot->value[1]);
......@@ -89,9 +89,9 @@ public function testBasicAnnotations()
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertTrue(is_array($annot->value));
$this->assertIsArray($annot->value);
$this->assertInstanceOf(Name::class, $annot->value[0]);
$this->assertTrue(is_array($annot->value[1]));
$this->assertIsArray($annot->value[1]);
$this->assertEquals('value1', $annot->value[1]['key1']);
$this->assertEquals('value2', $annot->value[1]['key2']);
......@@ -122,7 +122,7 @@ public function testDefaultValueAnnotations()
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertTrue(is_array($annot->value));
$this->assertIsArray($annot->value);
$this->assertEquals('value1', $annot->value['key1']);
// Array as first value and additional values
......@@ -130,7 +130,7 @@ public function testDefaultValueAnnotations()
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertTrue(is_array($annot->value));
$this->assertIsArray($annot->value);
$this->assertEquals('value1', $annot->value['key1']);
$this->assertEquals('bar', $annot->foo);
}
......@@ -1108,7 +1108,8 @@ class A {
try {
$parser = $this->createTestParser();
$result = $parser->parse($docblock);
$this->assertTrue(is_array($result) && empty($result));
$this->assertIsArray($result);
$this->assertEmpty($result);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
......@@ -1130,7 +1131,8 @@ class A {
try {
$parser = $this->createTestParser();
$result = $parser->parse($docblock);
$this->assertTrue(is_array($result) && empty($result));
$this->assertIsArray($result);
$this->assertEmpty($result);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment