Commit 6abefc59 authored by catch's avatar catch
Browse files

Issue #3059332 by alexpott, Mile23, Lendude: Mark kernel tests that perform no assertions as risky

parent db82a8e5
......@@ -85,6 +85,7 @@ public function providerSource() {
/**
* @expectedDeprecation Book is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.x. Use \Drupal\book\Plugin\migrate\source\Book instead. See https://www.drupal.org/node/2947487 for more information.
* @doesNotPerformAssertions
*/
public function testDeprecatedPlugin() {
new D6Book(
......
......@@ -107,6 +107,10 @@ public function testDatetimeSerialization() {
$form_id = $form_builder->getFormId($this, $form_state);
$form = $form_builder->retrieveForm($form_id, $form_state);
$form_builder->prepareForm($form_id, $form, $form_state);
// Set up $form_state so that the form is properly submitted.
$form_state->setUserInput(['form_id' => $form_id]);
$form_state->setProgrammed();
$form_state->setSubmitted();
$form_builder->processForm($form_id, $form, $form_state);
}
......
......@@ -3,7 +3,6 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -166,18 +165,13 @@ public function testFieldPluginDefinitionAvailability() {
protected function checkDisplayOption($entity_type_id, $field_id, BaseFieldDefinition $field_definition, DiscoveryInterface $plugin_manager, $display_context) {
$display_options = $field_definition->getDisplayOptions($display_context);
if (!empty($display_options['type'])) {
try {
$plugin_manager->getDefinition($display_options['type']);
}
catch (PluginNotFoundException $e) {
$this->fail(sprintf(
'PluginNotFoundException here for "%s" field %s display options of "%s" entity type. Original message: %s',
$field_id,
$display_context,
$entity_type_id,
$e->getMessage()
));
}
$plugin = $plugin_manager->getDefinition($display_options['type'], FALSE);
$this->assertNotNull($plugin, sprintf(
'Plugin found for "%s" field %s display options of "%s" entity type.',
$field_id,
$display_context,
$entity_type_id)
);
}
}
......
......@@ -21,9 +21,7 @@ class LanguageDependencyInjectionTest extends LanguageTestBase {
public function testDependencyInjectedNewLanguage() {
$expected = $this->languageManager->getDefaultLanguage();
$result = $this->languageManager->getCurrentLanguage();
foreach ($expected as $property => $value) {
$this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', ['%prop' => $property]));
}
$this->assertSame($expected, $result);
}
/**
......
......@@ -2,7 +2,10 @@
namespace Drupal\Tests\node\Kernel\Action;
use Drupal\Core\Render\RenderContext;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Entity\Action;
/**
......@@ -13,19 +16,55 @@ class UnpublishByKeywordActionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['action', 'node', 'system', 'user'];
public static $modules = ['action', 'node', 'system', 'user', 'field'];
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('node', ['node_access']);
// Install system's configuration as default date formats are needed.
$this->installConfig(['system']);
// Create a node type for testing.
$type = NodeType::create(['type' => 'page', 'name' => 'page', 'display_submitted' => FALSE]);
$type->save();
}
/**
* Tests creating an action using the node_unpublish_by_keyword_action plugin.
*
* @see https://www.drupal.org/node/2578519
*/
public function testUnpublishByKeywordAction() {
Action::create([
/** @var \Drupal\node\Plugin\Action\UnpublishByKeywordNode $action */
$action = Action::create([
'id' => 'foo',
'label' => 'Foobaz',
'plugin' => 'node_unpublish_by_keyword_action',
])->save();
'configuration' => [
'keywords' => ['test'],
],
]);
$action->save();
$node1 = Node::create([
'type' => 'page',
'title' => 'test',
'uid' => 1,
]);
$node1->setPublished();
$node1->save();
$node2 = Node::create([
'type' => 'page',
'title' => 'Another node',
'uid' => 1,
]);
$node2->setPublished();
$node2->save();
$this->container->get('renderer')->executeInRenderContext(new RenderContext(), function () use (&$node1, &$node2, $action) {
$action->execute([$node1, $node2]);
});
$this->assertFalse($node1->isPublished());
$this->assertTrue($node2->isPublished());
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\system\Kernel;
use Drupal\Core\Extension\Extension;
use Drupal\KernelTests\KernelTestBase;
/**
......@@ -22,7 +23,8 @@ class SystemFunctionsLegacyTest extends KernelTestBase {
* @see system_rebuild_module_data()
*/
public function testSystemRebuildModuleDataDeprecation() {
system_rebuild_module_data();
$list = system_rebuild_module_data();
$this->assertInstanceOf(Extension::class, $list['system']);
}
}
......@@ -9,6 +9,9 @@
* Tests the Drupal\views\Plugin\views\field\Counter handler.
*
* @group views
*
* @todo Write tests for pager in
* https://www.drupal.org/project/drupal/issues/3063179
*/
class FieldCounterTest extends ViewsKernelTestBase {
......@@ -84,10 +87,4 @@ public function testSimple() {
$this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter]));
}
/**
* @todo: Write tests for pager.
*/
public function testPager() {
}
}
......@@ -25,6 +25,7 @@ public function testFormatDate() {
/**
* @expectedDeprecation drupal_set_time_limit() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Environment::setTimeLimit() instead. See https://www.drupal.org/node/3000058.
* @doesNotPerformAssertions
*/
public function testDrupalSetTimeLimit() {
drupal_set_time_limit(1000);
......
......@@ -44,7 +44,7 @@ protected function setUp() {
* {@inheritdoc}
*/
public function testInvalidStorage() {
// No-op as this test does not make sense.
$this->markTestSkipped('No-op as this test does not make sense');
}
/**
......
......@@ -55,7 +55,7 @@ protected function delete($name) {
* {@inheritdoc}
*/
public function testInvalidStorage() {
// No-op as this test does not make sense.
$this->markTestSkipped('No-op as this test does not make sense');
}
/**
......
......@@ -123,7 +123,7 @@ public function testMultipleStatementsForNewPhp() {
// This just tests mysql, as other PDO integrations don't allow disabling
// multiple statements.
if (Database::getConnection()->databaseType() !== 'mysql') {
return;
$this->markTestSkipped("This test only runs for MySQL");
}
$db = Database::getConnection('default', 'default');
......@@ -160,7 +160,7 @@ public function testMultipleStatements() {
*/
public function testPostgresqlReservedWords() {
if (Database::getConnection()->databaseType() !== 'pgsql') {
return;
$this->markTestSkipped("This test only runs for PostgreSQL");
}
$db = Database::getConnection('default', 'default');
......
......@@ -119,6 +119,7 @@ public function testDbNextId() {
* Tests the db_change_field() function is deprecated.
*
* @expectedDeprecation db_change_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbChangeField() {
$spec = [
......@@ -137,6 +138,7 @@ public function testDbChangeField() {
*
* @expectedDeprecation db_field_set_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @expectedDeprecation fieldSetDefault() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
* @doesNotPerformAssertions
*/
public function testDbFieldSetDefault() {
db_field_set_default('test', 'job', 'baz');
......@@ -147,6 +149,7 @@ public function testDbFieldSetDefault() {
*
* @expectedDeprecation db_field_set_no_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @expectedDeprecation fieldSetNoDefault() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
* @doesNotPerformAssertions
*/
public function testDbFieldSetNoDefault() {
db_field_set_no_default('test_null', 'age');
......@@ -378,6 +381,7 @@ public function testDbDropUniqueKey() {
* Tests deprecation of the db_add_unique_key() function.
*
* @expectedDeprecation db_add_unique_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbAddUniqueKey() {
db_add_unique_key('test', 'age', ['age']);
......@@ -396,6 +400,7 @@ public function testDbDropPrimaryKey() {
* Tests deprecation of the db_add_primary_key() function.
*
* @expectedDeprecation db_add_primary_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbAddPrimaryKey() {
$this->connection->schema()->dropPrimaryKey('test_people');
......
......@@ -48,11 +48,12 @@ protected function setUp() {
*/
public function testModuleConfigureRoutes($module) {
$module_info = $this->moduleInfo[$module]->info;
if (isset($module_info['configure'])) {
$this->container->get('module_installer')->install([$module]);
$route = $this->routeProvider->getRouteByName($module_info['configure']);
$this->assertNotEmpty($route, sprintf('The configure route for the "%s" module was found.', $module));
if (!isset($module_info['configure'])) {
$this->markTestSkipped("$module has no configure route");
}
$this->container->get('module_installer')->install([$module]);
$route = $this->routeProvider->getRouteByName($module_info['configure']);
$this->assertNotEmpty($route, sprintf('The configure route for the "%s" module was found.', $module));
}
}
......@@ -17,6 +17,7 @@ class ModuleHandlerDeprecatedHookUnimplementedTest extends KernelTestBase {
* @covers ::alterDeprecated
* @covers ::invokeAllDeprecated
* @covers ::invokeDeprecated
* @doesNotPerformAssertions
*/
public function testUnimplementedHooks() {
$unimplemented_hook_name = 'unimplemented_hook_name';
......
......@@ -588,9 +588,6 @@ protected function assertPostConditions() {
$this->container->get('kernel')->shutdown();
}
// Fail in case any (new) shutdown functions exist.
$this->assertCount(0, drupal_register_shutdown_function(), 'Unexpected Drupal shutdown callbacks exist after running shutdown functions.');
parent::assertPostConditions();
}
......
<?php
namespace Drupal\KernelTests;
/**
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
*
* @group PHPUnit
* @group Test
* @group KernelTests
*/
class KernelTestBaseShutdownTest extends KernelTestBase {
/**
* Indicates which shutdown functions are expected to be called.
*
* @var array
*/
protected $expectedShutdownCalled;
/**
* Indicates which shutdown functions have been called.
*
* @var array
*/
protected static $shutdownCalled;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Initialize static variable prior to testing.
self::$shutdownCalled = [];
parent::setUp();
}
/**
* @covers ::assertPostConditions
*/
public function testShutdownFunction() {
$this->expectedShutdownCalled = ['shutdownFunction', 'shutdownFunction2'];
drupal_register_shutdown_function([$this, 'shutdownFunction']);
}
/**
* @covers ::assertPostConditions
*/
public function testNoShutdownFunction() {
$this->expectedShutdownCalled = [];
}
/**
* Registers that this shutdown function has been called.
*/
public function shutdownFunction() {
self::$shutdownCalled[] = 'shutdownFunction';
drupal_register_shutdown_function([$this, 'shutdownFunction2']);
}
/**
* Registers that this shutdown function has been called.
*/
public function shutdownFunction2() {
self::$shutdownCalled[] = 'shutdownFunction2';
}
/**
* {@inheritdoc}
*/
protected function assertPostConditions() {
parent::assertPostConditions();
$this->assertSame($this->expectedShutdownCalled, self::$shutdownCalled);
}
}
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