Skip to content
Snippets Groups Projects
Commit 20167a05 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

cleaning a little

parent 4c3b9613
No related branches found
No related tags found
1 merge request!196Views tests
......@@ -34,14 +34,9 @@ class LayoutBuilderFieldFormatterRenderTest extends UiPatternsFunctionalTestBase
protected function setUp(): void {
parent::setUp();
if ($this->user) {
// Create a role with a specific permission.
$custom_role = $this->drupalCreateRole(['configure any layout'], 'custom_role');
// Create a user and assign the role.
$user = $this->drupalCreateUser([], 'test_user');
$this->drupalCreateRole(['configure any layout'], 'custom_role');
$this->user->addRole('custom_role');
$this->user->save();
// $this->drupalLogout();
// $this->drupalLogin($this->user);
}
}
......
......@@ -34,28 +34,24 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
public function testPlugins(): void {
$this->createTestContentContentType();
$assert_session = $this->assertSession();
$view_test_data = self::loadTestDataFixture(__DIR__ . "/../fixtures/TestDataSet.yml");
// ---
// View Style
// ---
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/views.view.test.yml');
$this->importConfigFixture(
'views.view.test',
$config_import
);
// Check that the Views style plugin appears.
$this->drupalGet('admin/structure/views/nojs/display/test/default/style');
// $text = $this->getSession()->getPage()->getContent();
$text_views_style_plugin = "Component (UI Patterns)";
$assert_session->elementTextEquals("css", ".form-item label", $text_views_style_plugin);
$assert_session->elementTextEquals("css", ".form-item label", "Component (UI Patterns)");
// Configure the style plugin.
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/views.view.test.style.yml');
$ui_patterns_config = &$config_import['display']['page_1']['display_options']["style"]["options"]["ui_patterns"]['ui_patterns'];
$tests = $view_test_data->getTestSets();
foreach ($tests as $test_set_name => $test_set) {
if (!str_starts_with($test_set_name, 'style')) {
if (!str_starts_with($test_set_name, 'style') || !isset($test_set["assertSession"])) {
continue;
}
$node = $this->createTestContentNode('page', $test_set['entity'] ?? []);
......@@ -66,31 +62,26 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
);
\Drupal::service('router.builder')->rebuild();
$this->drupalGet('test');
if (isset($test_set["assertSession"])) {
$this->assertSessionObject($test_set["assertSession"]);
}
$this->assertSessionObject($test_set["assertSession"]);
$node->delete();
}
// ---
// View Row
// View Rows
// ---
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/views.view.test.yml');
$this->importConfigFixture(
'views.view.test',
$config_import
);
// Check that the Views style plugin appears.
// Check that the View rows style plugin appears.
$this->drupalGet('admin/structure/views/nojs/display/test/default/row');
$text_row_style_plugin = "Component (UI Patterns)";
// Check that the style plugins appears.
$assert_session->elementTextEquals("css", ".form-item label", $text_row_style_plugin);
$assert_session->elementTextEquals("css", ".form-item label", "Component (UI Patterns)");
// Configure the row style plugin.
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/views.view.test.row_style.yml');
$ui_patterns_config = &$config_import['display']['page_1']['display_options']["row"]["options"]["ui_patterns"];
$tests = $view_test_data->getTestSets();
foreach ($tests as $test_set_name => $test_set) {
if (!str_starts_with($test_set_name, 'row_style')) {
if (!str_starts_with($test_set_name, 'row_style') || !isset($test_set["assertSession"])) {
continue;
}
$node = $this->createTestContentNode('page', $test_set['entity'] ?? []);
......@@ -101,9 +92,7 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
);
\Drupal::service('router.builder')->rebuild();
$this->drupalGet('test');
if (isset($test_set["assertSession"])) {
$this->assertSessionObject($test_set["assertSession"]);
}
$this->assertSessionObject($test_set["assertSession"]);
$node->delete();
}
// ---
......@@ -117,7 +106,7 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
// Check that field formatter plugin appears.
$this->drupalGet('admin/structure/views/nojs/handler/test/default/field/title');
$text_field_formatter_plugin = "Component per item (UI Patterns)";
// Check that the style plugins appears.
$key_field_formatter_plugin = "ui_patterns_component_per_item";
$page = $this->getSession()->getPage();
$nodes = $page->findAll("css", "select[name='options[type]'] option");
$textFound = FALSE;
......@@ -127,19 +116,19 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
if ($text === $text_field_formatter_plugin) {
$textFound = TRUE;
}
if ($node->getAttribute("value") === "ui_patterns_component_per_item") {
if ($node->getAttribute("value") === $key_field_formatter_plugin) {
$valueFound = TRUE;
}
}
if (!$textFound || !$valueFound) {
$this->fail(sprintf("Option not found for field formatter: %s / %s", "ui_patterns_component_per_item", $text_field_formatter_plugin));
$this->fail(sprintf("Option not found for field formatter: %s / %s", $key_field_formatter_plugin, $text_field_formatter_plugin));
}
// Configure a field, with field formatter plugin.
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/views.view.test.field.yml');
$ui_patterns_config = &$config_import['display']['page_1']['display_options']["fields"]["title"]["settings"]["ui_patterns"];
$tests = $view_test_data->getTestSets();
foreach ($tests as $test_set_name => $test_set) {
if (!str_starts_with($test_set_name, 'field')) {
if (!str_starts_with($test_set_name, 'field') || !isset($test_set["assertSession"])) {
continue;
}
$node = $this->createTestContentNode('page', $test_set['entity'] ?? []);
......@@ -150,12 +139,9 @@ class ViewsRenderTest extends UiPatternsFunctionalTestBase {
);
\Drupal::service('router.builder')->rebuild();
$this->drupalGet('test');
if (isset($test_set["assertSession"])) {
$this->assertSessionObject($test_set["assertSession"]);
}
$this->assertSessionObject($test_set["assertSession"]);
$node->delete();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment