Open Oleksii909 opened 3 years ago
https://www.drupal.org/node/2783079
!!! ????
<?php
namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests the add filter handler UI.
*
* @group views
*/
class FilterTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['node', 'views', 'views_ui', 'user'];
/**
* The account.
*
* @var \Drupal\user\UserInterface
*/
protected $account;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Disable automatic live preview to make the sequence of calls clearer.
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
$this->account = $this->drupalCreateUser(['administer views']);
$this->drupalLogin($this->account);
NodeType::create([
'type' => 'page',
])->save();
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'body',
'bundle' => 'page',
])->save();
}
/**
* Tests adding a filter handler.
*/
public function testAddingFilter() {
$web_assert = $this->assertSession();
$url = '/admin/structure/views/view/content';
$this->drupalGet($url);
$page = $this->getSession()->getPage();
// Open the 'Add filter dialog'.
$page->clickLink('views-add-filter');
// Test filtering by type.
$web_assert->waitForField('override[controls][group]');
$page->fillField('override[controls][group]', 'content');
$only_content_rows = $this->waitForOnlyContentRows();
$this->assertTrue($only_content_rows);
// Search for a specific title and test that this is now the only one shown.
$page->fillField('override[controls][options_search]', 'body (body)');
$filtering_done = $this->waitForVisibleElementCount(1, 'tr.filterable-option');
$this->assertTrue($filtering_done);
// Select the body field and apply the choice.
$page->checkField('name[node__body.body_value]');
$page->find('css', '.ui-dialog .ui-dialog-buttonpane')->pressButton('Add and configure filter criteria');
$web_assert->waitForField('options[expose_button][checkbox][checkbox]');
// Expose the filter.
$page->findField('options[expose_button][checkbox][checkbox]')->click();
$web_assert->waitForField('options[expose][label]');
$page->find('css', '.ui-dialog .ui-dialog-buttonpane')->pressButton('Apply');
$web_assert->waitForText('Content: body (exposed)');
$web_assert->responseContains('Content: body (exposed)');
}
/**
* Removes any non-visible elements from the passed array.
*
* @param \Behat\Mink\Element\NodeElement[] $elements
* The elements to filter.
*
* @return \Behat\Mink\Element\NodeElement[]
* The filtered elements.
*/
protected function filterVisibleElements($elements) {
$elements = array_filter($elements, function ($element) {
return $element->isVisible();
});
return $elements;
}
/**
* Waits for the specified number of items to be visible.
*
* @param int $count
* The number of found elements to wait for.
* @param string|array $locator
* The selector locator.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return bool
* TRUE if the required number was matched, FALSE otherwise.
*/
protected function waitForVisibleElementCount($count, $locator, $timeout = 10000) {
$page = $this->getSession()->getPage();
return $page->waitFor($timeout / 1000, function () use ($count, $page, $locator) {
$elements = $page->findAll('css', $locator);
$visible_elements = $this->filterVisibleElements($elements);
if (count($visible_elements) === $count) {
return TRUE;
}
return FALSE;
});
}
/**
* Waits for only content rows to be visible.
*
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @return bool
* TRUE if the required number was matched, FALSE otherwise.
*/
protected function waitForOnlyContentRows($timeout = 10000) {
$page = $this->getSession()->getPage();
return $page->waitFor($timeout / 1000, function () use ($page) {
$handler_rows = $page->findAll('css', 'tr.filterable-option');
$handler_rows = $this->filterVisibleElements($handler_rows);
foreach ($handler_rows as $handler_row) {
// Test that all the visible rows are of the 'content' type.
if (strpos($handler_row->getAttribute('class'), 'content') === FALSE) {
return FALSE;
}
}
return TRUE;
});
}
}
Sent him greeting
Prev commit sha b3d61bd368e957d47b543cfcb508b47bc267e21a Last commit sha 754b8ffab29270107af0dadf3413436584fc868d
Passing a StatementInterface object as a $query argument to Drupal\Core\Database\Connection::query is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439![image](https://user-images.githubusercontent.com/73876066/101239891-ead96280-36f3-11eb-9d5f-46b127df24e9.png)