Commit b45af923 authored by webchick's avatar webchick

Issue #2382195 by tibbsa, subhojit777, tadityar, cilefen, Mile23: Clean-up...

Issue #2382195 by tibbsa, subhojit777, tadityar, cilefen, Mile23: Clean-up simpletest module test members - ensure property definition and use of camelCase naming convention
parent 41cb2391
......@@ -26,7 +26,7 @@ class BlockHtmlTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
// Enable the test_html block, to test HTML ID and attributes.
\Drupal::state()->set('block_test.attributes', array('data-custom-attribute' => 'foo'));
......
......@@ -46,7 +46,7 @@ protected function setUp() {
// roles are created then the role is lost after import. If the roles
// created have the same name then the sync will fail because they will
// have different UUIDs.
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
}
/**
......
......@@ -27,7 +27,7 @@ class FieldUIRouteTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
}
/**
......
......@@ -56,7 +56,7 @@ public function testConfigOverrideImport() {
$this->drupalGet('fr');
$this->assertText('FR default site name');
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
$this->assertText('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
}
......
......@@ -34,7 +34,7 @@ public function setUp() {
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->config('system.site')->set('langcode', 'fr')->save();
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
}
/**
......
......@@ -53,7 +53,7 @@ protected function setUp() {
$this->noAccessUser2 = $this->drupalCreateUser(array('access content overview', 'access content'));
$this->userMapping = [
1 => $this->root_user,
1 => $this->rootUser,
2 => $this->accessUser,
3 => $this->noAccessUser,
];
......
......@@ -165,7 +165,7 @@ public function testAdminFrontPage() {
// contextual links to the homepage view. This verifies there are no errors.
\Drupal::service('module_installer')->install(array('views_ui'));
// Login root user with sufficient permissions.
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
// Test frontpage view.
$this->drupalGet('node');
$this->assertResponse(200);
......
......@@ -290,7 +290,7 @@ protected function doPageRdfaTests() {
* Tests that user data is exposed on user page.
*/
protected function doUserRdfaTests() {
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
// Feed the HTML into the parser.
$graph = $this->getRdfGraph($this->adminUser->getSystemPath());
......
......@@ -104,7 +104,7 @@ public function testShortcutQuickLink() {
$this->config('node.settings')->set('use_admin_theme', '1')->save();
$this->container->get('router.builder')->rebuild();
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/config/system/cron');
// Test the "Add to shortcuts" link.
......@@ -165,7 +165,7 @@ public function testShortcutLinkChangePath() {
* Tests that changing the route of a shortcut link works.
*/
public function testShortcutLinkChangeRoute() {
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/content');
$this->assertResponse(200);
// Disable the view.
......@@ -242,7 +242,7 @@ public function testAccessShortcutsPermission() {
->save();
// Add cron to the default shortcut set.
$this->drupalLogin($this->root_user);
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/config/system/cron');
$this->clickLink('Add to Default shortcuts');
......
......@@ -78,7 +78,7 @@ protected function setUp() {
$this->isInstalled = FALSE;
// Define information about the user 1 account.
$this->root_user = new UserSession(array(
$this->rootUser = new UserSession(array(
'uid' => 1,
'name' => 'admin',
'mail' => 'admin@example.com',
......
......@@ -209,8 +209,8 @@ protected function setUp() {
// StreamWrapper APIs.
// @todo Move StreamWrapper management into DrupalKernel.
// @see https://drupal.org/node/2028109
file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$this->settingsSet('file_public_path', $this->public_files_directory);
file_prepare_directory($this->publicFilesDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$this->settingsSet('file_public_path', $this->publicFilesDirectory);
$this->streamWrappers = array();
$this->registerStreamWrapper('public', 'Drupal\Core\StreamWrapper\PublicStream');
// The temporary stream wrapper is able to operate both with and without
......
......@@ -54,20 +54,6 @@ abstract class TestBase {
*/
protected $databasePrefix = NULL;
/**
* The site directory of the original parent site.
*
* @var string
*/
protected $originalSite;
/**
* The original file directory, before it was changed for testing purposes.
*
* @var string
*/
protected $originalFileDirectory = NULL;
/**
* Time limit for the test.
*/
......@@ -132,6 +118,60 @@ abstract class TestBase {
*/
protected $verboseDirectory;
/**
* URL to the verbose output file directory.
*
* @var string
*/
protected $verboseDirectoryUrl;
/**
* The original configuration (variables), if available.
*
* @var string
* @todo Remove all remnants of $GLOBALS['conf'].
* @see https://drupal.org/node/2183323
*/
protected $originalConf;
/**
* The original configuration (variables).
*
* @var string
*/
protected $originalConfig;
/**
* The original configuration directories.
*
* An array of paths keyed by the CONFIG_*_DIRECTORY constants defined by
* core/includes/bootstrap.inc.
*
* @var array
*/
protected $originalConfigDirectories;
/**
* The original container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $originalContainer;
/**
* The original file directory, before it was changed for testing purposes.
*
* @var string
*/
protected $originalFileDirectory = NULL;
/**
* The original language.
*
* @var \Drupal\Core\Language\LanguageInterface
*/
protected $originalLanguage;
/**
* The original database prefix when running inside Simpletest.
*
......@@ -140,17 +180,47 @@ abstract class TestBase {
protected $originalPrefix;
/**
* URL to the verbose output file directory.
* The original installation profile.
*
* @var string
*/
protected $verboseDirectoryUrl;
protected $originalProfile;
/**
* The name of the session cookie.
*
* @var string
*/
protected $originalSessionName;
/**
* The settings array.
*
* @var array
*/
protected $originalSettings;
/**
* The original array of shutdown function callbacks.
*
* @var array
*/
protected $originalShutdownCallbacks;
/**
* The site directory of the original parent site.
*
* @var string
*/
protected $originalSite;
/**
* The original user, before testing began.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $originalUser;
/**
* The public file directory for the test environment.
*
......@@ -158,7 +228,7 @@ abstract class TestBase {
*
* @var string
*/
protected $public_files_directory;
protected $publicFilesDirectory;
/**
* The private file directory for the test environment.
......@@ -167,7 +237,25 @@ abstract class TestBase {
*
* @var string
*/
protected $private_files_directory;
protected $privateFilesDirectory;
/**
* The temporary file directory for the test environment.
*
* This is set in TestBase::prepareEnvironment().
*
* @var string
*/
protected $tempFilesDirectory;
/**
* The translation file directory for the test environment.
*
* This is set in TestBase::prepareEnvironment().
*
* @var string
*/
protected $translationFilesDirectory;
/**
* Whether to die in case any test assertion fails.
......@@ -206,11 +294,6 @@ abstract class TestBase {
*/
protected $randomGenerator;
/**
* The name of the session cookie.
*/
protected $originalSessionName;
/**
* Set to TRUE to strict check all configuration saved.
*
......@@ -220,6 +303,21 @@ abstract class TestBase {
*/
protected $strictConfigSchema = TRUE;
/**
* HTTP authentication method (specified as a CURLAUTH_* constant).
*
* @var int
* @see http://php.net/manual/en/function.curl-setopt.php
*/
protected $httpAuthMethod = CURLAUTH_BASIC;
/**
* HTTP authentication credentials (<username>:<password>).
*
* @var string
*/
protected $httpAuthCredentials = NULL;
/**
* Constructor for Test.
*
......@@ -804,6 +902,7 @@ public function run(array $methods = array()) {
if (!isset($this->verbose)) {
$this->verbose = $simpletest_config->get('verbose');
}
if ($this->verbose) {
// Initialize verbose debugging.
$this->verbose = TRUE;
......@@ -816,11 +915,11 @@ public function run(array $methods = array()) {
}
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
$this->httpauth_method = (int) $simpletest_config->get('httpauth.method');
$this->httpAuthMethod = (int) $simpletest_config->get('httpauth.method');
$username = $simpletest_config->get('httpauth.username');
$password = $simpletest_config->get('httpauth.password');
if (!empty($username) && !empty($password)) {
$this->httpauth_credentials = $username . ':' . $password;
$this->httpAuthCredentials = $username . ':' . $password;
}
set_error_handler(array($this, 'errorHandler'));
......@@ -1064,10 +1163,10 @@ private function prepareEnvironment() {
file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Prepare filesystem directory paths.
$this->public_files_directory = $this->siteDirectory . '/files';
$this->private_files_directory = $this->siteDirectory . '/private';
$this->temp_files_directory = $this->siteDirectory . '/temp';
$this->translation_files_directory = $this->siteDirectory . '/translations';
$this->publicFilesDirectory = $this->siteDirectory . '/files';
$this->privateFilesDirectory = $this->siteDirectory . '/private';
$this->tempFilesDirectory = $this->siteDirectory . '/temp';
$this->translationFilesDirectory = $this->siteDirectory . '/translations';
$this->generatedTestFiles = FALSE;
......
......@@ -41,7 +41,7 @@ protected function setUp() {
if (!$this->isInChildSite()) {
parent::setUp();
$this->sharedTriggerFile = $this->public_files_directory . '/trigger';
$this->sharedTriggerFile = $this->publicFilesDirectory . '/trigger';
// Create and log in user.
$admin_user = $this->drupalCreateUser(array('administer unit tests'));
......
......@@ -23,6 +23,13 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
*/
public static $modules = array('simpletest');
/**
* An administrative user with permission to adminsiter unit tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Use the Testing profile.
*
......@@ -40,8 +47,8 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->admin_user);
$this->adminUser = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->adminUser);
}
/**
......
......@@ -38,11 +38,18 @@ class OtherInstallationProfileTestsTest extends WebTestBase {
*/
protected $profile = 'minimal';
/**
* An administrative user with permission to administer unit tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->admin_user);
$this->adminUser = $this->drupalCreateUser(array('administer unit tests'));
$this->drupalLogin($this->adminUser);
}
/**
......
......@@ -38,7 +38,7 @@ class SimpleTestTest extends WebTestBase {
*
* Used to ensure they are incrementing.
*/
protected $test_ids = array();
protected $testIds = array();
/**
* Translated fail message.
......@@ -53,6 +53,20 @@ class SimpleTestTest extends WebTestBase {
*/
private $passMessage = '';
/**
* A valid and recognized permission.
*
* @var string
*/
protected $validPermission;
/**
* An invalid or unrecognized permission.
*
* @var string
*/
protected $invalidPermission;
protected function setUp() {
if (!$this->isInChildSite()) {
$php = <<<'EOD'
......@@ -103,8 +117,8 @@ class: Drupal\Core\Cache\MemoryBackendFactory
function testWebTestRunner() {
$this->passMessage = t('SimpleTest pass.');
$this->failMessage = t('SimpleTest fail.');
$this->valid_permission = 'access administration pages';
$this->invalid_permission = 'invalid permission';
$this->validPermission = 'access administration pages';
$this->invalidPermission = 'invalid permission';
if ($this->isInChildSite()) {
// Only run following code if this test is running itself through a CURL
......@@ -128,7 +142,7 @@ function testWebTestRunner() {
// Regression test for #290316.
// Check that test_id is incrementing.
$this->assertTrue($this->test_ids[0] != $this->test_ids[1], 'Test ID is incrementing.');
$this->assertTrue($this->testIds[0] != $this->testIds[1], 'Test ID is incrementing.');
}
}
......@@ -162,10 +176,10 @@ function stubTest() {
// This causes the second to fourth of the fifteen passes asserted in
// confirmStubResults().
$user = $this->drupalCreateUser(array($this->valid_permission), 'SimpleTestTest');
$user = $this->drupalCreateUser(array($this->validPermission), 'SimpleTestTest');
// This causes the fifth of the five fails asserted in confirmStubResults().
$this->drupalCreateUser(array($this->invalid_permission));
$this->drupalCreateUser(array($this->invalidPermission));
// Test logging in as a user.
// This causes the fifth to ninth of the fifteen passes asserted in
......@@ -215,8 +229,8 @@ function confirmStubTestResults() {
$this->assertAssertion($this->passMessage, 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion($this->failMessage, 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->validPermission)), 'Role', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
$this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalidPermission)), 'Role', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
// Check that the user was logged in successfully.
$this->assertAssertion('User SimpleTestTest successfully logged in.', 'User login', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
......@@ -237,7 +251,7 @@ function confirmStubTestResults() {
$this->assertEqual('15 passes, 3 fails, 2 exceptions, 3 debug messages', $this->childTestResults['summary']);
$this->test_ids[] = $test_id = $this->getTestIdFromResults();
$this->testIds[] = $test_id = $this->getTestIdFromResults();
$this->assertTrue($test_id, 'Found test ID in results.');
}
......
......@@ -67,6 +67,13 @@ abstract class WebTestBase extends TestBase {
*/
protected $headers;
/**
* The cookies of the page currently loaded in the internal browser.
*
* @var array
*/
protected $cookies;
/**
* Indicates that headers should be dumped if verbose output is enabled.
*
......@@ -84,6 +91,14 @@ abstract class WebTestBase extends TestBase {
*/
protected $loggedInUser = FALSE;
/**
* The "#1" admin user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $rootUser;
/**
* The current cookie file used by cURL.
*
......@@ -100,6 +115,13 @@ abstract class WebTestBase extends TestBase {
*/
protected $additionalCurlOptions = array();
/**
* The original batch, before it was changed for testing purposes.
*
* @var array
*/
protected $originalBatch;
/**
* The original user, before it was changed to a clean uid = 1 for testing.
*
......@@ -114,25 +136,15 @@ abstract class WebTestBase extends TestBase {
*/
protected $originalShutdownCallbacks = array();
/**
* HTTP authentication method.
*/
protected $httpauth_method = CURLAUTH_BASIC;
/**
* HTTP authentication credentials (<username>:<password>).
*/
protected $httpauth_credentials = NULL;
/**
* The current session name, if available.
*/
protected $session_name = NULL;
protected $sessionName = NULL;
/**
* The current session ID, if available.
*/
protected $session_id = NULL;
protected $sessionId = NULL;
/**
* Whether the files were copied to the test files directory.
......@@ -147,7 +159,7 @@ abstract class WebTestBase extends TestBase {
/**
* The number of redirects followed during the handling of a request.
*/
protected $redirect_count;
protected $redirectCount;
/**
* The kernel used in this test.
......@@ -678,8 +690,8 @@ protected function drupalLogin(AccountInterface $account) {
$this->drupalPostForm('user/login', $edit, t('Log in'));
// @see WebTestBase::drupalUserIsLoggedIn()
if (isset($this->session_id)) {
$account->session_id = $this->session_id;
if (isset($this->sessionId)) {
$account->session_id = $this->sessionId;
}
$pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', array('%name' => $account->getUsername())), 'User login');
if ($pass) {
......@@ -732,7 +744,7 @@ protected function drupalLogout() {
* The name of the session cookie.
*/
public function getSessionName() {
return $this->session_name;
return $this->sessionName;
}
/**
......@@ -759,7 +771,7 @@ protected function setUp() {
$this->originalBatch = batch_get();
// Define information about the user 1 account.
$this->root_user = new UserSession(array(
$this->rootUser = new UserSession(array(
'uid' => 1,
'name' => 'admin',
'mail' => 'admin@example.com',
......@@ -770,7 +782,7 @@ protected function setUp() {
// proper session cookies were set on a response. Because the child site
// uses the same session name as the test runner, it is necessary to make
// that available to test-methods.
$this->session_name = $this->originalSessionName;
$this->sessionName = $this->originalSessionName;
// Reset the static batch to remove Simpletest's batch operations.
$batch = &batch_get();
......@@ -791,11 +803,11 @@ protected function setUp() {
// @see system_requirements()
// @see TestBase::prepareEnvironment()
$settings['settings']['file_public_path'] = (object) array(
'value' => $this->public_files_directory,
'value' => $this->publicFilesDirectory,
'required' => TRUE,
);
$settings['settings']['file_private_path'] = (object) array(
'value' => $this->private_files_directory,
'value' => $this->privateFilesDirectory,
'required' => TRUE,
);
// Save the original site directory path, so that extensions in the
......@@ -875,10 +887,10 @@ protected function setUp() {
// While these could be preset/enforced in settings.php like the public
// files directory above, some tests expect them to be configurable in the
// UI. If declared in settings.php, they would no longer be configurable.
file_prepare_directory($this->private_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($this->temp_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY);
$config->get('system.file')
->set('path.temporary', $this->temp_files_directory)
->set('path.temporary', $this->tempFilesDirectory)
->save();
// Manually configure the test mail collector implementation to prevent
......@@ -973,11 +985,11 @@ protected function installParameters() {
'site_name' => 'Drupal',
'site_mail' => 'simpletest@example.com',
'account' => array(
'name' => $this->root_user->name,
'mail' => $this->root_user->getEmail(),
'name' => $this->rootUser->name,
'mail' => $this->rootUser->getEmail(),
'pass' => array(
'pass1' => $this->root_user->pass_raw,
'pass2' => $this->root_user->pass_raw,
'pass1' => $this->rootUser->pass_raw,
'pass2' => $this->rootUser->pass_raw,
),
),
// \Drupal\Core\Render\Element\Checkboxes::valueCallback() requires
......@@ -1209,7 +1221,7 @@ protected function curlInitialize() {
// Some versions/configurations of cURL break on a NULL cookie jar, so
// supply a real file.
if (empty($this->cookieFile)) {
$this->cookieFile = $this->public_files_directory . '/cookie.jar';
$this->cookieFile = $this->publicFilesDirectory . '/cookie.jar';
}
$curl_options = array(
......@@ -1224,9 +1236,9 @@ protected function curlInitialize() {
CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'),
CURLOPT_USERAGENT => $this->databasePrefix,
);
if (isset($this->httpauth_credentials)) {
$curl_options[CURLOPT_HTTPAUTH] = $this->httpauth_method;
$curl_options[CURLOPT_USERPWD] = $this->httpauth_credentials;
if (isset($this->httpAuthCredentials)) {
$curl_options[CURLOPT_HTTPAUTH] = $this->httpAuthMethod;
$curl_options[CURLOPT_USERPWD] = $this->httpAuthCredentials;
}
// curl_setopt_array() returns FALSE if any of the specified options
// cannot be set, and stops processing any further options.
......@@ -1330,9 +1342,9 @@ protected function curlExec($curl_options, $redirect = FALSE) {
if (!$redirect) {
// Reset headers, the session ID and the redirect counter.
$this->session_id = NULL;
$this->sessionId = NULL;
$this->headers = array();
$this->redirect_count = 0;
$this->redirectCount = 0;
}
$content = curl_exec($this->curlHandle);
......@@ -1343,9 +1355,9 @@ protected function curlExec($curl_options, $redirect = FALSE) {
// to prevent fragments being sent to the web server as part
// of the request.
// TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
if (in_array($status, array(300, 301, 302, 303, 305, 307)) && $this->redirect_count < $this->maximumRedirects) {
if (in_array($status, array(300, 301, 302, 303, 305, 307)) && $this->redirectCount < $this->maximumRedirects) {
if ($this->drupalGetHeader('location')) {
$this->redirect_count++;
$this->redirectCount++;
$curl_options = array();
$curl_options[CURLOPT_URL] = $this->drupalGetHeader('location');
$curl_options[CURLOPT_HTTPGET] = TRUE;
......@@ -1404,12 +1416,12 @@ protected function curlHeaderCallback($curlHandler, $header) {
$parts = array_map('trim', explode(';', $matches[2]));
$value = array_shift($parts);
$this->cookies[$name] = array('value' => $value, 'secure' => in_array('secure', $parts));
if ($name == $this->session_name) {
if ($name == $this->sessionName) {
if ($value != 'deleted') {
$this->session_id = $value;
$this->sessionId = $value;
}
else {
$this->session_id = NULL;
$this->sessionId = NULL;
}
}
}
......