public function CToolsViewsBasicViewBlockTest::testConfigureSorts in Chaos Tool Suite (ctools) 8.3
Test ctools_views 'configure_sorts' configuration.
File
- modules/
ctools_views/ tests/ src/ Functional/ CToolsViewsBasicViewBlockTest.php, line 330
Class
- CToolsViewsBasicViewBlockTest
- Tests ctools_views block display plugin overrides settings from a basic View.
Namespace
Drupal\Tests\ctools_views\FunctionalCode
public function testConfigureSorts() {
$default_theme = $this
->config('system.theme')
->get('default');
// Get the "Configure block" form for our Views block.
$this
->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_sort/' . $default_theme);
$this
->assertSession()
->fieldExists('settings[override][sort][id][order]');
// Add block to sidebar_first region with default settings.
$edit = [];
$edit['region'] = 'sidebar_first';
$this
->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_sort/' . $default_theme, $edit, $this
->t('Save block'));
// Assert configure_sorts default settings.
$this
->drupalGet('<front>');
// Check that the results are sorted ASC.
$element = $this
->xpath('//div[contains(@class, "view-display-id-block_sort")]//table//tr[1]/td[1]');
$value = $element[0]
->getText();
$this
->assertEquals('1', trim($value));
// Override configure_sorts settings.
$edit = [];
$edit['region'] = 'sidebar_first';
$edit['settings[override][sort][id][order]'] = 'DESC';
$this
->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_sort', $edit, $this
->t('Save block'));
$block = $this->storage
->load('views_block__ctools_views_test_view_block_sort');
$config = $block
->getPlugin()
->getConfiguration();
$this
->assertEquals('DESC', $config['sort']['id'], "'configure_sorts' setting is properly saved.");
// Assert configure_sorts overridden settings.
// Check that the results are sorted DESC.
$this
->drupalGet('<front>');
$element = $this
->xpath('//div[contains(@class, "view-display-id-block_sort")]//table//tr[1]/td[1]');
$value = $element[0]
->getText();
$this
->assertEquals('5', trim($value));
}