VoteCreationTest.php in Voting API 8.3
File
tests/src/Functional/VoteCreationTest.php
View source
<?php
namespace Drupal\Tests\votingapi\Functional;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\votingapi\Entity\Vote;
class VoteCreationTest extends BrowserTestBase {
protected static $modules = [
'node',
'votingapi',
'votingapi_test',
];
protected $defaultTheme = 'stark';
private $node;
protected function setUp() {
parent::setUp();
if ($this->profile != 'standard') {
$node_type = $this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
node_add_body_field($node_type);
}
$this
->drupalLogin($this
->drupalCreateUser());
$title = $this
->randomMachineName(8);
$node = Node::create([
'type' => 'page',
]);
$node
->setOwner($this->loggedInUser);
$node
->setTitle($title);
$node
->set('body', [
'value' => $this
->randomMachineName(16),
]);
$node
->save();
$this->node = $this
->drupalGetNodeByTitle($title);
$this
->assertNotEmpty($this->node, 'Basic page created for Voting API tests.');
}
public function testVoteCreationWithInvalidVoteType() {
$vote = Vote::create([
'type' => 'vote',
]);
$vote
->setVotedEntityId($this->node
->id());
$vote
->setVotedEntityType($this->node
->getEntityTypeId());
$vote
->setValue(50);
$vote
->save();
$this
->assertNotEmpty($vote, 'A "fake_vote_type" vote was successfully cast on a node.');
}
}