1

I am trying to setup a simple test that tests some breadcrumb altering code I have introduced only for a specific content type.

Here is the test, still just barebones:

namespace Drupal\mymodule_breadcrumbs\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Class ArticleBreadcrumbTest
 * @group mymodule_breadcrumbs
 */
class ArticleBreadcrumbTest extends WebTestBase {
  protected $node;
  private $account;

  /**
   * Modules to install.
   * @var array
   */
  public static $modules = ['node', 'mymodule_breadcrumbs', 'menu_breadcrumb'];

  /**
   * Set up our test.
   */
  public function setUp() {
    parent::setUp();

    // create admin user
    $this->account = $this->drupalCreateUser(['administer site configuration', 'administer content']);

    // create article node
    $this->node = $this->drupalCreateNode(array(
      'title' => t('Test Article'),
      'type' => 'article',
      'status' => 1,
    ));
  }

  public function testNodeTitleIsInBreadcrumb() {
    $this->drupalGet('node/' . $this->node->id());
    $this->assertResponse(200);
    #$this->assertText('Home > ' . $this->node->getTitle(), 'Breadcrumb contains the node title.');
    // get page
    // test that breadcrumb is correct per node title
    // change node title
    // save node
    // visit node, check that breadcrumb is updated
  }
}

However, I am getting this error and not sure what to make of it:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Invalid database prefix: in Drupal\Core\Test\TestDatabase->__construct() (line 81 of core/lib/Drupal/Core/Test/TestDatabase.php).
simpletest_log_read(NULL, , ) (Line: 476)
_simpletest_batch_finished(, Array, Array, '1 sec')
call_user_func_array('_simpletest_batch_finished', Array) (Line: 414)
_batch_finished() (Line: 81)
_batch_page(Object) (Line: 55)
Drupal\system\Controller\BatchController->batchPage(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

It's a very basic test, why would it cause an error like that?

Also I am running this from the UI runner, if that makes a difference.

  • What command do you use to run your tests? can you add it to the question? – Eyal Jan 24 '17 at 21:34
  • I used the Admin UI, I can't remember the commands offhand. Is the admin UI considered irrelevant anymore? – Kevin Jan 24 '17 at 21:35
  • I think that the admin UI is deprecated (not sure though). – Eyal Jan 24 '17 at 21:41
  • Ugh it traps me every time. – Kevin Jan 24 '17 at 21:42
  • 2
    It should work, but it's a mess. Someone at a sprint today had the same error, don't know what the problem is but using the terminal worked perfectly fine then. Use php core/scripts/run-tests.sh --url XX --browser --color --verbose --class "Drupal\module\...ClassName::optionalMethodName". Much faster, and with --browser you still get a detailed result in the browser just like running it in the UI. And only the terminal supports things like executing a single method. You can also use --concurrency X to run multiple tests fast. And use phpunit directly for phpunit based tests. – Berdir Jan 24 '17 at 22:26
0

For functional (browser) tests you need to provide some environment variables, in this case the SIMPLETEST_DB environment variable.

It can either be supplied in the phpunit.xml.dist file, or in phpunit command, or actually added to the environment before executing the phpunit command.

The format of the variable is seen in the phpunit.xml.dist file provided by Drupal core.

<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env name="SIMPLETEST_DB" value=""/>

From the error it seems that the provided SIMPLETEST_DB is not valid.

Note: the author mentioned that he was using the Admin UI and this answer does not address this problem.

  • I set up the phpunit.xml.dist file and the error still persists. I filled in all the applicable values. – Kevin Jan 25 '17 at 14:14
0

Well, this appears to be due to one of my dependencies missing a .schema.yml file (Menu Breadcrumb).

After patching that module to have a schema file, the console error AND the generic error in the testing UI went away. I can now execute the test from either interface.

See: https://www.drupal.org/node/2848879

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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