Hello all,
I've created one module for importing users with a CSV file. The module is working fine if try it by the admin interface.
In this module I have declared the following function :
<?php
public function getCountryId($country_code) {
$country_ids = $this->entity_type_manager->getStorage('node')->getQuery()
->condition('type', 'country')
->condition('title', $country_code)
->execute();
return reset($country_ids);
}
?>
Now what I'm doing is to create my test class and if I try to use this function to assert is return value, I've the following message displayed :
sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite import
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
E
Time: 4.63 seconds, Memory: 6.00MB
There was 1 error:
1) Drupal\Tests\users_csv_importer\Functional\ImportTest::testImportCSV
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "node" entity type does not exist.
/var/www/cip/bobp_new/core/lib/Drupal/Core/Entity/EntityTypeManager.php:133
/var/www/cip/bobp_new/core/lib/Drupal/Core/Entity/EntityTypeManager.php:233
/var/www/cip/bobp_new/core/lib/Drupal/Core/Entity/EntityTypeManager.php:169
/var/www/cip/bobp_new/modules/custom/users_csv_importer/src/Form/ImportForm.php:156
/var/www/cip/bobp_new/modules/custom/users_csv_importer/tests/src/Functional/ImportTest.php:51
Here the code of my test :
public function testImportCSV() {
$this->assertEquals(25, $this->import_form->getCountryId("AT"));
}
If remove this assert and try to assert my import function (which read a CSV file and for each line create a user) then my custom field created on user throw another exception : InvalidArgumentException: Field field_gender is unknown.
It's look like that database is not complete during tests.
Do I have misunderstanding something or it's something wrong with Drupal ?
I can provide more code if needed.
Thanks.