Commit 7e1043ea authored by catch's avatar catch
Browse files

Issue #3204764 by longwave, mondrake: PHPUnit assertions do not return a value

parent 768340be
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -87,9 +87,6 @@ protected function assertMail($name, $value = '', $message = '', $group = 'Email
   *   in test output. Use 'Debug' to indicate this is debugging output. Do not
   *   translate this string. Defaults to 'Other'; most tests do not override
   *   this default.
   *
   * @return bool
   *   TRUE on pass, FALSE on fail.
   */
  protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
    $mails = $this->getMails();
@@ -110,7 +107,7 @@ protected function assertMailString($field_name, $string, $email_depth, $message
    if (!$message) {
      $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $string]);
    }
    return $this->assertTrue($string_found, $message, $group);
    $this->assertTrue($string_found, $message, $group);
  }

  /**
@@ -130,9 +127,6 @@ protected function assertMailString($field_name, $string, $email_depth, $message
   *   in test output. Use 'Debug' to indicate this is debugging output. Do not
   *   translate this string. Defaults to 'Other'; most tests do not override
   *   this default.
   *
   * @return bool
   *   TRUE on pass, FALSE on fail.
   */
  protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
    $mails = $this->getMails();
@@ -141,7 +135,7 @@ protected function assertMailPattern($field_name, $regex, $message = '', $group
    if (!$message) {
      $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]);
    }
    return $this->assertTrue((bool) $regex_found, $message, $group);
    $this->assertTrue((bool) $regex_found, $message, $group);
  }

  /**
+2 −8
Original line number Diff line number Diff line
@@ -1139,12 +1139,9 @@ public function testHtmlCorrectorFilter() {
   *   (optional) Message to display if failed. Defaults to an empty string.
   * @param string $group
   *   (optional) The group this message belongs to. Defaults to 'Other'.
   *
   * @return bool
   *   TRUE on pass, FALSE on fail.
   */
  public function assertNormalized($haystack, $needle, $message = '', $group = 'Other') {
    return $this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
    $this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
  }

  /**
@@ -1164,12 +1161,9 @@ public function assertNormalized($haystack, $needle, $message = '', $group = 'Ot
   *   (optional) Message to display if failed. Defaults to an empty string.
   * @param string $group
   *   (optional) The group this message belongs to. Defaults to 'Other'.
   *
   * @return bool
   *   TRUE on pass, FALSE on fail.
   */
  public function assertNoNormalized($haystack, $needle, $message = '', $group = 'Other') {
    return $this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
    $this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
  }

}
+2 −8
Original line number Diff line number Diff line
@@ -96,14 +96,11 @@ public function testUrlAlter() {
   *   A string with the original path that is run through generateFrommPath().
   * @param $final
   *   A string with the expected result after generateFrommPath().
   *
   * @return
   *   TRUE if $original was correctly altered to $final, FALSE otherwise.
   */
  protected function assertUrlOutboundAlter($original, $final) {
    // Test outbound altering.
    $result = $this->container->get('path_processor_manager')->processOutbound($original);
    return $this->assertSame($final, $result, new FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
    $this->assertSame($final, $result, new FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
  }

  /**
@@ -113,14 +110,11 @@ protected function assertUrlOutboundAlter($original, $final) {
   *   The original path before it has been altered by inbound URL processing.
   * @param $final
   *   A string with the expected result.
   *
   * @return
   *   TRUE if $original was correctly altered to $final, FALSE otherwise.
   */
  protected function assertUrlInboundAlter($original, $final) {
    // Test inbound altering.
    $result = $this->container->get('path_alias.manager')->getPathByAlias($original);
    return $this->assertSame($final, $result, new FormattableMarkup('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
    $this->assertSame($final, $result, new FormattableMarkup('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result]));
  }

}
+1 −4
Original line number Diff line number Diff line
@@ -79,14 +79,11 @@ public function testConfirmFormWithExternalDestination() {
   *   The assert message.
   * @param string $group
   *   The assertion group.
   *
   * @return bool
   *   Result of the assertion.
   */
  public function assertCancelLinkUrl(Url $url, $message = '', $group = 'Other') {
    $links = $this->xpath('//a[@href=:url]', [':url' => $url->toString()]);
    $message = ($message ? $message : new FormattableMarkup('Cancel link with URL %url found.', ['%url' => $url->toString()]));
    return $this->assertTrue(isset($links[0]), $message, $group);
    $this->assertTrue(isset($links[0]), $message, $group);
  }

}
+6 −14
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ public function assertTableCount($base_table, $count = TRUE) {
    $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%');

    if ($count) {
      return $this->assertNotEmpty($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table]));
      $this->assertNotEmpty($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table]));
    }
    return $this->assertEmpty($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table]));
    $this->assertEmpty($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table]));
  }

  /**
@@ -67,7 +67,7 @@ public function assertModuleTablesExist($module) {
        $tables_exist = FALSE;
      }
    }
    return $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module]));
    $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module]));
  }

  /**
@@ -85,7 +85,7 @@ public function assertModuleTablesDoNotExist($module) {
        $tables_exist = TRUE;
      }
    }
    return $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module]));
    $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module]));
  }

  /**
@@ -93,11 +93,6 @@ public function assertModuleTablesDoNotExist($module) {
   *
   * @param string $module
   *   The name of the module.
   *
   * @return bool|null
   *   TRUE if configuration has been installed, FALSE otherwise. Returns NULL
   *   if the module configuration directory does not exist or does not contain
   *   any configuration files.
   */
  public function assertModuleConfig($module) {
    $module_config_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
@@ -131,7 +126,7 @@ public function assertModuleConfig($module) {
    }
    // Verify that all configuration has been installed (which means that $names
    // is empty).
    return $this->assertEmpty($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module]));
    $this->assertEmpty($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module]));
  }

  /**
@@ -139,13 +134,10 @@ public function assertModuleConfig($module) {
   *
   * @param string $module
   *   The name of the module.
   *
   * @return bool
   *   TRUE if no configuration was found, FALSE otherwise.
   */
  public function assertNoModuleConfig($module) {
    $names = \Drupal::configFactory()->listAll($module . '.');
    return $this->assertEmpty($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module]));
    $this->assertEmpty($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module]));
  }

  /**
Loading