StateFilterTest.php in State Machine 8
File
tests/src/Functional/StateFilterTest.php
View source
<?php
namespace Drupal\Tests\state_machine\Functional;
use Drupal\entity_test\Entity\EntityTestWithBundle;
use Drupal\Tests\BrowserTestBase;
class StateFilterTest extends BrowserTestBase {
protected static $modules = [
'entity_test',
'options',
'state_machine',
'state_machine_test',
'views',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$user = $this
->drupalCreateUser([
'administer entity_test content',
]);
$this
->drupalLogin($user);
}
public function testFilter() {
$first_entity = EntityTestWithBundle::create([
'type' => 'first',
'name' => 'First',
]);
$first_entity
->save();
$second_entity = EntityTestWithBundle::create([
'type' => 'second',
'name' => 'Second',
'field_state' => 'validation',
]);
$second_entity
->save();
$this
->drupalGet('/state-machine-test');
$this
->assertSession()
->pageTextContains('First');
$this
->assertSession()
->pageTextContains('New');
$this
->assertSession()
->pageTextContains('Second');
$this
->assertSession()
->pageTextContains('Validation');
$expected_options = [
'All' => '- Any -',
'new' => 'New',
'validation' => 'Validation',
'fulfillment' => 'Fulfillment',
'completed' => 'Completed',
'canceled' => 'Canceled',
];
$elements = $this
->xpath('//select[@name="field_state_value"]/option');
$found_options = [];
foreach ($elements as $element) {
$found_options[$element
->getValue()] = $element
->getText();
}
$this
->assertEquals($expected_options, $found_options);
}
}