Issue #2028939 by cilefen, deekayen: Clean up line wrapping in simpletest documentation and make namespaces in docs fully qualified

8.0.x
Jennifer Hodgdon 2013-07-10 06:47:20 -07:00
parent 09d7b8192d
commit 87417aaff2
18 changed files with 197 additions and 151 deletions

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains Drupal\simpletest\DrupalUnitTestBase. * Contains \Drupal\simpletest\DrupalUnitTestBase.
*/ */
namespace Drupal\simpletest; namespace Drupal\simpletest;

View File

@ -95,7 +95,8 @@ class SimpletestResultsForm implements FormInterface, ControllerInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state, $test_id = NULL) { public function buildForm(array $form, array &$form_state, $test_id = NULL) {
// Make sure there are test results to display and a re-run is not being performed. // Make sure there are test results to display and a re-run is not being
// performed.
$results = array(); $results = array();
if (is_numeric($test_id) && !$results = $this->getResults($test_id)) { if (is_numeric($test_id) && !$results = $this->getResults($test_id)) {

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\TestBase. * Definition of \Drupal\simpletest\TestBase.
*/ */
namespace Drupal\simpletest; namespace Drupal\simpletest;
@ -23,8 +23,8 @@ use ReflectionObject;
/** /**
* Base class for Drupal tests. * Base class for Drupal tests.
* *
* Do not extend this class directly, use either Drupal\simpletest\WebTestBaseBase * Do not extend this class directly, use either
* or Drupal\simpletest\UnitTestBaseBase. * \Drupal\simpletest\WebTestBaseBase or \Drupal\simpletest\UnitTestBaseBase.
*/ */
abstract class TestBase { abstract class TestBase {
/** /**
@ -273,14 +273,14 @@ abstract class TestBase {
* the test case has been destroyed, such as PHP fatal errors. The caller * the test case has been destroyed, such as PHP fatal errors. The caller
* information is not automatically gathered since the caller is most likely * information is not automatically gathered since the caller is most likely
* inserting the assertion on behalf of other code. In all other respects * inserting the assertion on behalf of other code. In all other respects
* the method behaves just like Drupal\simpletest\TestBase::assert() in terms * the method behaves just like \Drupal\simpletest\TestBase::assert() in terms
* of storing the assertion. * of storing the assertion.
* *
* @return * @return
* Message ID of the stored assertion. * Message ID of the stored assertion.
* *
* @see Drupal\simpletest\TestBase::assert() * @see \Drupal\simpletest\TestBase::assert()
* @see Drupal\simpletest\TestBase::deleteAssert() * @see \Drupal\simpletest\TestBase::deleteAssert()
*/ */
public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = array()) { public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = array()) {
// Convert boolean status to string status. // Convert boolean status to string status.
@ -319,7 +319,7 @@ abstract class TestBase {
* @return * @return
* TRUE if the assertion was deleted, FALSE otherwise. * TRUE if the assertion was deleted, FALSE otherwise.
* *
* @see Drupal\simpletest\TestBase::insertAssert() * @see \Drupal\simpletest\TestBase::insertAssert()
*/ */
public static function deleteAssert($message_id) { public static function deleteAssert($message_id) {
return (bool) self::getDatabaseConnection() return (bool) self::getDatabaseConnection()
@ -331,7 +331,7 @@ abstract class TestBase {
/** /**
* Returns the database connection to the site running Simpletest. * Returns the database connection to the site running Simpletest.
* *
* @return Drupal\Core\Database\Connection * @return \Drupal\Core\Database\Connection
* The database connection to use for inserting assertions. * The database connection to use for inserting assertions.
*/ */
public static function getDatabaseConnection() { public static function getDatabaseConnection() {
@ -369,7 +369,9 @@ abstract class TestBase {
} }
/** /**
* Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). * Check to see if a value is not false.
*
* False values are: empty string, 0, NULL, and FALSE.
* *
* @param $value * @param $value
* The value on which the assertion is to be done. * The value on which the assertion is to be done.
@ -390,7 +392,9 @@ abstract class TestBase {
} }
/** /**
* Check to see if a value is false (an empty string, 0, NULL, or FALSE). * Check to see if a value is false.
*
* False values are: empty string, 0, NULL, and FALSE.
* *
* @param $value * @param $value
* The value on which the assertion is to be done. * The value on which the assertion is to be done.
@ -989,7 +993,7 @@ abstract class TestBase {
} }
/** /**
* Deletes created files, database tables, and reverts all environment changes. * Deletes created files, database tables, and reverts environment changes.
* *
* This method needs to be invoked for both unit and integration tests. * This method needs to be invoked for both unit and integration tests.
* *
@ -1128,7 +1132,8 @@ abstract class TestBase {
'line' => $exception->getLine(), 'line' => $exception->getLine(),
'file' => $exception->getFile(), 'file' => $exception->getFile(),
)); ));
// The exception message is run through check_plain() by _drupal_decode_exception(). // The exception message is run through check_plain()
// by _drupal_decode_exception().
$decoded_exception = _drupal_decode_exception($exception); $decoded_exception = _drupal_decode_exception($exception);
unset($decoded_exception['backtrace']); unset($decoded_exception['backtrace']);
$message = format_string('%type: !message in %function (line %line of %file). <pre class="backtrace">!backtrace</pre>', $decoded_exception + array( $message = format_string('%type: !message in %function (line %line of %file). <pre class="backtrace">!backtrace</pre>', $decoded_exception + array(

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\BrokenSetUpTest. * Definition of \Drupal\simpletest\Tests\BrokenSetUpTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -13,11 +13,11 @@ use Drupal\simpletest\WebTestBase;
* Tests a test case that does not run parent::setUp() in its setUp() method. * Tests a test case that does not run parent::setUp() in its setUp() method.
* *
* If a test case does not call parent::setUp(), running * If a test case does not call parent::setUp(), running
* Drupal\simpletest\WebTestBase::tearDown() would destroy the main site's * \Drupal\simpletest\WebTestBase::tearDown() would destroy the main site's
* database tables. Therefore, we ensure that tests which are not set up * database tables. Therefore, we ensure that tests which are not set up
* properly are skipped. * properly are skipped.
* *
* @see Drupal\simpletest\WebTestBase * @see \Drupal\simpletest\WebTestBase
*/ */
class BrokenSetUpTest extends WebTestBase { class BrokenSetUpTest extends WebTestBase {

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\BrowserTest. * Definition of \Drupal\simpletest\Tests\BrowserTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -22,7 +22,7 @@ class BrowserTest extends WebTestBase {
} }
/** /**
* Test Drupal\simpletest\WebTestBase::getAbsoluteUrl(). * Test \Drupal\simpletest\WebTestBase::getAbsoluteUrl().
*/ */
function testGetAbsoluteUrl() { function testGetAbsoluteUrl() {
$url = 'user/login'; $url = 'user/login';

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains Drupal\simpletest\Tests\DrupalUnitTestBaseTest. * Contains \Drupal\simpletest\Tests\DrupalUnitTestBaseTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -104,7 +104,7 @@ class DrupalUnitTestBaseTest extends DrupalUnitTestBase {
} }
/** /**
* Tests installing modules via enableModules() with DepedencyInjection services. * Tests installing modules with DependencyInjection services.
*/ */
function testEnableModulesInstallContainer() { function testEnableModulesInstallContainer() {
// Install Node module. // Install Node module.
@ -195,7 +195,7 @@ class DrupalUnitTestBaseTest extends DrupalUnitTestBase {
} }
/** /**
* Tests that the module list is retained after enabling/installing/disabling modules. * Tests that the module list is retained after enabling/installing/disabling.
*/ */
function testEnableModulesFixedList() { function testEnableModulesFixedList() {
// entity_test is loaded via $modules; its entity type should exist. // entity_test is loaded via $modules; its entity type should exist.

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\FolderTest. * Definition of \Drupal\simpletest\Tests\FolderTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\InstallationProfileModuleTestsTest. * Definition of \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -31,7 +31,7 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
* - but still install the drupal_system_listing_compatible_test.module * - but still install the drupal_system_listing_compatible_test.module
* contained in the Testing profile. * contained in the Testing profile.
* *
* @see Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest * @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
*/ */
protected $profile = 'testing'; protected $profile = 'testing';

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\MailCaptureTest. * Definition of \Drupal\simpletest\Tests\MailCaptureTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -77,8 +77,9 @@ class MailCaptureTest extends WebTestBase {
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject, 'from' => 'this_was_not_used@example.com')); $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test', 'subject' => $subject, 'from' => 'this_was_not_used@example.com'));
$this->assertEqual(count($captured_emails), 0, 'No e-mails are returned when querying with an unused from address.', 'E-mail'); $this->assertEqual(count($captured_emails), 0, 'No e-mails are returned when querying with an unused from address.', 'E-mail');
// Send the last e-mail again, so we can confirm that the drupalGetMails-filter // Send the last e-mail again, so we can confirm that the
// correctly returns all e-mails with a given property/value. // drupalGetMails-filter correctly returns all e-mails with a given
// property/value.
drupal_mail_system('drupal_mail_test', $index)->mail($message); drupal_mail_system('drupal_mail_test', $index)->mail($message);
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4')); $captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4'));
$this->assertEqual(count($captured_emails), 2, 'All e-mails with the same id are returned when filtering by id.', 'E-mail'); $this->assertEqual(count($captured_emails), 2, 'All e-mails with the same id are returned when filtering by id.', 'E-mail');

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\MissingCheckedRequirementsTest. * Definition of \Drupal\simpletest\Tests\MissingCheckedRequirementsTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\MissingDependentModuleUnitTest. * Definition of \Drupal\simpletest\Tests\MissingDependentModuleUnitTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\OtherInstallationProfileModuleTestsTest. * Definition of \Drupal\simpletest\Tests\OtherInstallationProfileModuleTestsTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -30,7 +30,7 @@ class OtherInstallationProfileModuleTestsTest extends WebTestBase {
* which should not be found. * which should not be found.
* *
* @see SimpleTestInstallationProfileModuleTestsTestCase * @see SimpleTestInstallationProfileModuleTestsTestCase
* @see Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest * @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
*/ */
protected $profile = 'minimal'; protected $profile = 'minimal';

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\Tests\SimpleTestTest. * Definition of \Drupal\simpletest\Tests\SimpleTestTest.
*/ */
namespace Drupal\simpletest\Tests; namespace Drupal\simpletest\Tests;
@ -25,8 +25,9 @@ class SimpleTestTest extends WebTestBase {
protected $childTestResults; protected $childTestResults;
/** /**
* Store the test ID from each test run for comparison, to ensure they are * Stores the test ID from each test run for comparison.
* incrementing. *
* Used to ensure they are incrementing.
*/ */
protected $test_ids = array(); protected $test_ids = array();
@ -131,8 +132,7 @@ class SimpleTestTest extends WebTestBase {
} }
/** /**
* Make sure that tests selected through the web interface are run and * Ensures the tests selected through the web interface are run and displayed.
* that the results are displayed correctly.
*/ */
function testWebTestRunner() { function testWebTestRunner() {
$this->pass = t('SimpleTest pass.'); $this->pass = t('SimpleTest pass.');
@ -141,7 +141,8 @@ class SimpleTestTest extends WebTestBase {
$this->invalid_permission = 'invalid permission'; $this->invalid_permission = 'invalid permission';
if ($this->inCURL()) { if ($this->inCURL()) {
// Only run following code if this test is running itself through a CURL request. // Only run following code if this test is running itself through a CURL
// request.
$this->stubTest(); $this->stubTest();
} }
else { else {
@ -215,9 +216,9 @@ class SimpleTestTest extends WebTestBase {
// Check that the backtracing code works for specific assert function. // Check that the backtracing code works for specific assert function.
$this->assertAssertion('This is nothing.', 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); $this->assertAssertion('This is nothing.', 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that errors that occur inside PHP internal functions are correctly reported. // Check that errors that occur inside PHP internal functions are correctly
// The exact error message differs between PHP versions so we check only // reported. The exact error message differs between PHP versions so we
// the function name 'array_key_exists'. // check only the function name 'array_key_exists'.
$this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); $this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); $this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
@ -241,8 +242,7 @@ class SimpleTestTest extends WebTestBase {
} }
/** /**
* Assert that an assertion with the specified values is displayed * Asserts that an assertion with specified values is displayed in results.
* in the test results.
* *
* @param string $message Assertion message. * @param string $message Assertion message.
* @param string $type Assertion type. * @param string $type Assertion type.

View File

@ -35,10 +35,10 @@ abstract class UnitTestBase extends TestBase {
/** /**
* Sets up unit test environment. * Sets up unit test environment.
* *
* Unlike Drupal\simpletest\WebTestBase::setUp(), UnitTestBase::setUp() does not * Unlike \Drupal\simpletest\WebTestBase::setUp(), UnitTestBase::setUp() does
* install modules because tests are performed without accessing the database. * not install modules because tests are performed without accessing the
* Any required files must be explicitly included by the child class setUp() * database. Any required files must be explicitly included by the child class
* method. * setUp() method.
*/ */
protected function setUp() { protected function setUp() {
global $conf; global $conf;
@ -60,7 +60,7 @@ abstract class UnitTestBase extends TestBase {
// Change the database prefix. // Change the database prefix.
// All static variables need to be reset before the database prefix is // All static variables need to be reset before the database prefix is
// changed, since Drupal\Core\Utility\CacheArray implementations attempt to // changed, since \Drupal\Core\Utility\CacheArray implementations attempt to
// write back to persistent caches when they are destructed. // write back to persistent caches when they are destructed.
$this->changeDatabasePrefix(); $this->changeDatabasePrefix();
if (!$this->setupDatabasePrefix) { if (!$this->setupDatabasePrefix) {

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of Drupal\simpletest\WebTestBase. * Definition of \Drupal\simpletest\WebTestBase.
*/ */
namespace Drupal\simpletest; namespace Drupal\simpletest;
@ -73,14 +73,16 @@ abstract class WebTestBase extends TestBase {
protected $content; protected $content;
/** /**
* The content of the page currently loaded in the internal browser (plain text version). * The plain-text content of the currently-loaded page.
* *
* @var string * @var string
*/ */
protected $plainTextContent; protected $plainTextContent;
/** /**
* The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser. * The value of Drupal.settings for the currently-loaded page.
*
* Drupal.settings refers to the Drupal.settings JavaScript variable.
* *
* @var Array * @var Array
*/ */
@ -111,27 +113,27 @@ abstract class WebTestBase extends TestBase {
/** /**
* Additional cURL options. * Additional cURL options.
* *
* Drupal\simpletest\WebTestBase itself never sets this but always obeys what is * \Drupal\simpletest\WebTestBase itself never sets this but always obeys what
* set. * is set.
*/ */
protected $additionalCurlOptions = array(); protected $additionalCurlOptions = array();
/** /**
* The original user, before it was changed to a clean uid = 1 for testing purposes. * The original user, before it was changed to a clean uid = 1 for testing.
* *
* @var object * @var object
*/ */
protected $originalUser = NULL; protected $originalUser = NULL;
/** /**
* The original shutdown handlers array, before it was cleaned for testing purposes. * The original shutdown handlers array, before it was cleaned for testing.
* *
* @var array * @var array
*/ */
protected $originalShutdownCallbacks = array(); protected $originalShutdownCallbacks = array();
/** /**
* HTTP authentication method * HTTP authentication method.
*/ */
protected $httpauth_method = CURLAUTH_BASIC; protected $httpauth_method = CURLAUTH_BASIC;
@ -171,7 +173,7 @@ abstract class WebTestBase extends TestBase {
protected $kernel; protected $kernel;
/** /**
* Constructor for Drupal\simpletest\WebTestBase. * Constructor for \Drupal\simpletest\WebTestBase.
*/ */
function __construct($test_id = NULL) { function __construct($test_id = NULL) {
parent::__construct($test_id); parent::__construct($test_id);
@ -320,7 +322,8 @@ abstract class WebTestBase extends TestBase {
$this->assertEqual($status, SAVED_NEW, t('Created content type %type.', array('%type' => $type->id()))); $this->assertEqual($status, SAVED_NEW, t('Created content type %type.', array('%type' => $type->id())));
// Reset permissions so that permissions for this content type are available. // Reset permissions so that permissions for this content type are
// available.
$this->checkPermissions(array(), TRUE); $this->checkPermissions(array(), TRUE);
return $type; return $type;
@ -378,10 +381,11 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Get a list files that can be used in tests. * Gets a list files that can be used in tests.
* *
* @param $type * @param $type
* File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'. * File type, possible values: 'binary', 'html', 'image', 'javascript',
* 'php', 'sql', 'text'.
* @param $size * @param $size
* File size in bytes to match. Please check the tests/files folder. * File size in bytes to match. Please check the tests/files folder.
* @return * @return
@ -658,8 +662,10 @@ abstract class WebTestBase extends TestBase {
return Crypt::hmacBase64($value, $this->session_id . $private_key); return Crypt::hmacBase64($value, $this->session_id . $private_key);
} }
/* /**
* Logs a user out of the internal browser, then check the login page to confirm logout. * Logs a user out of the internal browser and confirms.
*
* Confirms logout by checking the login page.
*/ */
protected function drupalLogout() { protected function drupalLogout() {
// Make a request to the logout page, and redirect to the user page, the // Make a request to the logout page, and redirect to the user page, the
@ -681,7 +687,7 @@ abstract class WebTestBase extends TestBase {
* Sets up a Drupal site for running functional and integration tests. * Sets up a Drupal site for running functional and integration tests.
* *
* Generates a random database prefix and installs Drupal with the specified * Generates a random database prefix and installs Drupal with the specified
* installation profile in Drupal\simpletest\WebTestBase::$profile into the * installation profile in \Drupal\simpletest\WebTestBase::$profile into the
* prefixed database. Afterwards, installs any additional modules specified by * prefixed database. Afterwards, installs any additional modules specified by
* the test. * the test.
* *
@ -694,9 +700,9 @@ abstract class WebTestBase extends TestBase {
* List of modules to enable for the duration of the test. This can be * List of modules to enable for the duration of the test. This can be
* either a single array or a variable number of string arguments. * either a single array or a variable number of string arguments.
* *
* @see Drupal\simpletest\WebTestBase::prepareDatabasePrefix() * @see \Drupal\simpletest\WebTestBase::prepareDatabasePrefix()
* @see Drupal\simpletest\WebTestBase::changeDatabasePrefix() * @see \Drupal\simpletest\WebTestBase::changeDatabasePrefix()
* @see Drupal\simpletest\WebTestBase::prepareEnvironment() * @see \Drupal\simpletest\WebTestBase::prepareEnvironment()
*/ */
protected function setUp() { protected function setUp() {
global $user, $conf; global $user, $conf;
@ -723,7 +729,7 @@ abstract class WebTestBase extends TestBase {
// Change the database prefix. // Change the database prefix.
// All static variables need to be reset before the database prefix is // All static variables need to be reset before the database prefix is
// changed, since Drupal\Core\Utility\CacheArray implementations attempt to // changed, since \Drupal\Core\Utility\CacheArray implementations attempt to
// write back to persistent caches when they are destructed. // write back to persistent caches when they are destructed.
$this->changeDatabasePrefix(); $this->changeDatabasePrefix();
if (!$this->setupDatabasePrefix) { if (!$this->setupDatabasePrefix) {
@ -893,7 +899,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Overrides Drupal\simpletest\TestBase::rebuildContainer(). * Overrides \Drupal\simpletest\TestBase::rebuildContainer().
*/ */
protected function rebuildContainer() { protected function rebuildContainer() {
parent::rebuildContainer(); parent::rebuildContainer();
@ -903,11 +909,11 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Reset all data structures after having enabled new modules. * Resets all data structures after having enabled new modules.
* *
* This method is called by Drupal\simpletest\WebTestBase::setUp() after enabling * This method is called by \Drupal\simpletest\WebTestBase::setUp() after
* the requested modules. It must be called again when additional modules * enabling the requested modules. It must be called again when additional
* are enabled later. * modules are enabled later.
*/ */
protected function resetAll() { protected function resetAll() {
// Clear all database and static caches and rebuild data structures. // Clear all database and static caches and rebuild data structures.
@ -920,16 +926,18 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Refresh the in-memory set of variables. Useful after a page request is made * Refreshes the in-memory set of variables.
* that changes a variable in a different thread.
* *
* In other words calling a settings page with $this->drupalPost() with a changed * Useful after a page request is made that changes a variable in a different
* value would update a variable to reflect that change, but in the thread that * thread.
* made the call (thread running the test) the changed variable would not be
* picked up.
* *
* This method clears the variables cache and loads a fresh copy from the database * In other words calling a settings page with $this->drupalPost() with a
* to ensure that the most up-to-date set of variables is loaded. * changed value would update a variable to reflect that change, but in the
* thread that made the call (thread running the test) the changed variable
* would not be picked up.
*
* This method clears the variables cache and loads a fresh copy from the
* database to ensure that the most up-to-date set of variables is loaded.
*/ */
protected function refreshVariables() { protected function refreshVariables() {
global $conf; global $conf;
@ -941,8 +949,10 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Delete created files and temporary files directory, delete the tables created by setUp(), * Cleans up after testing.
* and reset the database prefix. *
* Deletes created files and temporary files directory, deletes the tables
* created by setUp(), and resets the database prefix.
*/ */
protected function tearDown() { protected function tearDown() {
// Destroy the testing kernel. // Destroy the testing kernel.
@ -984,8 +994,10 @@ abstract class WebTestBase extends TestBase {
CURLOPT_URL => $base_url, CURLOPT_URL => $base_url,
CURLOPT_FOLLOWLOCATION => FALSE, CURLOPT_FOLLOWLOCATION => FALSE,
CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE, // Required to make the tests run on HTTPS. // Required to make the tests run on HTTPS.
CURLOPT_SSL_VERIFYHOST => FALSE, // Required to make the tests run on HTTPS. CURLOPT_SSL_VERIFYPEER => FALSE,
// Required to make the tests run on HTTPS.
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'), CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'),
CURLOPT_USERAGENT => $this->databasePrefix, CURLOPT_USERAGENT => $this->databasePrefix,
); );
@ -1132,9 +1144,10 @@ abstract class WebTestBase extends TestBase {
// Errors are being sent via X-Drupal-Assertion-* headers, // Errors are being sent via X-Drupal-Assertion-* headers,
// generated by _drupal_log_error() in the exact form required // generated by _drupal_log_error() in the exact form required
// by Drupal\simpletest\WebTestBase::error(). // by \Drupal\simpletest\WebTestBase::error().
if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) { if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) {
// Call Drupal\simpletest\WebTestBase::error() with the parameters from the header. // Call \Drupal\simpletest\WebTestBase::error() with the parameters from
// the header.
call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1]))); call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1])));
} }
@ -1215,7 +1228,8 @@ abstract class WebTestBase extends TestBase {
// previous options. // previous options.
$url = $this->container->get('url_generator')->generateFromPath($path, $options); $url = $this->container->get('url_generator')->generateFromPath($path, $options);
$out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => $url, CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers)); $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => $url, CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up. // Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
// Replace original page output with new output from redirected page(s). // Replace original page output with new output from redirected page(s).
if ($new = $this->checkForMetaRefresh()) { if ($new = $this->checkForMetaRefresh()) {
@ -1253,7 +1267,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Requests a Drupal path in drupal_ajax format, and JSON decodes the response. * Requests a Drupal path in drupal_ajax format and JSON-decodes the response.
*/ */
protected function drupalGetAJAX($path, array $options = array(), array $headers = array()) { protected function drupalGetAJAX($path, array $options = array(), array $headers = array()) {
$headers[] = 'Accept: application/vnd.drupal-ajax'; $headers[] = 'Accept: application/vnd.drupal-ajax';
@ -1261,7 +1275,8 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Execute a POST request on a Drupal page. * Executes a POST request on a Drupal page.
*
* It will be done as usual POST request with SimpleBrowser. * It will be done as usual POST request with SimpleBrowser.
* *
* @param $path * @param $path
@ -1402,10 +1417,12 @@ abstract class WebTestBase extends TestBase {
$post = implode('&', $post) . $extra_post; $post = implode('&', $post) . $extra_post;
} }
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers)); $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers));
// Ensure that any changes to variables in the other thread are picked up. // Ensure that any changes to variables in the other thread are picked
// up.
$this->refreshVariables(); $this->refreshVariables();
// Replace original page output with new output from redirected page(s). // Replace original page output with new output from redirected
// page(s).
if ($new = $this->checkForMetaRefresh()) { if ($new = $this->checkForMetaRefresh()) {
$out = $new; $out = $new;
} }
@ -1637,9 +1654,10 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Check for meta refresh tag and if found call drupalGet() recursively. This * Checks for meta refresh tag and if found call drupalGet() recursively.
* function looks for the http-equiv attribute to be set to "Refresh" *
* and is case-sensitive. * This function looks for the http-equiv attribute to be set to "Refresh" and
* is case-sensitive.
* *
* @return * @return
* Either the new page content or FALSE. * Either the new page content or FALSE.
@ -1675,7 +1693,8 @@ abstract class WebTestBase extends TestBase {
$options['absolute'] = TRUE; $options['absolute'] = TRUE;
$url = $this->container->get('url_generator')->generateFromPath($path, $options); $url = $this->container->get('url_generator')->generateFromPath($path, $options);
$out = $this->curlExec(array(CURLOPT_NOBODY => TRUE, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $headers)); $out = $this->curlExec(array(CURLOPT_NOBODY => TRUE, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $headers));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up. // Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
if ($this->dumpHeaders) { if ($this->dumpHeaders) {
$this->verbose('GET request to: ' . $path . $this->verbose('GET request to: ' . $path .
@ -1687,9 +1706,10 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Handle form input related to drupalPost(). Ensure that the specified fields * Handles form input related to drupalPost().
* exist and attempt to create POST data in the correct manner for the particular *
* field type. * Ensure that the specified fields exist and attempt to create POST data in
* the correct manner for the particular field type.
* *
* @param $post * @param $post
* Reference to array of post values. * Reference to array of post values.
@ -1886,8 +1906,9 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Perform an xpath search on the contents of the internal browser. The search * Performs an xpath search on the contents of the internal browser.
* is relative to the root element (HTML tag normally) of the page. *
* The search is relative to the root element (HTML tag normally) of the page.
* *
* @param $xpath * @param $xpath
* The xpath string to use in the search. * The xpath string to use in the search.
@ -1935,8 +1956,9 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if a link with the specified label is found, and optional with the * Passes if a link with the specified label is found.
* specified index. *
* An optional link index may be passed.
* *
* @param $label * @param $label
* Text between the anchor tags. * Text between the anchor tags.
@ -1961,7 +1983,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if a link with the specified label is not found. * Passes if a link with the specified label is not found.
* *
* @param $label * @param $label
* Text between the anchor tags. * Text between the anchor tags.
@ -1986,7 +2008,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if a link containing a given href (part) is found. * Passes if a link containing a given href (part) is found.
* *
* @param $href * @param $href
* The full or partial value of the 'href' attribute of the anchor tag. * The full or partial value of the 'href' attribute of the anchor tag.
@ -2012,7 +2034,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if a link containing a given href (part) is not found. * Passes if a link containing a given href (part) is not found.
* *
* @param $href * @param $href
* The full or partial value of the 'href' attribute of the anchor tag. * The full or partial value of the 'href' attribute of the anchor tag.
@ -2106,11 +2128,12 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Gets the HTTP response headers of the requested page. Normally we are only * Gets the HTTP response headers of the requested page.
* interested in the headers returned by the last request. However, if a page *
* is redirected or HTTP authentication is in use, multiple requests will be * Normally we are only interested in the headers returned by the last
* required to retrieve the page. Headers from all requests may be requested * request. However, if a page is redirected or HTTP authentication is in use,
* by passing TRUE to this function. * multiple requests will be required to retrieve the page. Headers from all
* requests may be requested by passing TRUE to this function.
* *
* @param $all_requests * @param $all_requests
* Boolean value specifying whether to return headers from all requests * Boolean value specifying whether to return headers from all requests
@ -2156,11 +2179,12 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Gets the value of an HTTP response header. If multiple requests were * Gets the value of an HTTP response header.
* required to retrieve the page, only the headers from the last request will *
* be checked by default. However, if TRUE is passed as the second argument, * If multiple requests were required to retrieve the page, only the headers
* all requests will be processed from last to first until the header is * from the last request will be checked by default. However, if TRUE is
* found. * passed as the second argument, all requests will be processed from last to
* first until the header is found.
* *
* @param $name * @param $name
* The name of the header to retrieve. Names are case-insensitive (see RFC * The name of the header to retrieve. Names are case-insensitive (see RFC
@ -2199,7 +2223,9 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Gets the value of the Drupal.settings JavaScript variable for the currently loaded page. * Gets the value of Drupal.settings for the currently-loaded page.
*
* Drupal.settings refers to the Drupal.settings JavaScript variable.
*/ */
protected function drupalGetSettings() { protected function drupalGetSettings() {
return $this->drupalSettings; return $this->drupalSettings;
@ -2209,7 +2235,8 @@ abstract class WebTestBase extends TestBase {
* Gets an array containing all e-mails sent during this test case. * Gets an array containing all e-mails sent during this test case.
* *
* @param $filter * @param $filter
* An array containing key/value pairs used to filter the e-mails that are returned. * An array containing key/value pairs used to filter the e-mails that are
* returned.
* @return * @return
* An array containing e-mail messages captured during the current test. * An array containing e-mail messages captured during the current test.
*/ */
@ -2230,13 +2257,14 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Sets the raw HTML content. This can be useful when a page has been fetched * Sets the raw HTML content.
* outside of the internal browser and assertions need to be made on the
* returned page.
* *
* A good example would be when testing HTTP request made by Drupal. After fetching * This can be useful when a page has been fetched outside of the internal
* the page the content can be set and page elements can be checked to ensure * browser and assertions need to be made on the returned page.
* that the function worked properly. *
* A good example would be when testing HTTP request made by Drupal. After
* fetching the page the content can be set and page elements can be checked
* to ensure that the function worked properly.
*/ */
protected function drupalSetContent($content, $url = 'internal:') { protected function drupalSetContent($content, $url = 'internal:') {
$this->content = $content; $this->content = $content;
@ -2250,14 +2278,16 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Sets the value of the Drupal.settings JavaScript variable for the currently loaded page. * Sets the value of Drupal.settings for the currently-loaded page.
*
* Drupal.settings refers to the Drupal.settings JavaScript variable.
*/ */
protected function drupalSetSettings($settings) { protected function drupalSetSettings($settings) {
$this->drupalSettings = $settings; $this->drupalSettings = $settings;
} }
/** /**
* Pass if the internal browser's URL matches the given path. * Passes if the internal browser's URL matches the given path.
* *
* @param $path * @param $path
* The expected system path. * The expected system path.
@ -2287,8 +2317,9 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the raw text IS found on the loaded page, fail otherwise. Raw text * Passes if the raw text IS found on the loaded page, fail otherwise.
* refers to the raw HTML that the page generated. *
* Raw text refers to the raw HTML that the page generated.
* *
* @param $raw * @param $raw
* Raw (HTML) string to look for. * Raw (HTML) string to look for.
@ -2312,8 +2343,9 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text * Passes if the raw text is NOT found on the loaded page, fail otherwise.
* refers to the raw HTML that the page generated. *
* Raw text refers to the raw HTML that the page generated.
* *
* @param $raw * @param $raw
* Raw (HTML) string to look for. * Raw (HTML) string to look for.
@ -2337,9 +2369,11 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the text IS found on the text version of the page. The text version * Passes if the text IS found on the text version of the page.
* is the equivalent of what a user would see when viewing through a web browser. *
* In other words the HTML has been filtered out of the contents. * The text version is the equivalent of what a user would see when viewing
* through a web browser. In other words the HTML has been filtered out of the
* contents.
* *
* @param $text * @param $text
* Plain text to look for. * Plain text to look for.
@ -2360,9 +2394,11 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the text is NOT found on the text version of the page. The text version * Passes if the text is NOT found on the text version of the page.
* is the equivalent of what a user would see when viewing through a web browser. *
* In other words the HTML has been filtered out of the contents. * The text version is the equivalent of what a user would see when viewing
* through a web browser. In other words the HTML has been filtered out of the
* contents.
* *
* @param $text * @param $text
* Plain text to look for. * Plain text to look for.
@ -2414,7 +2450,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the text is found ONLY ONCE on the text version of the page. * Passes if the text is found ONLY ONCE on the text version of the page.
* *
* The text version is the equivalent of what a user would see when viewing * The text version is the equivalent of what a user would see when viewing
* through a web browser. In other words the HTML has been filtered out of * through a web browser. In other words the HTML has been filtered out of
@ -2439,7 +2475,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Pass if the text is found MORE THAN ONCE on the text version of the page. * Passes if the text is found MORE THAN ONCE on the text version of the page.
* *
* The text version is the equivalent of what a user would see when viewing * The text version is the equivalent of what a user would see when viewing
* through a web browser. In other words the HTML has been filtered out of * through a web browser. In other words the HTML has been filtered out of
@ -2480,7 +2516,8 @@ abstract class WebTestBase extends TestBase {
* translate this string. Defaults to 'Other'; most tests do not override * translate this string. Defaults to 'Other'; most tests do not override
* this default. * this default.
* @param $be_unique * @param $be_unique
* TRUE if this text should be found only once, FALSE if it should be found more than once. * TRUE if this text should be found only once, FALSE if it should be found
* more than once.
* @return * @return
* TRUE on pass, FALSE on fail. * TRUE on pass, FALSE on fail.
*/ */
@ -2501,7 +2538,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Will trigger a pass if the Perl regex pattern is found in the raw content. * Triggers a pass if the Perl regex pattern is found in the raw content.
* *
* @param $pattern * @param $pattern
* Perl regex to look for including the regex delimiters. * Perl regex to look for including the regex delimiters.
@ -2525,7 +2562,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Will trigger a pass if the perl regex pattern is not present in raw content. * Triggers a pass if the perl regex pattern is not found in raw content.
* *
* @param $pattern * @param $pattern
* Perl regex to look for including the regex delimiters. * Perl regex to look for including the regex delimiters.
@ -2761,7 +2798,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Asserts that a field exists in the current page with the given name and value. * Asserts that a field exists with the given name and value.
* *
* @param $name * @param $name
* Name of field to assert. * Name of field to assert.
@ -2822,7 +2859,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Asserts that a field exists in the current page with the given id and value. * Asserts that a field exists with the given id and value.
* *
* @param $id * @param $id
* Id of field to assert. * Id of field to assert.
@ -3099,7 +3136,7 @@ abstract class WebTestBase extends TestBase {
} }
/** /**
* Helper function: construct an XPath for the given set of attributes and value. * Helper: Constructs an XPath for the given set of attributes and value.
* *
* @param $attribute * @param $attribute
* Field attributes. * Field attributes.
@ -3170,7 +3207,8 @@ abstract class WebTestBase extends TestBase {
* The field in $name must have the content described in $value. * The field in $name must have the content described in $value.
* *
* @param $name * @param $name
* Name of field or message property to assert. Examples: subject, body, id, ... * Name of field or message property to assert. Examples: subject, body,
* id, ...
* @param $value * @param $value
* Value of the field to assert. * Value of the field to assert.
* @param $message * @param $message

View File

@ -59,9 +59,10 @@ function hook_test_group_finished() {
* This hook is called when an individual test has finished. * This hook is called when an individual test has finished.
* *
* @param * @param
* $results The results of the test as gathered by Drupal\simpletest\WebTestBase. * $results The results of the test as gathered by
* \Drupal\simpletest\WebTestBase.
* *
* @see Drupal\simpletest\WebTestBase->results() * @see \Drupal\simpletest\WebTestBase->results()
*/ */
function hook_test_finished($results) { function hook_test_finished($results) {
} }

View File

@ -530,7 +530,7 @@ function simpletest_classloader_register() {
} }
} }
// Register the core test directory so we can find Drupal\UnitTestCase. // Register the core test directory so we can find \Drupal\UnitTestCase.
drupal_classloader()->addPrefix('Drupal\\Tests', DRUPAL_ROOT . '/core/tests'); drupal_classloader()->addPrefix('Drupal\\Tests', DRUPAL_ROOT . '/core/tests');
// Manually register phpunit prefixes because they use a classmap instead of a // Manually register phpunit prefixes because they use a classmap instead of a
@ -565,7 +565,8 @@ function simpletest_generate_file($filename, $width, $lines, $type = 'binary-tex
break; break;
} }
} }
$text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symmetrical file. // Add \n for symmetrical file.
$text = wordwrap($text, $width - 1, "\n", TRUE) . "\n";
// Create filename. // Create filename.
file_put_contents('public://' . $filename . '.txt', $text); file_put_contents('public://' . $filename . '.txt', $text);
@ -591,8 +592,7 @@ function simpletest_clean_environment() {
} }
/** /**
* Removed prefixed tables from the database that are left over from crashed * Remove prefixed tables from the database from crashed tests.
* tests.
*/ */
function simpletest_clean_database() { function simpletest_clean_database() {
$tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . '%'); $tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . '%');

View File

@ -6,7 +6,7 @@
*/ */
/** /**
* Returns HTML for a test list generated by simpletest_test_form() into a table. * Returns an HTML table for a test list generated by simpletest_test_form().
* *
* @param $variables * @param $variables
* An associative array containing: * An associative array containing: