Test of Spambot caching functionality.

@group spambot

Hierarchy

  • class \Drupal\Tests\spambot\Kernel\SpambotCacheTest extends \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceModifierInterface

Expanded class hierarchy of SpambotCacheTest

File

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

Namespace

Drupal\Tests\spambot\Kernel
View source
class SpambotCacheTest extends KernelTestBase implements ServiceModifierInterface {
    
    /**
     * Modules to enable.
     *
     * @var string[]
     */
    protected static $modules = [
        'spambot',
    ];
    
    /**
     * {@inheritDoc}
     */
    public function setUp() : void {
        parent::setUp();
        $this->installConfig([
            'spambot',
        ]);
    }
    
    /**
     * Tests spambot caching functionality.
     */
    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);
    }
    
    /**
     * {@inheritdoc}
     */
    public function alter(ContainerBuilder $container) {
        $container->removeDefinition('test.http_client.middleware');
    }

}

Members

Title Sort descending Modifiers Object type Summary
SpambotCacheTest::$modules protected static property Modules to enable.
SpambotCacheTest::alter public function
SpambotCacheTest::setUp public function
SpambotCacheTest::testSpambotCaching public function Tests spambot caching functionality.