View source
<?php
namespace Drupal\Tests\search_api_sorts\Functional;
use Drupal\Core\Url;
class IntegrationTest extends SortsFunctionalBase {
public function testFramework() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/sorts');
$this
->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/sorts/' . $this->escapedDisplayId);
$edit = [
'sorts[id][status]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings');
$this
->drupalGet('search-api-sorts-test');
$this
->assertSession()
->linkNotExists('ID');
$block_settings = [
'region' => 'footer',
'id' => 'sorts_id',
];
$this
->drupalPlaceBlock('search_api_sorts_block:' . $this->displayId, $block_settings);
$this
->drupalGet('search-api-sorts-test');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkExists('ID');
$this
->assertPositions([
'default | foo bar baz foobaz föö',
'default | foo test foobuz',
'default | foo baz',
'default | bar baz',
]);
$this
->clickLink('ID');
$this
->assertSession()
->statusCodeEquals(200);
$url = Url::fromUserInput('/search-api-sorts-test', [
'query' => [
'sort' => 'id',
'order' => 'asc',
],
]);
$this
->assertSession()
->addressEquals($url);
$this
->assertPositions([
'default | foo bar baz foobaz föö',
'default | foo test foobuz',
'default | foo baz',
'default | bar baz',
]);
$this
->clickLink('ID');
$this
->assertSession()
->statusCodeEquals(200);
$url = Url::fromUserInput('/search-api-sorts-test', [
'query' => [
'sort' => 'id',
'order' => 'desc',
],
]);
$this
->assertSession()
->addressEquals($url);
$this
->assertPositions([
'default | bar baz',
'default | foo baz',
'default | foo test foobuz',
'default | foo bar baz foobaz föö',
]);
$this
->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/sorts/' . $this->escapedDisplayId);
$edit = [
'sorts[id][status]' => TRUE,
'sorts[search_api_relevance][status]' => TRUE,
'sorts[type][status]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save settings');
$this
->drupalGet('search-api-sorts-test');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkExists('ID');
$this
->assertSession()
->linkExists('Type');
$this
->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/fields');
$this
->getSession()
->getPage()
->find('css', '#edit-fields-type-remove')
->click();
$this
->drupalPostForm(NULL, [], 'Save changes');
$this
->drupalGet('search-api-sorts-test');
$this
->assertSession()
->linkExists('ID');
$this
->assertSession()
->linkNotExists('Type');
$this
->assertSession()
->linkExists('Relevance');
$this
->drupalGet('admin/config/search/search-api/sorts/' . $this->escapedDisplayId . '_id');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('admin/config/search/search-api/index/' . $this->indexId . '/sorts/' . $this->escapedDisplayId);
}
public function testSavedConfigs() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/sorts/' . $this->escapedDisplayId);
$edit = [
'sorts[id][status]' => TRUE,
'sorts[created][status]' => TRUE,
'sorts[type][status]' => TRUE,
'default_sort' => 'id',
];
$this
->drupalPostForm(NULL, $edit, 'Save settings');
$configs_to_be_saved = [
'id',
'created',
'type',
];
$configs_not_to_be_saved = [
'search_api_relevance',
'keywords',
'category',
'width',
];
$page = $this
->getSession()
->getPage();
$id_default_sort_checkbox = $page
->find('css', '#edit-sorts .form-item-default-sort input[value="id"]');
$this
->assertEquals(TRUE, $id_default_sort_checkbox
->isChecked());
foreach ($configs_to_be_saved as $config_id) {
$this
->assertNotEmpty($this->container
->get('entity_type.manager')
->getStorage('search_api_sorts_field')
->load($this->escapedDisplayId . '_' . $config_id), t("Config @config_name was not saved as expected", [
'@config_name' => $config_id,
]));
}
foreach ($configs_not_to_be_saved as $config_id) {
$this
->assertEmpty($this->container
->get('entity_type.manager')
->getStorage('search_api_sorts_field')
->load($this->escapedDisplayId . '_' . $config_id), t("Config @config_name that should not have been saved was saved unexpectedly", [
'@config_name' => $config_id,
]));
}
}
}