Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/BrowserTestBase.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
33 * | 33 * |
34 * Tests extending BrowserTestBase must exist in the | 34 * Tests extending BrowserTestBase must exist in the |
35 * Drupal\Tests\yourmodule\Functional namespace and live in the | 35 * Drupal\Tests\yourmodule\Functional namespace and live in the |
36 * modules/yourmodule/tests/src/Functional directory. | 36 * modules/yourmodule/tests/src/Functional directory. |
37 * | 37 * |
38 * Tests extending this base class should only translate text when testing | |
39 * translation functionality. For example, avoid wrapping test text with t() | |
40 * or TranslatableMarkup(). | |
41 * | |
38 * @ingroup testing | 42 * @ingroup testing |
39 */ | 43 */ |
40 abstract class BrowserTestBase extends TestCase { | 44 abstract class BrowserTestBase extends TestCase { |
41 | 45 |
42 use FunctionalTestSetupTrait; | 46 use FunctionalTestSetupTrait; |
60 use UserCreationTrait { | 64 use UserCreationTrait { |
61 createRole as drupalCreateRole; | 65 createRole as drupalCreateRole; |
62 createUser as drupalCreateUser; | 66 createUser as drupalCreateUser; |
63 } | 67 } |
64 use XdebugRequestTrait; | 68 use XdebugRequestTrait; |
69 use PhpunitCompatibilityTrait; | |
65 | 70 |
66 /** | 71 /** |
67 * The database prefix of this test run. | 72 * The database prefix of this test run. |
68 * | 73 * |
69 * @var string | 74 * @var string |
340 * When provided default Mink driver class can't be instantiated. | 345 * When provided default Mink driver class can't be instantiated. |
341 */ | 346 */ |
342 protected function getDefaultDriverInstance() { | 347 protected function getDefaultDriverInstance() { |
343 // Get default driver params from environment if availables. | 348 // Get default driver params from environment if availables. |
344 if ($arg_json = getenv('MINK_DRIVER_ARGS')) { | 349 if ($arg_json = getenv('MINK_DRIVER_ARGS')) { |
345 $this->minkDefaultDriverArgs = json_decode($arg_json); | 350 $this->minkDefaultDriverArgs = json_decode($arg_json, TRUE); |
346 } | 351 } |
347 | 352 |
348 // Get and check default driver class from environment if availables. | 353 // Get and check default driver class from environment if availables. |
349 if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) { | 354 if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) { |
350 if (class_exists($minkDriverClass)) { | 355 if (class_exists($minkDriverClass)) { |
444 | 449 |
445 /** | 450 /** |
446 * {@inheritdoc} | 451 * {@inheritdoc} |
447 */ | 452 */ |
448 protected function setUp() { | 453 protected function setUp() { |
454 // Installing Drupal creates 1000s of objects. Garbage collection of these | |
455 // objects is expensive. This appears to be causing random segmentation | |
456 // faults in PHP 5.x due to https://bugs.php.net/bug.php?id=72286. Once | |
457 // Drupal is installed is rebuilt, garbage collection is re-enabled. | |
458 $disable_gc = version_compare(PHP_VERSION, '7', '<') && gc_enabled(); | |
459 if ($disable_gc) { | |
460 gc_collect_cycles(); | |
461 gc_disable(); | |
462 } | |
449 parent::setUp(); | 463 parent::setUp(); |
450 | 464 |
451 $this->setupBaseUrl(); | 465 $this->setupBaseUrl(); |
452 | 466 |
453 // Install Drupal test site. | 467 // Install Drupal test site. |
464 } | 478 } |
465 } | 479 } |
466 | 480 |
467 // Set up the browser test output file. | 481 // Set up the browser test output file. |
468 $this->initBrowserOutputFile(); | 482 $this->initBrowserOutputFile(); |
483 // If garbage collection was disabled prior to rebuilding container, | |
484 // re-enable it. | |
485 if ($disable_gc) { | |
486 gc_enable(); | |
487 } | |
469 } | 488 } |
470 | 489 |
471 /** | 490 /** |
472 * Ensures test files are deletable within file_unmanaged_delete_recursive(). | 491 * Ensures test files are deletable within file_unmanaged_delete_recursive(). |
473 * | 492 * |
775 * | 794 * |
776 * A checkbox can be set to TRUE to be checked and should be set to FALSE to | 795 * A checkbox can be set to TRUE to be checked and should be set to FALSE to |
777 * be unchecked. | 796 * be unchecked. |
778 * @param string $submit | 797 * @param string $submit |
779 * Value of the submit button whose click is to be emulated. For example, | 798 * Value of the submit button whose click is to be emulated. For example, |
780 * t('Save'). The processing of the request depends on this value. For | 799 * 'Save'. The processing of the request depends on this value. For example, |
781 * example, a form may have one button with the value t('Save') and another | 800 * a form may have one button with the value 'Save' and another button with |
782 * button with the value t('Delete'), and execute different code depending | 801 * the value 'Delete', and execute different code depending on which one is |
783 * on which one is clicked. | 802 * clicked. |
784 * @param string $form_html_id | 803 * @param string $form_html_id |
785 * (optional) HTML ID of the form to be submitted. On some pages | 804 * (optional) HTML ID of the form to be submitted. On some pages |
786 * there are many identical forms, so just using the value of the submit | 805 * there are many identical forms, so just using the value of the submit |
787 * button is not enough. For example: 'trigger-node-presave-assign-form'. | 806 * button is not enough. For example: 'trigger-node-presave-assign-form'. |
788 * Note that this is not the Drupal $form_id, but rather the HTML ID of the | 807 * Note that this is not the Drupal $form_id, but rather the HTML ID of the |
857 * path to NULL and have it post to the last received page. Example: | 876 * path to NULL and have it post to the last received page. Example: |
858 * | 877 * |
859 * @code | 878 * @code |
860 * // First step in form. | 879 * // First step in form. |
861 * $edit = array(...); | 880 * $edit = array(...); |
862 * $this->drupalPostForm('some_url', $edit, t('Save')); | 881 * $this->drupalPostForm('some_url', $edit, 'Save'); |
863 * | 882 * |
864 * // Second step in form. | 883 * // Second step in form. |
865 * $edit = array(...); | 884 * $edit = array(...); |
866 * $this->drupalPostForm(NULL, $edit, t('Save')); | 885 * $this->drupalPostForm(NULL, $edit, 'Save'); |
867 * @endcode | 886 * @endcode |
868 * @param array $edit | 887 * @param array $edit |
869 * Field data in an associative array. Changes the current input fields | 888 * Field data in an associative array. Changes the current input fields |
870 * (where possible) to the values indicated. | 889 * (where possible) to the values indicated. |
871 * | 890 * |
891 * @endcode | 910 * @endcode |
892 * @todo change $edit to disallow NULL as a value for Drupal 9. | 911 * @todo change $edit to disallow NULL as a value for Drupal 9. |
893 * https://www.drupal.org/node/2802401 | 912 * https://www.drupal.org/node/2802401 |
894 * @param string $submit | 913 * @param string $submit |
895 * Value of the submit button whose click is to be emulated. For example, | 914 * Value of the submit button whose click is to be emulated. For example, |
896 * t('Save'). The processing of the request depends on this value. For | 915 * 'Save'. The processing of the request depends on this value. For example, |
897 * example, a form may have one button with the value t('Save') and another | 916 * a form may have one button with the value 'Save' and another button with |
898 * button with the value t('Delete'), and execute different code depending | 917 * the value 'Delete', and execute different code depending on which one is |
899 * on which one is clicked. | 918 * clicked. |
900 * | 919 * |
901 * This function can also be called to emulate an Ajax submission. In this | 920 * This function can also be called to emulate an Ajax submission. In this |
902 * case, this value needs to be an array with the following keys: | 921 * case, this value needs to be an array with the following keys: |
903 * - path: A path to submit the form values to for Ajax-specific processing. | 922 * - path: A path to submit the form values to for Ajax-specific processing. |
904 * - triggering_element: If the value for the 'path' key is a generic Ajax | 923 * - triggering_element: If the value for the 'path' key is a generic Ajax |