You are here

public function SpambotCacheTest::testSpambotCaching in Spambot 8

Tests spambot caching functionality.

File

tests/src/Kernel/SpambotCacheTest.php, line 35

Class

SpambotCacheTest
Test of Spambot caching functionality.

Namespace

Drupal\Tests\spambot\Kernel

Code

public function testSpambotCaching() {
  $username = mb_strtolower($this
    ->getRandomGenerator()
    ->name());
  $email = mb_strtolower($this
    ->getRandomGenerator()
    ->name()) . '@example.com';
  $ip = '' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
  $mock_query = [
    'username' => $username,
    'email' => $email,
    'ip' => $ip,
  ];
  $mock_data = [];
  spambot_sfs_request($mock_query, $mock_data);
  $cache_username = \Drupal::cache('spambot')
    ->get("username:{$username}");
  $cache_email = \Drupal::cache('spambot')
    ->get("email:{$email}");
  $cache_ip = \Drupal::cache('spambot')
    ->get("ip:{$ip}");
  $this
    ->assertNotFalse($cache_username);
  $this
    ->assertNotFalse($cache_email);
  $this
    ->assertNotFalse($cache_ip);
}