assertMailString example

// Test HTML mails.     $mail_config = $this->config('system.mail');
    $mail_config->set('interface.default', 'test_html_mail_collector');
    $mail_config->save();

    $this->drupalLogin($this->webUser);
    $message['message[0][value]'] = 'This <i>is</i> a more <b>specific</b> <sup>test</sup>, the emails are formatted now.';
    $message = $this->submitPersonalContact($this->contactUser, $message);

    // Assert mail content.     $this->assertMailString('body', 'Hello ' . $this->contactUser->getDisplayName(), 1);
    $this->assertMailString('body', $this->webUser->getDisplayName(), 1);
    $this->assertMailString('body', Html::Escape($message['message[0][value]']), 1);
  }

  /** * Tests access to the personal contact form. */
  public function testPersonalContactAccess() {
    // Test allowed access to admin user's contact form.     $this->drupalLogin($this->webUser);
    $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
    
$edit['user_bulk_form[4]'] = TRUE;
    $config
      ->set('notify.status_blocked', TRUE)
      ->save();
    $this->drupalGet('admin/people', [
      // Sort the table by username so that we know reliably which user will be       // targeted with the blocking action.       'query' => ['order' => 'name', 'sort' => 'asc'],
    ]);
    $this->submitForm($edit, 'Apply to selected items');
    $site_name = $this->config('system.site')->get('name');
    $this->assertMailString('body', 'Your account on ' . $site_name . ' has been blocked.', 1, 'Blocked message found in the mail sent to user C.');
    $user_storage->resetCache([$user_c->id()]);
    $account = $user_storage->load($user_c->id());
    $this->assertTrue($account->isBlocked(), 'User C blocked');

    // Test filtering on admin page for blocked users     $this->drupalGet('admin/people', ['query' => ['status' => 2]]);
    $this->assertSession()->elementNotExists('xpath', static::getLinkSelectorForUser($user_a));
    $this->assertSession()->elementNotExists('xpath', static::getLinkSelectorForUser($user_b));
    $this->assertSession()->elementExists('xpath', static::getLinkSelectorForUser($user_c));

    // Test unblocking of a user from /admin/people page and sending of activation mail
// Allow visitors to register with email verification.     $config->set('register', UserInterface::REGISTER_VISITORS);
    $config->set('verify_mail', 1);
    $config->save();
    $name = 'Jason.Taverner';
    $user = $this->registerUser($name, FALSE);
    $this->assertEmpty($user->getPassword());
    $this->assertTrue($user->isBlocked());
    $this->resetAll();

    $this->assertMailString('body', 'You may now log in by clicking this link', 1);

    // Allow visitors to register with Admin approval and no email verification.     $config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
    $config->set('verify_mail', 0);
    $config->save();
    $name = 'Argaven';
    $user = $this->registerUser($name);
    $this->resetAll();
    $this->assertNotEmpty($user->getPassword());
    $this->assertTrue($user->isBlocked());
    $this->assertMailString('body', 'Your application for an account is', 2);
    
$preferredLangcode = $user->getPreferredLangcode();
    $this->assertSame('zh-hant', $preferredLangcode);

    // Recovery email should respect user preferred langcode by default if     // langcode not set.     $this->config('system.site')->set('mail', 'test@example.com')->save();
    $params['account'] = $user;
    $default_email = \Drupal::service('plugin.manager.mail')->mail('user', 'password_reset', $user->getEmail()$preferredLangcode$params);
    $this->assertTrue($default_email['result']);

    // Assert for zh.     $this->assertMailString('subject', 'hant subject', 1);
    $this->assertMailString('body', 'hant body', 1);
    $this->assertMailString('body', 'zh/user/reset', 1);

    // Recovery email should be fr when langcode specified.     $french_email = \Drupal::service('plugin.manager.mail')->mail('user', 'password_reset', $user->getEmail(), 'fr', $params);
    $this->assertTrue($french_email['result']);

    // Assert for fr.     $this->assertMailString('subject', 'fr subject', 1);
    $this->assertMailString('body', 'fr body', 1);
    $this->assertMailString('body', 'fr/user/reset', 1);

  }
Home | Imprint | This part of the site doesn't use cookies.