Issue #3470203 by mstrelan, smustgrave: Add (more) bool return typehints to protected test helper methods

merge-requests/8983/head^2
quietone 2024-09-25 19:57:19 +12:00
parent 694cb802f4
commit acd24cb30d
No known key found for this signature in database
GPG Key ID: 43BFBBB26EA09FE1
13 changed files with 24 additions and 24 deletions

View File

@ -199,7 +199,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return bool
* Boolean indicating whether the comment was found.
*/
protected function commentExists(?CommentInterface $comment = NULL, $reply = FALSE) {
protected function commentExists(?CommentInterface $comment = NULL, $reply = FALSE): bool {
if ($comment) {
$comment_element = $this->cssSelect(($reply ? '.indented ' : '') . 'article#comment-' . $comment->id());
if (empty($comment_element)) {
@ -347,7 +347,7 @@ abstract class CommentTestBase extends BrowserTestBase {
* @return bool
* Contact info is available.
*/
protected function commentContactInfoAvailable() {
protected function commentContactInfoAvailable(): bool {
return (bool) preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
}

View File

@ -306,7 +306,7 @@ trait ResourceResponseTestTrait {
* @return bool
* TRUE if the needle exists is present in the haystack, FALSE otherwise.
*/
protected static function collectionHasResourceIdentifier(array $needle, array $haystack) {
protected static function collectionHasResourceIdentifier(array $needle, array $haystack): bool {
foreach ($haystack as $resource) {
if ($resource['type'] == $needle['type'] && $resource['id'] == $needle['id']) {
return TRUE;

View File

@ -3504,7 +3504,7 @@ abstract class ResourceTestBase extends BrowserTestBase {
* TRUE if the field definition is found to be a reference field. FALSE
* otherwise.
*/
protected static function isReferenceFieldDefinition(FieldDefinitionInterface $field_definition) {
protected static function isReferenceFieldDefinition(FieldDefinitionInterface $field_definition): bool {
/** @var \Drupal\Core\Field\TypedData\FieldItemDataDefinition $item_definition */
$item_definition = $field_definition->getItemDefinition();
$main_property = $item_definition->getMainPropertyName();

View File

@ -183,7 +183,7 @@ class SettingsTrayTestBase extends OffCanvasTestBase {
* @return bool
* TRUE if the label is visible, FALSE if it is not.
*/
protected function isLabelInputVisible() {
protected function isLabelInputVisible(): bool {
return $this->getSession()->getPage()->find('css', static::LABEL_INPUT_SELECTOR)->isVisible();
}

View File

@ -104,7 +104,7 @@ class FieldTestItem extends FieldItemBase {
* @return bool
* TRUE if the item should be resaved, FALSE otherwise.
*/
protected function mustResave() {
protected function mustResave(): bool {
return $this->getValue()['value'] == 'resave';
}

View File

@ -28,7 +28,7 @@ abstract class CacheTestBase extends BrowserTestBase {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function checkCacheExists($cid, $var, $bin = NULL) {
protected function checkCacheExists($cid, $var, $bin = NULL): bool {
if ($bin == NULL) {
$bin = $this->defaultBin;
}

View File

@ -290,7 +290,7 @@ trait UserCreationTrait {
* @return bool
* TRUE if the permissions are valid, FALSE otherwise.
*/
protected function checkPermissions(array $permissions) {
protected function checkPermissions(array $permissions): bool {
$available = array_keys(\Drupal::service('user.permissions')->getPermissions());
$valid = TRUE;
foreach ($permissions as $permission) {

View File

@ -123,7 +123,7 @@ class FilterTest extends WebDriverTestBase {
* @return bool
* TRUE if the required number was matched, FALSE otherwise.
*/
protected function waitForVisibleElementCount($count, $locator, $timeout = 10000) {
protected function waitForVisibleElementCount($count, $locator, $timeout = 10000): bool {
$page = $this->getSession()->getPage();
return $page->waitFor($timeout / 1000, function () use ($count, $page, $locator) {
@ -145,7 +145,7 @@ class FilterTest extends WebDriverTestBase {
* @return bool
* TRUE if the required number was matched, FALSE otherwise.
*/
protected function waitForOnlyContentRows($timeout = 10000) {
protected function waitForOnlyContentRows($timeout = 10000): bool {
$page = $this->getSession()->getPage();
return $page->waitFor($timeout / 1000, function () use ($page) {

View File

@ -503,7 +503,7 @@ abstract class BuildTestBase extends TestCase {
*
* @return bool
*/
protected function checkPortIsAvailable($port) {
protected function checkPortIsAvailable($port): bool {
$fp = @fsockopen(self::$hostName, $port, $errno, $errstr, 1);
// If fsockopen() fails to connect, probably nothing is listening.
// It could be a firewall but that's impossible to detect, so as a

View File

@ -398,7 +398,7 @@ JS);
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException
* When an invalid corner specification is given.
*/
private function checkNodeVisibilityInViewport(NodeElement $node, $corner = FALSE) {
private function checkNodeVisibilityInViewport(NodeElement $node, $corner = FALSE): bool {
$xpath = $node->getXpath();
// Build the JavaScript to test if the complete element or a specific corner

View File

@ -557,7 +557,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertUniqueText($text, $message = '') {
protected function assertUniqueText($text, $message = ''): bool {
return $this->assertUniqueTextHelper($text, $message, NULL, TRUE);
}
@ -580,7 +580,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertNoUniqueText($text, $message = '') {
protected function assertNoUniqueText($text, $message = ''): bool {
return $this->assertUniqueTextHelper($text, $message, NULL, FALSE);
}
@ -847,7 +847,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldByXPath($xpath, $value = NULL, $message = '') {
protected function assertFieldByXPath($xpath, $value = NULL, $message = ''): bool {
$fields = $this->xpath($xpath);
return $this->assertFieldsByValue($fields, $value, $message);
@ -933,7 +933,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldByName($name, $value = NULL, $message = NULL) {
protected function assertFieldByName($name, $value = NULL, $message = NULL): bool {
if (!isset($message)) {
if (!isset($value)) {
$message = new FormattableMarkup('Found field with name @name', [
@ -970,7 +970,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertNoFieldByName($name, $value = '', $message = '') {
protected function assertNoFieldByName($name, $value = '', $message = ''): bool {
return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : new FormattableMarkup('Did not find field by name @name', ['@name' => $name]));
}
@ -994,7 +994,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldById($id, $value = '', $message = '') {
protected function assertFieldById($id, $value = '', $message = ''): bool {
// Cast MarkupInterface objects to string.
if (isset($value)) {
$value = (string) $value;
@ -1023,7 +1023,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertNoFieldById($id, $value = '', $message = '') {
protected function assertNoFieldById($id, $value = '', $message = ''): bool {
return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : new FormattableMarkup('Did not find field by id @id', ['@id' => $id]));
}
@ -1246,7 +1246,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertField($field, $message = '') {
protected function assertField($field, $message = ''): bool {
return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message);
}
@ -1265,7 +1265,7 @@ trait AssertContentTrait {
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertNoField($field, $message = '') {
protected function assertNoField($field, $message = ''): bool {
return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message);
}

View File

@ -116,7 +116,7 @@ class TestSiteTearDownCommand extends Command {
*
* @see \Drupal\Core\File\FileSystemInterface::deleteRecursive()
*/
protected function fileUnmanagedDeleteRecursive($path, $callback = NULL) {
protected function fileUnmanagedDeleteRecursive($path, $callback = NULL): bool {
if (isset($callback)) {
call_user_func($callback, $path);
}

View File

@ -401,7 +401,7 @@ trait UiHelperTrait {
* @return bool
* Return TRUE if the user is logged in, FALSE otherwise.
*/
protected function drupalUserIsLoggedIn(AccountInterface $account) {
protected function drupalUserIsLoggedIn(AccountInterface $account): bool {
$logged_in = FALSE;
if (isset($account->sessionId)) {
@ -534,7 +534,7 @@ trait UiHelperTrait {
* @return bool
* TRUE if test is using DrupalTestBrowser.
*/
protected function isTestUsingGuzzleClient() {
protected function isTestUsingGuzzleClient(): bool {
$driver = $this->getSession()->getDriver();
if ($driver instanceof BrowserKitDriver) {
return $driver->getClient() instanceof DrupalTestBrowser;