comparison core/core.api.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1044 * - In the Field API, data types can be used as the class in the property 1044 * - In the Field API, data types can be used as the class in the property
1045 * definition of the field. See the @link field Field API topic @endlink for 1045 * definition of the field. See the @link field Field API topic @endlink for
1046 * more information. 1046 * more information.
1047 * - In configuration schema files, you can use the unique ID ('id' annotation) 1047 * - In configuration schema files, you can use the unique ID ('id' annotation)
1048 * from any DataType plugin class as the 'type' value for an entry. See the 1048 * from any DataType plugin class as the 'type' value for an entry. See the
1049 * @link config_api Confuration API topic @endlink for more information. 1049 * @link config_api Configuration API topic @endlink for more information.
1050 * - If you need to create a typed data object in code, first get the 1050 * - If you need to create a typed data object in code, first get the
1051 * typed_data_manager service from the container or by calling 1051 * typed_data_manager service from the container or by calling
1052 * \Drupal::typedDataManager(). Then pass the plugin ID to 1052 * \Drupal::typedDataManager(). Then pass the plugin ID to
1053 * $manager::createDataDefinition() to create an appropriate data definition 1053 * $manager::createDataDefinition() to create an appropriate data definition
1054 * object. Then pass the data definition object and the value of the data to 1054 * object. Then pass the data definition object and the value of the data to
1060 */ 1060 */
1061 1061
1062 /** 1062 /**
1063 * @defgroup testing Automated tests 1063 * @defgroup testing Automated tests
1064 * @{ 1064 * @{
1065 * Overview of PHPUnit tests and Simpletest tests. 1065 * Overview of PHPUnit and Nightwatch automated tests.
1066 * 1066 *
1067 * The Drupal project has embraced a philosophy of using automated tests, 1067 * The Drupal project has embraced a philosophy of using automated tests,
1068 * consisting of both unit tests (which test the functionality of classes at a 1068 * consisting of both unit tests (which test the functionality of classes at a
1069 * low level) and functional tests (which test the functionality of Drupal 1069 * low level) and functional tests (which test the functionality of Drupal
1070 * systems at a higher level, usually involving web output). The goal is to 1070 * systems at a higher level, usually involving web output). The goal is to
1081 * - When making a patch to implement a new feature, include new unit and/or 1081 * - When making a patch to implement a new feature, include new unit and/or
1082 * functional tests in the patch. This serves to both demonstrate that the 1082 * functional tests in the patch. This serves to both demonstrate that the
1083 * code actually works, and ensure that later changes do not break the new 1083 * code actually works, and ensure that later changes do not break the new
1084 * functionality. 1084 * functionality.
1085 * 1085 *
1086 * @section write_unit Writing PHPUnit tests for classes 1086 * @section write_test Writing tests
1087 * PHPUnit tests for classes are written using the industry-standard PHPUnit 1087 * All PHP-based tests for Drupal core are written using the industry-standard
1088 * framework. Use a PHPUnit test to test functionality of a class if the Drupal 1088 * PHPUnit framework, with Drupal extensions. There are several categories of
1089 * environment (database, settings, etc.) and web browser are not needed for the 1089 * tests; each has its own purpose, base class, namespace, and directory:
1090 * test, or if the Drupal environment can be replaced by a "mock" object. To 1090 * - Unit tests:
1091 * write a PHPUnit test: 1091 * - Purpose: Test functionality of a class if the Drupal environment
1092 * - Define a class that extends \Drupal\Tests\UnitTestCase. 1092 * (database, settings, etc.) and web browser are not needed for the test,
1093 * - The class name needs to end in the word Test. 1093 * or if the Drupal environment can be replaced by a "mock" object.
1094 * - The namespace must be a subspace/subdirectory of \Drupal\yourmodule\Tests, 1094 * - Base class: \Drupal\Tests\UnitTestCase
1095 * where yourmodule is your module's machine name. 1095 * - Namespace: \Drupal\Tests\yourmodule\Unit (or a subdirectory)
1096 * - The test class file must be named and placed under the 1096 * - Directory location: yourmodule/tests/src/Unit (or a subdirectory)
1097 * yourmodule/tests/src/Unit directory, according to the PSR-4 standard. 1097 * - Kernel tests:
1098 * - Your test class needs a phpDoc comment block with a description and 1098 * - Purpose: Test functionality of a class if the full Drupal environment
1099 * a @group annotation, which gives information about the test. 1099 * and web browser are not needed for the test, but the functionality has
1100 * - Add test cases by adding method names that start with 'test' and have no 1100 * significant Drupal dependencies that cannot easily be mocked. Kernel
1101 * arguments, for example testYourTestCase(). Each one should test a logical 1101 * tests can access services, the database, and a minimal mocked file
1102 * subset of the functionality. 1102 * system, and they use an in-memory pseudo-installation. However, modules
1103 * are only installed to the point of having services and hooks, unless you
1104 * install them explicitly.
1105 * - Base class: \Drupal\KernelTests\KernelTestBase
1106 * - Namespace: \Drupal\Tests\yourmodule\Kernel (or a subdirectory)
1107 * - Directory location: yourmodule/tests/src/Kernel (or a subdirectory)
1108 * - Browser tests:
1109 * - Purpose: Test functionality with the full Drupal environment and an
1110 * internal simulated web browser, if JavaScript is not needed.
1111 * - Base class: \Drupal\Tests\BrowserTestBase
1112 * - Namespace: \Drupal\Tests\yourmodule\Functional (or a subdirectory)
1113 * - Directory location: yourmodule/tests/src/Functional (or a subdirectory)
1114 * - Browser tests with JavaScript:
1115 * - Purpose: Test functionality with the full Drupal environment and an
1116 * internal web browser that includes JavaScript execution.
1117 * - Base class: \Drupal\FunctionalJavascriptTests\WebDriverTestBase
1118 * - Namespace: \Drupal\Tests\yourmodule\FunctionalJavascript (or a
1119 * subdirectory)
1120 * - Directory location: yourmodule/tests/src/FunctionalJavascript (or a
1121 * subdirectory)
1122 *
1123 * Some notes about writing PHP test classes:
1124 * - The class needs a phpDoc comment block with a description and
1125 * @group annotation, which gives information about the test.
1126 * - For unit tests, this comment block should also have @coversDefaultClass
1127 * annotation.
1128 * - When writing tests, put the test code into public methods, each covering a
1129 * logical subset of the functionality that is being tested.
1130 * - The test methods must have names starting with 'test'. For unit tests, the
1131 * test methods need to have a phpDoc block with @covers annotation telling
1132 * which class method they are testing.
1133 * - In some cases, you may need to write a test module to support your test;
1134 * put such modules under the yourmodule/tests/modules directory.
1135 *
1136 * Besides the PHPUnit tests described above, Drupal Core also includes a few
1137 * JavaScript-only tests, which use the Nightwatch.js framework to test
1138 * JavaScript code using only JavaScript. These are located in
1139 * core/tests/Drupal/Nightwatch.
1140 *
1103 * For more details, see: 1141 * For more details, see:
1142 * - core/tests/README.md for instructions on running tests
1104 * - https://www.drupal.org/phpunit for full documentation on how to write 1143 * - https://www.drupal.org/phpunit for full documentation on how to write
1105 * PHPUnit tests for Drupal. 1144 * and run PHPUnit tests for Drupal.
1106 * - http://phpunit.de for general information on the PHPUnit framework. 1145 * - http://phpunit.de for general information on the PHPUnit framework.
1107 * - @link oo_conventions Object-oriented programming topic @endlink for more 1146 * - @link oo_conventions Object-oriented programming topic @endlink for more
1108 * on PSR-4, namespaces, and where to place classes. 1147 * on PSR-4, namespaces, and where to place classes.
1109 * 1148 * - http://nightwatchjs.org/ for information about Nightwatch testing for
1110 * @section write_functional Writing functional tests 1149 * JavaScript
1111 * Functional tests are written using a Drupal-specific framework that is, for
1112 * historical reasons, known as "Simpletest". Use a Simpletest test to test the
1113 * functionality of sub-system of Drupal, if the functionality depends on the
1114 * Drupal database and settings, or to test the web output of Drupal. To
1115 * write a Simpletest test:
1116 * - For functional tests of the web output of Drupal, define a class that
1117 * extends \Drupal\simpletest\WebTestBase, which contains an internal web
1118 * browser and defines many helpful test assertion methods that you can use
1119 * in your tests. You can specify modules to be enabled by defining a
1120 * $modules member variable -- keep in mind that by default, WebTestBase uses
1121 * a "testing" install profile, with a minimal set of modules enabled.
1122 * - For functional tests that do not test web output, define a class that
1123 * extends \Drupal\KernelTests\KernelTestBase. This class is much faster
1124 * than WebTestBase, because instead of making a full install of Drupal, it
1125 * uses an in-memory pseudo-installation (similar to what the installer and
1126 * update scripts use). To use this test class, you will need to create the
1127 * database tables you need and install needed modules manually.
1128 * - The namespace must be a subspace/subdirectory of \Drupal\yourmodule\Tests,
1129 * where yourmodule is your module's machine name.
1130 * - The test class file must be named and placed under the yourmodule/src/Tests
1131 * directory, according to the PSR-4 standard.
1132 * - Your test class needs a phpDoc comment block with a description and
1133 * a @group annotation, which gives information about the test.
1134 * - You may also override the default setUp() method, which can set be used to
1135 * set up content types and similar procedures.
1136 * - In some cases, you may need to write a test module to support your test;
1137 * put such modules under the yourmodule/tests/modules directory.
1138 * - Add test cases by adding method names that start with 'test' and have no
1139 * arguments, for example testYourTestCase(). Each one should test a logical
1140 * subset of the functionality. Each method runs in a new, isolated test
1141 * environment, so it can only rely on the setUp() method, not what has
1142 * been set up by other test methods.
1143 * For more details, see:
1144 * - https://www.drupal.org/simpletest for full documentation on how to write
1145 * functional tests for Drupal.
1146 * - @link oo_conventions Object-oriented programming topic @endlink for more
1147 * on PSR-4, namespaces, and where to place classes.
1148 *
1149 * @section write_functional_phpunit Write functional PHP tests (phpunit)
1150 * Functional tests extend the BrowserTestBase base class, and use PHPUnit as
1151 * their underlying framework. They use a simulated browser, in which the test
1152 * can click links, visit URLs, post to forms, etc. To write a functional test:
1153 * - Extend \Drupal\Tests\BrowserTestBase.
1154 * - Place the test in the yourmodule/tests/src/Functional/ directory and use
1155 * the \Drupal\Tests\yourmodule\Functional namespace.
1156 * - Add a @group annotation. For example, if the test is for a Drupal 6
1157 * migration process, the group core uses is migrate_drupal_6. Use yourmodule
1158 * as the group name if the test does not belong to another larger group.
1159 * - You may also override the default setUp() method, which can be used to set
1160 * up content types and similar procedures. Don't forget to call the parent
1161 * method.
1162 * - In some cases, you may need to write a test module to support your test;
1163 * put such modules under the yourmodule/tests/modules directory.
1164 * - Add test cases by adding method names that start with 'test' and have no
1165 * arguments, for example testYourTestCase(). Each one should test a logical
1166 * subset of the functionality. Each method runs in a new, isolated test
1167 * environment, so it can only rely on the setUp() method, not what has
1168 * been set up by other test methods.
1169 * For more details, see:
1170 * - https://www.drupal.org/docs/8/phpunit/phpunit-browser-test-tutorial for
1171 * a full tutorial on how to write functional PHPUnit tests for Drupal.
1172 * - https://www.drupal.org/phpunit for the full documentation on how to write
1173 * PHPUnit tests for Drupal.
1174 *
1175 * @section write_jsfunctional_phpunit Write functional JavaScript tests (phpunit)
1176 * To write a functional test that relies on JavaScript:
1177 * - Extend \Drupal\FunctionalJavaScriptTests\JavascriptTestBase.
1178 * - Place the test into the yourmodule/tests/src/FunctionalJavascript/
1179 * directory and use the \Drupal\Tests\yourmodule\FunctionalJavascript
1180 * namespace.
1181 * - Add a @group annotation. Use yourmodule as the group name if the test does
1182 * not belong to another larger group.
1183 * - Set up PhantomJS; see http://phantomjs.org/download.html.
1184 * - To run tests, see core/tests/README.md.
1185 * - When clicking a link/button with Ajax behavior attached, keep in mind that
1186 * the underlying browser might take time to deliver changes to the HTML. Use
1187 * $this->assertSession()->assertWaitOnAjaxRequest() to wait for the Ajax
1188 * request to finish.
1189 * For more details, see:
1190 * - https://www.drupal.org/docs/8/phpunit/phpunit-javascript-testing-tutorial
1191 * for a full tutorial on how to write PHPUnit JavaScript tests for Drupal.
1192 * - https://www.drupal.org/phpunit for the full documentation on how to write
1193 * PHPUnit tests for Drupal.
1194 *
1195 * @section running Running tests
1196 * You can run both Simpletest and PHPUnit tests by enabling the core Testing
1197 * module (core/modules/simpletest). Once that module is enabled, tests can be
1198 * run on through the Testing module's user interface or on the command line.
1199 *
1200 * See @link https://www.drupal.org/node/2116263 Running tests with PHPUnit
1201 * binary @endlink or @link https://www.drupal.org/node/645286 Running tests
1202 * with run-tests.sh @endlink for more information.
1203 * @} 1150 * @}
1204 */ 1151 */
1205 1152
1206 /** 1153 /**
1207 * @defgroup php_assert PHP Runtime Assert Statements 1154 * @defgroup php_assert PHP Runtime Assert Statements
1380 * - Define an interface for the plugin. This describes the common set of 1327 * - Define an interface for the plugin. This describes the common set of
1381 * behavior, and the methods you will call on each plugin class that is 1328 * behavior, and the methods you will call on each plugin class that is
1382 * instantiated. Usually this interface will extend one or more of the 1329 * instantiated. Usually this interface will extend one or more of the
1383 * following interfaces: 1330 * following interfaces:
1384 * - \Drupal\Component\Plugin\PluginInspectionInterface 1331 * - \Drupal\Component\Plugin\PluginInspectionInterface
1385 * - \Drupal\Component\Plugin\ConfigurablePluginInterface 1332 * - \Drupal\Component\Plugin\ConfigurableInterface
1333 * - \Drupal\Component\Plugin\DependentPluginInterface
1386 * - \Drupal\Component\Plugin\ContextAwarePluginInterface 1334 * - \Drupal\Component\Plugin\ContextAwarePluginInterface
1387 * - \Drupal\Core\Plugin\PluginFormInterface 1335 * - \Drupal\Core\Plugin\PluginFormInterface
1388 * - \Drupal\Core\Executable\ExecutableInterface 1336 * - \Drupal\Core\Executable\ExecutableInterface
1389 * - (optional) Create a base class that provides a partial implementation of 1337 * - (optional) Create a base class that provides a partial implementation of
1390 * the interface, for the convenience of developers wishing to create plugins 1338 * the interface, for the convenience of developers wishing to create plugins
2136 if (isset($params['node'])) { 2084 if (isset($params['node'])) {
2137 /** @var \Drupal\node\NodeInterface $node */ 2085 /** @var \Drupal\node\NodeInterface $node */
2138 $node = $params['node']; 2086 $node = $params['node'];
2139 $variables += [ 2087 $variables += [
2140 '%uid' => $node->getOwnerId(), 2088 '%uid' => $node->getOwnerId(),
2141 '%url' => $node->url('canonical', ['absolute' => TRUE]), 2089 '%url' => $node->toUrl('canonical', ['absolute' => TRUE])->toString(),
2142 '%node_type' => node_get_type_label($node), 2090 '%node_type' => node_get_type_label($node),
2143 '%title' => $node->getTitle(), 2091 '%title' => $node->getTitle(),
2144 '%teaser' => $node->teaser, 2092 '%teaser' => $node->teaser,
2145 '%body' => $node->body, 2093 '%body' => $node->body,
2146 ]; 2094 ];