public function EmailNotificationsTest::testFieldDefinitions in Search API Saved Searches 8
Tests whether the plugin returns the correct field definitions used.
@covers ::getFieldDefinitions
File
- tests/
src/ Kernel/ EmailNotificationsTest.php, line 66
Class
- EmailNotificationsTest
- Tests the functionality of the "E-mail" notifications plugin.
Namespace
Drupal\Tests\search_api_saved_searches\KernelCode
public function testFieldDefinitions() {
// Make sure the correct definition is returned from the plugin.
$fields = $this->plugin
->getFieldDefinitions();
$this
->assertEquals([
'mail',
], array_keys($fields));
$this
->assertEquals('E-mail', $fields['mail']
->getLabel());
$this
->assertFalse($fields['mail']
->isBaseField());
// Make sure the mail can be stored in a saved search correctly.
$mail = 'test@example.net';
$search = SavedSearch::create([
'uid' => 0,
'type' => 'default',
'label' => 'Test search',
'mail' => $mail,
]);
$search
->save();
$search = SavedSearch::load($search
->id());
$this
->assertEquals($mail, $search
->get('mail')->value);
// Make sure the saved search bundle field definitions include the mail.
$fields = \Drupal::getContainer()
->get('entity_field.manager')
->getFieldDefinitions('search_api_saved_search', 'default');
$this
->assertArrayHasKey('mail', $fields);
$this
->assertEquals('E-mail', $fields['mail']
->getLabel());
$this
->assertFalse($fields['mail']
->isBaseField());
}