Commit bcfecbbf authored by catch's avatar catch
Browse files

Issue #3131900 by mondrake, longwave, xjm, alexpott: Refactor assertions that...

Issue #3131900 by mondrake, longwave, xjm, alexpott: Refactor assertions that assign return values to variables
parent 58a4457b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ protected function assertCacheTags(array $expected_tags, $include_default_tags =
   *   (optional) Whether the default contexts should automatically be included.
   *
   * @return bool
   *   TRUE if the assertion succeeded, FALSE otherwise.
   *   Always returns TRUE.
   */
  protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) {
    if ($include_default_contexts) {
@@ -142,7 +142,7 @@ protected function assertCacheContexts(array $expected_contexts, $message = NULL
    sort($expected_contexts);
    sort($actual_contexts);
    $this->assertSame($expected_contexts, $actual_contexts, $message ?? '');
    return $actual_contexts === $expected_contexts;
    return TRUE;
  }

  /**
+1 −2
Original line number Diff line number Diff line
@@ -72,8 +72,7 @@ public function testSessionSaveRegenerate() {
    $this->drupalGet('user/login');
    $this->submitForm($edit, 'Log in');
    $this->drupalGet('user');
    $pass = $this->assertSession()->pageTextContains($user->getAccountName());
    $this->_logged_in = $pass;
    $this->assertSession()->pageTextContains($user->getAccountName());

    $this->drupalGet('session-test/id');
    $matches = [];
+2 −8
Original line number Diff line number Diff line
@@ -107,9 +107,6 @@ public function testToolbarCacheContextsCaller() {
   *   Expected cache contexts for both users.
   * @param string $message
   *   (optional) A verbose message to output.
   *
   * @return
   *   TRUE if the assertion succeeded, FALSE otherwise.
   */
  protected function assertToolbarCacheContexts(array $cache_contexts, $message = NULL) {
    // Default cache contexts that should exist on all test cases.
@@ -123,16 +120,13 @@ protected function assertToolbarCacheContexts(array $cache_contexts, $message =
    // Assert contexts for user1 which has only default permissions.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('test-page');
    $return = $this->assertCacheContexts($cache_contexts);
    $this->assertCacheContexts($cache_contexts, $message);
    $this->drupalLogout();

    // Assert contexts for user2 which has some additional permissions.
    $this->drupalLogin($this->adminUser2);
    $this->drupalGet('test-page');
    $return = $return && $this->assertCacheContexts($cache_contexts);

    $this->assertTrue($return, $message);
    return $return;
    $this->assertCacheContexts($cache_contexts, $message);
  }

  /**
+2 −5
Original line number Diff line number Diff line
@@ -160,9 +160,6 @@ public function testPagePaths() {
   *
   * @param string $path
   *   Path that will be set as the view page display path.
   *
   * @return bool
   *   Assertion result.
   */
  public function assertPagePath($path) {
    $view = Views::getView('test_page_display_path');
@@ -172,10 +169,10 @@ public function assertPagePath($path) {
    $this->container->get('router.builder')->rebuild();
    // Check if we successfully changed the path.
    $this->drupalGet($path);
    $success = $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->statusCodeEquals(200);
    // Check if we don't get any error on the view edit page.
    $this->drupalGet('admin/structure/views/view/test_page_display_path');
    return $success && $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->statusCodeEquals(200);
  }

}