1

i am trying to write a functional test for my module that ships a views display extender but it already fails at installing my module.

in my module.install file i have these lines that will add my display extender to views.settings config:

function my_module_install() {
  // Enable display extender.
  $config = \Drupal::service('config.factory')->getEditable('views.settings');
  $display_extenders = $config->get('display_extenders') ?: [];
  $display_extenders[] = 'my_display_extender';
  $config->set('display_extenders', $display_extenders);
  $config->save();
}

And i have this simple test that extends ViewsTestBase

<?php

namespace Drupal\Tests\my_module\Functional;

use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;

/**
 * Test description.
 *
 * @group my_module
 */
class MyModuleTests extends ViewTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'olivero';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'views',
    'my_module',
    'my_module_tests',
  ];

  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'my_module_test_content',
  ];


  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views, ['my_module_tests']);

    //$this->configImporter();
    $account = $this->drupalCreateUser(['access content']);
    $this->drupalLogin($account);
    // ...
  }

  /**
   * Assert that the my_module installed correctly.
   */
  public function testModuleInstalls() {
    // If we get here, then the module was successfully installed during the
    // setUp phase without throwing any Exceptions. Assert that TRUE is true,
    // so at least one assertion runs, and then exit.
    $this->assertTrue(TRUE, 'Module installed correctly.');
  }

}

But the test fails at the install hook

Drupal\Tests\my_module\Functional\MyModuleTests::testModuleInstalls web\modules\custom\my_module\my_module.install:20

Drupal\Core\Config\Schema\SchemaIncompleteException: No schema for views.settings

And i am having a hard time trying to fix it or even understand why, the schema for views.settings is existent at core/modules/views/config/schema/views.schema.yml
Why is it that i get the error? Shouldnt the "views" module be enabled as well?

What do i have to do in order to make it work?

2
  • What's line 20 of my_module.install doing? I'm assuming something with Views but might be useful to see Commented Jun 3 at 12:44
  • Sorry, line 20 of my_module.install is $config->save() from the lines i posted in the question
    – john Smith
    Commented Jun 3 at 13:17

1 Answer 1

0

Okay i found the issue, i did not have the dependency to views module in the my_module.info.yml

after adding

dependencies:
  - drupal:views

the error disappeared and the tests were successfull

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.