summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-06-27 15:11:05 (GMT)
committerGabor Hojtsy2017-06-27 15:11:05 (GMT)
commitfa54442c291bfe1118803d2e8ffeac3a1abeb5b1 (patch)
tree233038f7fecface355c6b5588087e82062916bae
parent4d45aabb74e2bade3ed7c7cb74c6bf0a7f00d229 (diff)
Issue #2870464 by naveenvalecha, Antonnavi, dawehner, Lendude: Convert web tests to browser tests for update module
-rw-r--r--core/modules/update/src/Tests/UpdateTestBase.php7
-rw-r--r--core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php (renamed from core/modules/update/src/Tests/FileTransferAuthorizeFormTest.php)4
-rw-r--r--core/modules/update/tests/src/Functional/UpdateContribTest.php (renamed from core/modules/update/src/Tests/UpdateContribTest.php)2
-rw-r--r--core/modules/update/tests/src/Functional/UpdateCoreTest.php (renamed from core/modules/update/src/Tests/UpdateCoreTest.php)10
-rw-r--r--core/modules/update/tests/src/Functional/UpdateDeleteFileIfStaleTest.php (renamed from core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php)2
-rw-r--r--core/modules/update/tests/src/Functional/UpdateTestBase.php84
-rw-r--r--core/modules/update/tests/src/Functional/UpdateUploadTest.php (renamed from core/modules/update/src/Tests/UpdateUploadTest.php)11
7 files changed, 111 insertions, 9 deletions
diff --git a/core/modules/update/src/Tests/UpdateTestBase.php b/core/modules/update/src/Tests/UpdateTestBase.php
index fc39d1a..e243d0b 100644
--- a/core/modules/update/src/Tests/UpdateTestBase.php
+++ b/core/modules/update/src/Tests/UpdateTestBase.php
@@ -2,6 +2,8 @@
namespace Drupal\update\Tests;
+@trigger_error(__NAMESPACE__ . '\UpdateTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\update\Functional\UpdateTestBase', E_USER_DEPRECATED);
+
use Drupal\Core\DrupalKernel;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
@@ -22,6 +24,9 @@ use Drupal\simpletest\WebTestBase;
* (via the 'update_test_xml_map' variable), and then performs a series of
* assertions that the report matches our expectations given the specific
* initial state and availability scenario.
+ *
+ * @deprecated Scheduled for removal in Drupal 9.0.0.
+ * Use \Drupal\Tests\update\Functional\UpdateTestBase instead.
*/
abstract class UpdateTestBase extends WebTestBase {
@@ -58,7 +63,7 @@ abstract class UpdateTestBase extends WebTestBase {
* (optional) A string containing the URL to fetch update data from.
* Defaults to 'update-test'.
*
- * @see Drupal\update_test\Controller\UpdateTestController::updateTest()
+ * @see \Drupal\update_test\Controller\UpdateTestController::updateTest()
*/
protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
// Tell the Update Manager module to fetch from the URL provided by
diff --git a/core/modules/update/src/Tests/FileTransferAuthorizeFormTest.php b/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php
index 9d1819f..d768b06 100644
--- a/core/modules/update/src/Tests/FileTransferAuthorizeFormTest.php
+++ b/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\update\Tests;
+namespace Drupal\Tests\update\Functional;
/**
* Tests the Update Manager module upload via authorize.php functionality.
@@ -23,7 +23,7 @@ class FileTransferAuthorizeFormTest extends UpdateTestBase {
// Create a local cache so the module is not downloaded from drupal.org.
$cache_directory = _update_manager_cache_directory(TRUE);
- $validArchiveFile = __DIR__ . '/../../tests/update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
+ $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
copy($validArchiveFile, $cache_directory . '/update_test_new_module.tar.gz');
}
diff --git a/core/modules/update/src/Tests/UpdateContribTest.php b/core/modules/update/tests/src/Functional/UpdateContribTest.php
index 81f7117..20d397c 100644
--- a/core/modules/update/src/Tests/UpdateContribTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateContribTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\update\Tests;
+namespace Drupal\Tests\update\Functional;
use Drupal\Core\Url;
use Drupal\Core\Utility\ProjectInfo;
diff --git a/core/modules/update/src/Tests/UpdateCoreTest.php b/core/modules/update/tests/src/Functional/UpdateCoreTest.php
index b6287c7..5cd4b10 100644
--- a/core/modules/update/src/Tests/UpdateCoreTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateCoreTest.php
@@ -1,8 +1,9 @@
<?php
-namespace Drupal\update\Tests;
+namespace Drupal\Tests\update\Functional;
use Drupal\Core\Url;
+use Drupal\Tests\Traits\Core\CronRunTrait;
/**
* Tests the Update Manager module through a series of functional tests using
@@ -12,6 +13,8 @@ use Drupal\Core\Url;
*/
class UpdateCoreTest extends UpdateTestBase {
+ use CronRunTrait;
+
/**
* Modules to enable.
*
@@ -76,6 +79,7 @@ class UpdateCoreTest extends UpdateTestBase {
$this->standardTests();
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
$this->assertNoText(t('Security update required!'));
$this->assertRaw(\Drupal::l("8.$minor_version.1" . $extra_version, Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release")), 'Link to release appears.');
$this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version.tar.gz")), 'Link to download appears.');
@@ -139,6 +143,7 @@ class UpdateCoreTest extends UpdateTestBase {
$this->standardTests();
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
$this->assertNoText(t('Security update required!'));
$this->assertRaw(\Drupal::l('9.0.0', Url::fromUri("http://example.com/drupal-9-0-0-release")), 'Link to release appears.');
$this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-9-0-0.tar.gz")), 'Link to download appears.');
@@ -226,6 +231,7 @@ class UpdateCoreTest extends UpdateTestBase {
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
@@ -247,6 +253,7 @@ class UpdateCoreTest extends UpdateTestBase {
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertText(t('There are updates available for your version of Drupal.'));
@@ -268,6 +275,7 @@ class UpdateCoreTest extends UpdateTestBase {
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
diff --git a/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php b/core/modules/update/tests/src/Functional/UpdateDeleteFileIfStaleTest.php
index 99499d7..601a6cc 100644
--- a/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateDeleteFileIfStaleTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\update\Tests;
+namespace Drupal\Tests\update\Functional;
/**
* Tests the update_delete_file_if_stale() function.
diff --git a/core/modules/update/tests/src/Functional/UpdateTestBase.php b/core/modules/update/tests/src/Functional/UpdateTestBase.php
new file mode 100644
index 0000000..a4d07d0
--- /dev/null
+++ b/core/modules/update/tests/src/Functional/UpdateTestBase.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Drupal\Tests\update\Functional;
+
+use Drupal\Core\DrupalKernel;
+use Drupal\Core\Url;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Defines some shared functions used by all update tests.
+ *
+ * The overarching methodology of these tests is we need to compare a given
+ * state of installed modules and themes (e.g., version, project grouping,
+ * timestamps, etc) against a current state of what the release history XML
+ * files we fetch say is available. We have dummy XML files (in the
+ * core/modules/update/tests directory) that describe various scenarios of
+ * what's available for different test projects, and we have dummy .info file
+ * data (specified via hook_system_info_alter() in the update_test helper
+ * module) describing what's currently installed. Each test case defines a set
+ * of projects to install, their current state (via the
+ * 'update_test_system_info' variable) and the desired available update data
+ * (via the 'update_test_xml_map' variable), and then performs a series of
+ * assertions that the report matches our expectations given the specific
+ * initial state and availability scenario.
+ */
+abstract class UpdateTestBase extends BrowserTestBase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ // Change the root path which Update Manager uses to install and update
+ // projects to be inside the testing site directory. See
+ // \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
+ // test child site.
+ $request = \Drupal::request();
+ $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
+ $this->container->set('update.root', $update_root);
+ \Drupal::setContainer($this->container);
+
+ // Create the directories within the root path within which the Update
+ // Manager will install projects.
+ foreach (drupal_get_updaters() as $updater_info) {
+ $updater = $updater_info['class'];
+ $install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
+ if (!is_dir($install_directory)) {
+ mkdir($install_directory);
+ }
+ }
+ }
+
+ /**
+ * Refreshes the update status based on the desired available update scenario.
+ *
+ * @param $xml_map
+ * Array that maps project names to availability scenarios to fetch. The key
+ * '#all' is used if a project-specific mapping is not defined.
+ * @param $url
+ * (optional) A string containing the URL to fetch update data from.
+ * Defaults to 'update-test'.
+ *
+ * @see \Drupal\update_test\Controller\UpdateTestController::updateTest()
+ */
+ protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
+ // Tell the Update Manager module to fetch from the URL provided by
+ // update_test module.
+ $this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save();
+ // Save the map for UpdateTestController::updateTest() to use.
+ $this->config('update_test.settings')->set('xml_map', $xml_map)->save();
+ // Manually check the update status.
+ $this->drupalGet('admin/reports/updates');
+ $this->clickLink(t('Check manually'));
+ $this->checkForMetaRefresh();
+ }
+
+ /**
+ * Runs a series of assertions that are applicable to all update statuses.
+ */
+ protected function standardTests() {
+ $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
+ $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.');
+ $this->assertNoText(t('No available releases found'));
+ }
+
+}
diff --git a/core/modules/update/src/Tests/UpdateUploadTest.php b/core/modules/update/tests/src/Functional/UpdateUploadTest.php
index 80d3f15..6096620 100644
--- a/core/modules/update/src/Tests/UpdateUploadTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateUploadTest.php
@@ -1,10 +1,11 @@
<?php
-namespace Drupal\update\Tests;
+namespace Drupal\Tests\update\Functional;
use Drupal\Core\Extension\InfoParserDynamic;
use Drupal\Core\Updater\Updater;
use Drupal\Core\Url;
+use Drupal\Tests\TestFileCreationTrait;
/**
* Tests the Update Manager module's upload and extraction functionality.
@@ -13,6 +14,10 @@ use Drupal\Core\Url;
*/
class UpdateUploadTest extends UpdateTestBase {
+ use TestFileCreationTrait {
+ getTestFiles as drupalGetTestFiles;
+ }
+
/**
* Modules to enable.
*
@@ -50,7 +55,7 @@ class UpdateUploadTest extends UpdateTestBase {
// Check to ensure an existing module can't be reinstalled. Also checks that
// the archive was extracted since we can't know if the module is already
// installed until after extraction.
- $validArchiveFile = __DIR__ . '/../../tests/aaa_update_test.tar.gz';
+ $validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];
@@ -63,7 +68,7 @@ class UpdateUploadTest extends UpdateTestBase {
$moduleUpdater = $updaters['module']['class'];
$installedInfoFilePath = $this->container->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml';
$this->assertFalse(file_exists($installedInfoFilePath), 'The new module does not exist in the filesystem before it is installed with the Update Manager.');
- $validArchiveFile = __DIR__ . '/../../tests/update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
+ $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
$edit = [
'files[project_upload]' => $validArchiveFile,
];