Here's the class I want to test:
class Thing {
public function foo() {
return \Drupal::entityQuery('node')->condition('body', 'blah')->execute();
}
}
And the test:
class footest extends \Drupal\KernelTests\KernelTestBase {
public static $modules = ['node', 'user', 'field'];
public function testFoo() {
$thing = new Thing();
\PHPUnit\Framework\assertEquals($thing->foo() ,4);
}
}
Obviously this is not a real class or a real test, but they are pared down to the basics to demonstrate the issue.
When I run the test I get "Drupal\Core\Entity\Query\QueryException : 'body' not found
".
If I replace "body" with "field_baz', a field that I know exists on at least some content types, I get "Drupal\Core\Entity\Query\QueryException : 'field_baz' not found
".
Removing the condition entirely, so that the function body becomes:
return \Drupal::entityQuery('node')->execute();
produces "Drupal\Core\Database\DatabaseExceptionWrapper : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'carbon.test65392739node' doesn't exist
"
What am I doing wrong? How can I write tests for code that uses EntityQuery? Thanks!