Mercurial > hg > isophonics-drupal-site
comparison core/modules/simpletest/src/WebTestBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
5 use Drupal\block\Entity\Block; | 5 use Drupal\block\Entity\Block; |
6 use Drupal\Component\Serialization\Json; | 6 use Drupal\Component\Serialization\Json; |
7 use Drupal\Component\Utility\Html; | 7 use Drupal\Component\Utility\Html; |
8 use Drupal\Component\Utility\NestedArray; | 8 use Drupal\Component\Utility\NestedArray; |
9 use Drupal\Component\Utility\UrlHelper; | 9 use Drupal\Component\Utility\UrlHelper; |
10 use Drupal\Component\Utility\SafeMarkup; | 10 use Drupal\Component\Render\FormattableMarkup; |
11 use Drupal\Core\EventSubscriber\AjaxResponseSubscriber; | 11 use Drupal\Core\EventSubscriber\AjaxResponseSubscriber; |
12 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; | 12 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; |
13 use Drupal\Core\Session\AccountInterface; | 13 use Drupal\Core\Session\AccountInterface; |
14 use Drupal\Core\Session\AnonymousUserSession; | 14 use Drupal\Core\Session\AnonymousUserSession; |
15 use Drupal\Core\Test\AssertMailTrait; | 15 use Drupal\Core\Test\AssertMailTrait; |
284 $this->drupalLogout(); | 284 $this->drupalLogout(); |
285 } | 285 } |
286 | 286 |
287 $edit = [ | 287 $edit = [ |
288 'name' => $account->getUsername(), | 288 'name' => $account->getUsername(), |
289 'pass' => $account->pass_raw | 289 'pass' => $account->pass_raw, |
290 ]; | 290 ]; |
291 $this->drupalPostForm('user/login', $edit, t('Log in')); | 291 $this->drupalPostForm('user/login', $edit, t('Log in')); |
292 | 292 |
293 // @see WebTestBase::drupalUserIsLoggedIn() | 293 // @see WebTestBase::drupalUserIsLoggedIn() |
294 if (isset($this->sessionId)) { | 294 if (isset($this->sessionId)) { |
658 | 658 |
659 $message_vars = [ | 659 $message_vars = [ |
660 '@method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), | 660 '@method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), |
661 '@url' => isset($original_url) ? $original_url : $url, | 661 '@url' => isset($original_url) ? $original_url : $url, |
662 '@status' => $status, | 662 '@status' => $status, |
663 '@length' => format_size(strlen($this->getRawContent())) | 663 '@length' => format_size(strlen($this->getRawContent())), |
664 ]; | 664 ]; |
665 $message = SafeMarkup::format('@method @url returned @status (@length).', $message_vars); | 665 $message = new FormattableMarkup('@method @url returned @status (@length).', $message_vars); |
666 $this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser'); | 666 $this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser'); |
667 return $this->getRawContent(); | 667 return $this->getRawContent(); |
668 } | 668 } |
669 | 669 |
670 /** | 670 /** |
696 $parameters = unserialize(urldecode($matches[1])); | 696 $parameters = unserialize(urldecode($matches[1])); |
697 // Handle deprecation notices triggered by system under test. | 697 // Handle deprecation notices triggered by system under test. |
698 if ($parameters[1] === 'User deprecated function') { | 698 if ($parameters[1] === 'User deprecated function') { |
699 if (getenv('SYMFONY_DEPRECATIONS_HELPER') !== 'disabled') { | 699 if (getenv('SYMFONY_DEPRECATIONS_HELPER') !== 'disabled') { |
700 $message = (string) $parameters[0]; | 700 $message = (string) $parameters[0]; |
701 if (!in_array($message, DeprecationListenerTrait::getSkippedDeprecations())) { | 701 $test_info = TestDiscovery::getTestInfo(get_called_class()); |
702 if ($test_info['group'] !== 'legacy' && !in_array($message, DeprecationListenerTrait::getSkippedDeprecations())) { | |
702 call_user_func_array([&$this, 'error'], $parameters); | 703 call_user_func_array([&$this, 'error'], $parameters); |
703 } | 704 } |
704 } | 705 } |
705 } | 706 } |
706 else { | 707 else { |
1051 return $out; | 1052 return $out; |
1052 } | 1053 } |
1053 } | 1054 } |
1054 // We have not found a form which contained all fields of $edit. | 1055 // We have not found a form which contained all fields of $edit. |
1055 foreach ($edit as $name => $value) { | 1056 foreach ($edit as $name => $value) { |
1056 $this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); | 1057 $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); |
1057 } | 1058 } |
1058 if (!$ajax && isset($submit)) { | 1059 if (!$ajax && isset($submit)) { |
1059 $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); | 1060 $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); |
1060 } | 1061 } |
1061 $this->fail(format_string('Found the requested form fields at @path', ['@path' => ($path instanceof Url) ? $path->toString() : $path])); | 1062 $this->fail(format_string('Found the requested form fields at @path', ['@path' => ($path instanceof Url) ? $path->toString() : $path])); |
1723 $label = (string) $label; | 1724 $label = (string) $label; |
1724 $url_before = $this->getUrl(); | 1725 $url_before = $this->getUrl(); |
1725 $urls = $this->xpath($pattern, [':label' => $label]); | 1726 $urls = $this->xpath($pattern, [':label' => $label]); |
1726 if (isset($urls[$index])) { | 1727 if (isset($urls[$index])) { |
1727 $url_target = $this->getAbsoluteUrl($urls[$index]['href']); | 1728 $url_target = $this->getAbsoluteUrl($urls[$index]['href']); |
1728 $this->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser'); | 1729 $this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser'); |
1729 return $this->drupalGet($url_target); | 1730 return $this->drupalGet($url_target); |
1730 } | 1731 } |
1731 $this->fail(SafeMarkup::format('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser'); | 1732 $this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser'); |
1732 return FALSE; | 1733 return FALSE; |
1733 } | 1734 } |
1734 | 1735 |
1735 /** | 1736 /** |
1736 * Takes a path and returns an absolute path. | 1737 * Takes a path and returns an absolute path. |
1902 * The expected system path or URL. | 1903 * The expected system path or URL. |
1903 * @param $options | 1904 * @param $options |
1904 * (optional) Any additional options to pass for $path to the url generator. | 1905 * (optional) Any additional options to pass for $path to the url generator. |
1905 * @param $message | 1906 * @param $message |
1906 * (optional) A message to display with the assertion. Do not translate | 1907 * (optional) A message to display with the assertion. Do not translate |
1907 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed | 1908 * messages: use \Drupal\Component\Render\FormattableMarkup to embed |
1908 * variables in the message text, not t(). If left blank, a default message | 1909 * variables in the message text, not t(). If left blank, a default message |
1909 * will be displayed. | 1910 * will be displayed. |
1910 * @param $group | 1911 * @param $group |
1911 * (optional) The group this message is in, which is displayed in a column | 1912 * (optional) The group this message is in, which is displayed in a column |
1912 * in test output. Use 'Debug' to indicate this is debugging output. Do not | 1913 * in test output. Use 'Debug' to indicate this is debugging output. Do not |
1929 $options['path_processing'] = TRUE; | 1930 $options['path_processing'] = TRUE; |
1930 $url_obj = Url::fromUri($uri, $options); | 1931 $url_obj = Url::fromUri($uri, $options); |
1931 } | 1932 } |
1932 $url = $url_obj->setAbsolute()->toString(); | 1933 $url = $url_obj->setAbsolute()->toString(); |
1933 if (!$message) { | 1934 if (!$message) { |
1934 $message = SafeMarkup::format('Expected @url matches current URL (@current_url).', [ | 1935 $message = new FormattableMarkup('Expected @url matches current URL (@current_url).', [ |
1935 '@url' => var_export($url, TRUE), | 1936 '@url' => var_export($url, TRUE), |
1936 '@current_url' => $this->getUrl(), | 1937 '@current_url' => $this->getUrl(), |
1937 ]); | 1938 ]); |
1938 } | 1939 } |
1939 // Paths in query strings can be encoded or decoded with no functional | 1940 // Paths in query strings can be encoded or decoded with no functional |
1949 * @param $code | 1950 * @param $code |
1950 * Response code. For example 200 is a successful page request. For a list | 1951 * Response code. For example 200 is a successful page request. For a list |
1951 * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. | 1952 * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. |
1952 * @param $message | 1953 * @param $message |
1953 * (optional) A message to display with the assertion. Do not translate | 1954 * (optional) A message to display with the assertion. Do not translate |
1954 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed | 1955 * messages: use \Drupal\Component\Render\FormattableMarkup to embed |
1955 * variables in the message text, not t(). If left blank, a default message | 1956 * variables in the message text, not t(). If left blank, a default message |
1956 * will be displayed. | 1957 * will be displayed. |
1957 * @param $group | 1958 * @param $group |
1958 * (optional) The group this message is in, which is displayed in a column | 1959 * (optional) The group this message is in, which is displayed in a column |
1959 * in test output. Use 'Debug' to indicate this is debugging output. Do not | 1960 * in test output. Use 'Debug' to indicate this is debugging output. Do not |
1964 * Assertion result. | 1965 * Assertion result. |
1965 */ | 1966 */ |
1966 protected function assertResponse($code, $message = '', $group = 'Browser') { | 1967 protected function assertResponse($code, $message = '', $group = 'Browser') { |
1967 $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); | 1968 $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); |
1968 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; | 1969 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; |
1969 return $this->assertTrue($match, $message ? $message : SafeMarkup::format('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); | 1970 return $this->assertTrue($match, $message ? $message : new FormattableMarkup('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); |
1970 } | 1971 } |
1971 | 1972 |
1972 /** | 1973 /** |
1973 * Asserts the page did not return the specified response code. | 1974 * Asserts the page did not return the specified response code. |
1974 * | 1975 * |
1975 * @param $code | 1976 * @param $code |
1976 * Response code. For example 200 is a successful page request. For a list | 1977 * Response code. For example 200 is a successful page request. For a list |
1977 * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. | 1978 * of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. |
1978 * @param $message | 1979 * @param $message |
1979 * (optional) A message to display with the assertion. Do not translate | 1980 * (optional) A message to display with the assertion. Do not translate |
1980 * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed | 1981 * messages: use \Drupal\Component\Render\FormattableMarkup to embed |
1981 * variables in the message text, not t(). If left blank, a default message | 1982 * variables in the message text, not t(). If left blank, a default message |
1982 * will be displayed. | 1983 * will be displayed. |
1983 * @param $group | 1984 * @param $group |
1984 * (optional) The group this message is in, which is displayed in a column | 1985 * (optional) The group this message is in, which is displayed in a column |
1985 * in test output. Use 'Debug' to indicate this is debugging output. Do not | 1986 * in test output. Use 'Debug' to indicate this is debugging output. Do not |
1990 * Assertion result. | 1991 * Assertion result. |
1991 */ | 1992 */ |
1992 protected function assertNoResponse($code, $message = '', $group = 'Browser') { | 1993 protected function assertNoResponse($code, $message = '', $group = 'Browser') { |
1993 $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); | 1994 $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); |
1994 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; | 1995 $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code; |
1995 return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); | 1996 return $this->assertFalse($match, $message ? $message : new FormattableMarkup('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); |
1996 } | 1997 } |
1997 | 1998 |
1998 /** | 1999 /** |
1999 * Builds an a absolute URL from a system path or a URL object. | 2000 * Builds an a absolute URL from a system path or a URL object. |
2000 * | 2001 * |