Test spambot report account.

@group spambot

Hierarchy

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

Expanded class hierarchy of SpambotUserspamTest

File

tests/src/Kernel/SpambotUserspamTest.php, line 15

Namespace

Drupal\Tests\spambot\Kernel
View source
class SpambotUserspamTest extends KernelTestBase implements ServiceModifierInterface {
    
    /**
     * User for tests.
     *
     * @var \Drupal\Core\Entity\EntityBase|\Drupal\Core\Entity\EntityInterface
     */
    protected $user;
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'spambot',
        'user',
    ];
    
    /**
     * {@inheritdoc}
     */
    public function setUp() : void {
        parent::setUp();
        // Create an user that we will use for testing.
        $this->user = User::create([
            'name' => 'amparohm69',
            'mail' => 'nelda@singaporetravel.network',
        ]);
    }
    
    /**
     * Test spambot_report_account() function without "api_key".
     */
    public function testSpambotReportAccountEmptyApiKey() {
        $key = '';
        $success = spambot_report_account($this->user, '130.176.13.140', 'title', $key);
        $this->assertFalse($success, 'Field api key should not be filled.');
    }
    
    /**
     * Test spambot_report_account() function with incorrect "api_key".
     */
    public function testSpambotReportAccountIncorrectApiKey() {
        $key = 'notExist503';
        $success = spambot_report_account($this->user, '130.176.13.140', 'title', $key);
        $this->assertFalse($success, 'Field api key should not be filled.');
    }
    
    /**
     * Test spambot_report_account() function with correct "api_key".
     */
    public function testSpambotReportSpamAccount() {
        $key = 'wqd31vfkhae9gn';
        $success = spambot_report_account($this->user, '130.176.13.140', 'title', $key);
        $this->assertTrue($success, 'Guzzle exception.');
    }
    
    /**
     * {@inheritdoc}
     */
    public function alter(ContainerBuilder $container) {
        $container->removeDefinition('test.http_client.middleware');
    }

}

Members

Title Sort descending Modifiers Object type Summary
SpambotUserspamTest::$modules protected static property
SpambotUserspamTest::$user protected property User for tests.
SpambotUserspamTest::alter public function
SpambotUserspamTest::setUp public function
SpambotUserspamTest::testSpambotReportAccountEmptyApiKey public function Test spambot_report_account() function without "api_key".
SpambotUserspamTest::testSpambotReportAccountIncorrectApiKey public function Test spambot_report_account() function with incorrect "api_key".
SpambotUserspamTest::testSpambotReportSpamAccount public function Test spambot_report_account() function with correct "api_key".