Commit 5b5c83ab authored by catch's avatar catch

Issue #3131223 by jungle, mondrake, longwave: Replace assertions involving...

Issue #3131223 by jungle, mondrake, longwave: Replace assertions involving calls to array_key_exists() with assertArrayHasKey()/assertArrayNotHasKey()

(cherry picked from commit 54f84c2b)
parent 3590225a
......@@ -226,7 +226,7 @@ public function testFormatterUI() {
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$display = $display_storage->loadUnchanged($display_id);
$component = $display->getComponent('field_test');
$this->assertFalse(array_key_exists('field_third_party_test', $component['third_party_settings']));
$this->assertArrayNotHasKey('field_third_party_test', $component['third_party_settings']);
}
/**
......
......@@ -70,7 +70,7 @@ public function testNumericStyleName() {
$this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', ['%name' => $style_label]));
$options = image_style_options();
$this->assertTrue(array_key_exists($style_name, $options), new FormattableMarkup('Array key %key exists.', ['%key' => $style_name]));
$this->assertArrayHasKey($style_name, $options);
}
/**
......
......@@ -552,8 +552,8 @@ public function testContentCustomization() {
$this->assertTrue(in_array('language_content', $config->get('configurable')), 'Content language is configurable.');
// Ensure configuration was saved.
$this->assertFalse(array_key_exists('language-url', $config->get('negotiation.language_content.enabled')), 'URL negotiation is not enabled for content.');
$this->assertTrue(array_key_exists('language-session', $config->get('negotiation.language_content.enabled')), 'Session negotiation is enabled for content.');
$this->assertArrayNotHasKey('language-url', $config->get('negotiation.language_content.enabled'));
$this->assertArrayHasKey('language-session', $config->get('negotiation.language_content.enabled'));
}
/**
......
......@@ -263,10 +263,10 @@ public function testNodeAccessLanguageAwareCombination() {
// Four nodes should be returned with public Hungarian translations or the
// no language public node.
$this->assertEqual(count($nids), 4, 'Query returns 4 nodes when no langcode is specified.');
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is full public node.');
$this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
$this->assertTrue(array_key_exists($this->nodes['public_no_language_public']->id(), $nids), 'Returned node ID is no language public node.');
$this->assertArrayHasKey($this->nodes['public_both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['public_ca_private']->id(), $nids);
$this->assertArrayHasKey($this->nodes['private_both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['public_no_language_public']->id(), $nids);
// Query with Hungarian (hu) specified.
$select = $connection->select('node', 'n')
......@@ -278,9 +278,9 @@ public function testNodeAccessLanguageAwareCombination() {
// Three nodes should be returned (with public Hungarian translations).
$this->assertEqual(count($nids), 3, 'Query returns 3 nodes.');
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.');
$this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
$this->assertArrayHasKey($this->nodes['public_both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['public_ca_private']->id(), $nids);
$this->assertArrayHasKey($this->nodes['private_both_public']->id(), $nids);
// Query with Catalan (ca) specified.
$select = $connection->select('node', 'n')
......@@ -292,9 +292,9 @@ public function testNodeAccessLanguageAwareCombination() {
// Three nodes should be returned (with public Catalan translations).
$this->assertEqual(count($nids), 3, 'Query returns 3 nodes.');
$this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.');
$this->assertTrue(array_key_exists($this->nodes['public_hu_private']->id(), $nids), 'Returned node ID is Catalan public only node.');
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
$this->assertArrayHasKey($this->nodes['public_both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['public_hu_private']->id(), $nids);
$this->assertArrayHasKey($this->nodes['private_both_public']->id(), $nids);
// Query with German (de) specified.
$select = $connection->select('node', 'n')
......
......@@ -206,9 +206,9 @@ public function testNodeAccessLanguageAware() {
// - Node with only the Catalan translation marked as private.
// - No language node marked as public.
$this->assertEqual(count($nids), 3, '$connection->select() returns 3 nodes when no langcode is specified.');
$this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.');
$this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.');
$this->assertTrue(array_key_exists($this->nodes['no_language_public']->id(), $nids), 'The node with no language is returned.');
$this->assertArrayHasKey($this->nodes['both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['ca_private']->id(), $nids);
$this->assertArrayHasKey($this->nodes['no_language_public']->id(), $nids);
// Query with Hungarian (hu) specified.
$select = $connection->select('node', 'n')
......@@ -221,8 +221,8 @@ public function testNodeAccessLanguageAware() {
// Two nodes should be returned: the node with both translations public, and
// the node with only the Catalan translation marked as private.
$this->assertEqual(count($nids), 2, 'Query returns 2 nodes when the hu langcode is specified.');
$this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.');
$this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.');
$this->assertArrayHasKey($this->nodes['both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['ca_private']->id(), $nids);
// Query with Catalan (ca) specified.
$select = $connection->select('node', 'n')
......@@ -235,8 +235,8 @@ public function testNodeAccessLanguageAware() {
// Two nodes should be returned: the node with both translations public, and
// the node with only the Hungarian translation marked as private.
$this->assertEqual(count($nids), 2, 'Query returns 2 nodes when the hu langcode is specified.');
$this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.');
$this->assertTrue(array_key_exists($this->nodes['hu_private']->id(), $nids), 'The node with only the Hungarian translation private is returned.');
$this->assertArrayHasKey($this->nodes['both_public']->id(), $nids);
$this->assertArrayHasKey($this->nodes['hu_private']->id(), $nids);
// Query with German (de) specified.
$select = $connection->select('node', 'n')
......
......@@ -215,8 +215,8 @@ public function testNodeAccessQueryTag() {
// The public node and no language node should be returned. Because no
// langcode is given it will use the fallback node.
$this->assertEqual(count($nids), 2, 'Query returns 2 node');
$this->assertTrue(array_key_exists($node_public->id(), $nids), 'Returned node ID is public node.');
$this->assertTrue(array_key_exists($node_no_language->id(), $nids), 'Returned node ID is no language node.');
$this->assertArrayHasKey($node_public->id(), $nids);
$this->assertArrayHasKey($node_no_language->id(), $nids);
// Query the nodes table as the web user with the node access tag and
// langcode de.
......
......@@ -181,8 +181,8 @@ public function testUserNormalize() {
// Test password isn't available.
$normalized = $this->serializer->normalize($this->user);
$this->assertFalse(array_key_exists('pass', $normalized), '"pass" key does not exist in normalized user');
$this->assertFalse(array_key_exists('mail', $normalized), '"mail" key does not exist in normalized user');
$this->assertArrayNotHasKey('pass', $normalized);
$this->assertArrayNotHasKey('mail', $normalized);
// Test again using our test user, so that our access control override will
// allow password viewing.
......
......@@ -46,8 +46,8 @@ public function testUpdateNewDependency() {
// Running the updates enables the dependency.
$this->runUpdates();
$this->assertTrue(array_key_exists('new_dependency_test', $this->container->get('config.factory')->get('core.extension')->get('module')));
$this->assertTrue(array_key_exists('new_dependency_test_with_service', $this->container->get('config.factory')->get('core.extension')->get('module')));
$this->assertArrayHasKey('new_dependency_test', $this->container->get('config.factory')->get('core.extension')->get('module'));
$this->assertArrayHasKey('new_dependency_test_with_service', $this->container->get('config.factory')->get('core.extension')->get('module'));
// Tests that the new services are available and working as expected.
$this->assertEquals('Hello', $this->container->get('new_dependency_test_with_service.service')->greet());
......
......@@ -191,9 +191,9 @@ public function testLoadFunctions() {
$this->assertIdentical(array_keys($all_views_sorted), array_keys(Views::getViewsAsOptions(TRUE, 'all', NULL, FALSE, TRUE)), 'All view id keys returned in expected sort order');
// Test $exclude_view parameter.
$this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', 'archive')), 'View excluded from options based on name');
$this->assertFalse(array_key_exists('archive:default', Views::getViewsAsOptions(FALSE, 'all', 'archive:default')), 'View display excluded from options based on name');
$this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', $archive->getExecutable())), 'View excluded from options based on object');
$this->assertArrayNotHasKey('archive', Views::getViewsAsOptions(TRUE, 'all', 'archive'));
$this->assertArrayNotHasKey('archive:default', Views::getViewsAsOptions(FALSE, 'all', 'archive:default'));
$this->assertArrayNotHasKey('archive', Views::getViewsAsOptions(TRUE, 'all', $archive->getExecutable()));
// Test the $opt_group parameter.
$expected_opt_groups = [];
......
......@@ -69,7 +69,7 @@ public function testPluginData() {
// Check all plugin types.
foreach ($this->pluginTypes as $type) {
$this->assertTrue(array_key_exists($type, $this->definitions), new FormattableMarkup('Key for plugin type @type found.', ['@type' => $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]));
}
......
......@@ -67,7 +67,7 @@ public function testOtherOptions() {
$displays = $view->get('display');
$this->assertTrue(!empty($displays['test_1']), 'Display data found for new display ID key.');
$this->assertIdentical($displays['test_1']['id'], 'test_1', 'New display ID matches the display ID key.');
$this->assertFalse(array_key_exists('attachment_1', $displays), 'Old display ID not found.');
$this->assertArrayNotHasKey('attachment_1', $displays);
// Set to the same machine name and save the View.
$edit = ['display_id' => 'test_1'];
......
......@@ -81,8 +81,8 @@ public function testAddFiles() {
$css = $this->assetResolver->getCssAssets($assets, FALSE);
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/bar.css', $css), 'CSS files are correctly added.');
$this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/foo.js', $js), 'JavaScript files are correctly added.');
$this->assertArrayHasKey('core/modules/system/tests/modules/common_test/bar.css', $css);
$this->assertArrayHasKey('core/modules/system/tests/modules/common_test/foo.js', $js);
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
......@@ -103,8 +103,8 @@ public function testAddJsSettings() {
$this->assertEqual([], $assets->getSettings(), 'JavaScript settings on $assets are empty.');
$javascript = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$this->assertTrue(array_key_exists('currentPath', $javascript['drupalSettings']['data']['path']), 'The current path JavaScript setting is set correctly.');
$this->assertTrue(array_key_exists('currentPath', $assets->getSettings()['path']), 'JavaScript settings on $assets are resolved after retrieving JavaScript assets, and are equal to the returned JavaScript settings.');
$this->assertArrayHasKey('currentPath', $javascript['drupalSettings']['data']['path']);
$this->assertArrayHasKey('currentPath', $assets->getSettings()['path']);
$assets->setSettings(['drupal' => 'rocks', 'dries' => 280342800]);
$javascript = $this->assetResolver->getJsAssets($assets, FALSE)[1];
......@@ -121,8 +121,8 @@ public function testAddExternalFiles() {
$css = $this->assetResolver->getCssAssets($assets, FALSE);
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$this->assertTrue(array_key_exists('http://example.com/stylesheet.css', $css), 'External CSS files are correctly added.');
$this->assertTrue(array_key_exists('http://example.com/script.js', $js), 'External JavaScript files are correctly added.');
$this->assertArrayHasKey('http://example.com/stylesheet.css', $css);
$this->assertArrayHasKey('http://example.com/script.js', $js);
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
......@@ -464,8 +464,8 @@ public function testAddJsFileWithQueryString() {
$css = $this->assetResolver->getCssAssets($assets, FALSE);
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2', $css), 'CSS file with query string is correctly added.');
$this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js), 'JavaScript file with query string is correctly added.');
$this->assertArrayHasKey('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2', $css);
$this->assertArrayHasKey('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js);
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$rendered_css = $this->renderer->renderPlain($css_render_array);
......
......@@ -336,7 +336,7 @@ public function testNoTemplate() {
$entity = $this->createTestEntity('entity_test');
$build = $entity_type_manager->getViewBuilder('entity_test')->view($entity);
$this->assertEquals($entity, $build['#entity_test']);
$this->assertFalse(array_key_exists('#theme', $build));
$this->assertArrayNotHasKey('#theme', $build);
}
}
......@@ -42,8 +42,7 @@ public function testModuleImplementsAlter() {
$this->assertTrue(function_exists('module_test_modules_installed'),
'The file module_test.module was successfully included.');
$this->assertTrue(array_key_exists('module_test', \Drupal::moduleHandler()->getModuleList()),
'module_test is in the module list.');
$this->assertArrayHasKey('module_test', \Drupal::moduleHandler()->getModuleList());
$this->assertTrue(in_array('module_test', \Drupal::moduleHandler()->getImplementations('modules_installed')),
'module_test implements hook_modules_installed().');
......
......@@ -127,13 +127,13 @@ public function testCandidateOutlines() {
$candidates = array_flip($candidates);
$this->assertCount(7, $candidates, 'Correct number of candidates found');
$this->assertTrue(array_key_exists('/node/5/edit', $candidates), 'First candidate found.');
$this->assertTrue(array_key_exists('/node/5/%', $candidates), 'Second candidate found.');
$this->assertTrue(array_key_exists('/node/%/edit', $candidates), 'Third candidate found.');
$this->assertTrue(array_key_exists('/node/%/%', $candidates), 'Fourth candidate found.');
$this->assertTrue(array_key_exists('/node/5', $candidates), 'Fifth candidate found.');
$this->assertTrue(array_key_exists('/node/%', $candidates), 'Sixth candidate found.');
$this->assertTrue(array_key_exists('/node', $candidates), 'Seventh candidate found.');
$this->assertArrayHasKey('/node/5/edit', $candidates);
$this->assertArrayHasKey('/node/5/%', $candidates);
$this->assertArrayHasKey('/node/%/edit', $candidates);
$this->assertArrayHasKey('/node/%/%', $candidates);
$this->assertArrayHasKey('/node/5', $candidates);
$this->assertArrayHasKey('/node/%', $candidates);
$this->assertArrayHasKey('/node', $candidates);
}
/**
......
......@@ -236,7 +236,7 @@ public function testVersion() {
$libraries = $this->libraryDiscoveryParser->buildByExtension('versions');
$this->assertFalse(array_key_exists('version', $libraries['versionless']));
$this->assertArrayNotHasKey('version', $libraries['versionless']);
$this->assertEquals(-1, $libraries['versionless']['css'][0]['version']);
$this->assertEquals(-1, $libraries['versionless']['js'][0]['version']);
......
......@@ -107,7 +107,7 @@ public function testGetMultiple() {
$this->assertSame($ret['t123']->data, 1231, 'Got key 123 and value is from the first backend');
$this->assertSame($ret['t23']->data, 232, 'Got key 23 and value is from the second backend');
$this->assertSame($ret['t3']->data, 33, 'Got key 3 and value is from the third backend');
$this->assertFalse(array_key_exists('t4', $ret), "Didn't get the nonexistent key");
$this->assertArrayNotHasKey('t4', $ret);
$this->assertFalse(in_array('t123', $cids), "Existing key 123 has been removed from &\$cids");
$this->assertFalse(in_array('t23', $cids), "Existing key 23 has been removed from &\$cids");
......
......@@ -200,7 +200,7 @@ public function testCheckAccess() {
$this->assertInstanceOf('\Drupal\Core\Menu\InaccessibleMenuLink', $element->link);
// Menu link 4: child of menu link 3, which was AccessResult::neutral(),
// hence menu link 3's subtree is removed, of which this menu link is one.
$this->assertFalse(array_key_exists(4, $tree[2]->subtree[3]->subtree));
$this->assertArrayNotHasKey(4, $tree[2]->subtree[3]->subtree);
// Menu link 5: no route name, treated as external, hence access granted.
$element = $tree[5];
$this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $element->access);
......
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