annotate core/modules/update/tests/src/Functional/UpdateTestBase.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\update\Functional;
Chris@0 4
Chris@0 5 use Drupal\Core\DrupalKernel;
Chris@0 6 use Drupal\Core\Url;
Chris@0 7 use Drupal\Tests\BrowserTestBase;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Defines some shared functions used by all update tests.
Chris@0 11 *
Chris@0 12 * The overarching methodology of these tests is we need to compare a given
Chris@0 13 * state of installed modules and themes (e.g., version, project grouping,
Chris@0 14 * timestamps, etc) against a current state of what the release history XML
Chris@0 15 * files we fetch say is available. We have dummy XML files (in the
Chris@0 16 * core/modules/update/tests directory) that describe various scenarios of
Chris@0 17 * what's available for different test projects, and we have dummy .info file
Chris@0 18 * data (specified via hook_system_info_alter() in the update_test helper
Chris@0 19 * module) describing what's currently installed. Each test case defines a set
Chris@0 20 * of projects to install, their current state (via the
Chris@0 21 * 'update_test_system_info' variable) and the desired available update data
Chris@0 22 * (via the 'update_test_xml_map' variable), and then performs a series of
Chris@0 23 * assertions that the report matches our expectations given the specific
Chris@0 24 * initial state and availability scenario.
Chris@0 25 */
Chris@0 26 abstract class UpdateTestBase extends BrowserTestBase {
Chris@0 27
Chris@0 28 protected function setUp() {
Chris@0 29 parent::setUp();
Chris@0 30
Chris@0 31 // Change the root path which Update Manager uses to install and update
Chris@0 32 // projects to be inside the testing site directory. See
Chris@0 33 // \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
Chris@0 34 // test child site.
Chris@0 35 $request = \Drupal::request();
Chris@0 36 $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
Chris@0 37 $this->container->set('update.root', $update_root);
Chris@0 38 \Drupal::setContainer($this->container);
Chris@0 39
Chris@0 40 // Create the directories within the root path within which the Update
Chris@0 41 // Manager will install projects.
Chris@0 42 foreach (drupal_get_updaters() as $updater_info) {
Chris@0 43 $updater = $updater_info['class'];
Chris@0 44 $install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
Chris@0 45 if (!is_dir($install_directory)) {
Chris@0 46 mkdir($install_directory);
Chris@0 47 }
Chris@0 48 }
Chris@0 49 }
Chris@0 50
Chris@0 51 /**
Chris@0 52 * Refreshes the update status based on the desired available update scenario.
Chris@0 53 *
Chris@0 54 * @param $xml_map
Chris@0 55 * Array that maps project names to availability scenarios to fetch. The key
Chris@0 56 * '#all' is used if a project-specific mapping is not defined.
Chris@0 57 * @param $url
Chris@0 58 * (optional) A string containing the URL to fetch update data from.
Chris@0 59 * Defaults to 'update-test'.
Chris@0 60 *
Chris@0 61 * @see \Drupal\update_test\Controller\UpdateTestController::updateTest()
Chris@0 62 */
Chris@0 63 protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
Chris@0 64 // Tell the Update Manager module to fetch from the URL provided by
Chris@0 65 // update_test module.
Chris@0 66 $this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save();
Chris@0 67 // Save the map for UpdateTestController::updateTest() to use.
Chris@0 68 $this->config('update_test.settings')->set('xml_map', $xml_map)->save();
Chris@0 69 // Manually check the update status.
Chris@0 70 $this->drupalGet('admin/reports/updates');
Chris@0 71 $this->clickLink(t('Check manually'));
Chris@0 72 $this->checkForMetaRefresh();
Chris@0 73 }
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Runs a series of assertions that are applicable to all update statuses.
Chris@0 77 */
Chris@0 78 protected function standardTests() {
Chris@0 79 $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
Chris@0 80 $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.');
Chris@0 81 $this->assertNoText(t('No available releases found'));
Chris@0 82 }
Chris@0 83
Chris@0 84 }