VoteTypeFormTest.php in Voting API 8.3
File
tests/src/Functional/VoteTypeFormTest.php
View source
<?php
namespace Drupal\Tests\votingapi\Functional;
use Drupal\Tests\BrowserTestBase;
class VoteTypeFormTest extends BrowserTestBase {
protected static $modules = [
'votingapi',
'votingapi_test',
];
protected $defaultTheme = 'stark';
protected $entityTypeManager;
protected function setUp() {
parent::setUp();
$this->entityTypeManager = $this->container
->get('entity_type.manager');
}
public function testVoteTypeCreation() {
$this
->drupalGet('admin/structure/vote-types/add');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogin($this
->drupalCreateUser([
'administer vote types',
]));
$this
->drupalGet('admin/structure/vote-types/add');
$this
->assertSession()
->statusCodeEquals(200);
$type_label = 'Rating';
$machine_name = 'rating';
$value_type = 'points';
$description = 'A test Vote Type for testing.';
$page = $this
->getSession()
->getPage();
$page
->fillField('Name', $type_label);
$page
->fillField('Machine-readable name', $machine_name);
$page
->fillField('Value type', $value_type);
$page
->fillField('Description', $description);
$page
->pressButton('Save vote type');
$assert = $this
->assertSession();
$assert
->pageTextContains('The default tag for votes on content.');
$assert
->pageTextContains('A generic vote used for testing purposes.');
$assert
->pageTextContains($description);
$assert
->pageTextContains("The vote type {$type_label} has been added.");
$vote_type = $this->entityTypeManager
->getStorage('vote_type');
$this
->assertEquals($type_label, $vote_type
->load($machine_name)
->label());
}
}