ImportTest.php in Bibliography & Citation 2.0.x
File
modules/bibcite_import/tests/src/Functional/ImportTest.php
View source
<?php
namespace Drupal\Tests\bibcite_import\Functional;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\Yaml\Yaml;
class ImportTest extends BrowserTestBase {
public static $modules = [
'bibcite_import_test',
];
protected $defaultTheme = 'stable';
protected $user;
public function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'create bibcite_reference',
'edit own bibcite_reference',
'edit any bibcite_reference',
'view bibcite_reference',
'administer bibcite',
]);
}
public function testImportForm() {
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/content/bibcite/reference/import');
$page = $this
->getSession()
->getPage();
$page
->attachFileToField('edit-file', __DIR__ . '/data/zero_test.ris');
$page
->selectFieldOption('edit-format', 'RIS');
$page
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testPopulateForm($input_data, $format, $title, $year) {
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/content/bibcite/reference/populate');
$page = $this
->getSession()
->getPage();
$page
->fillField('edit-data', $input_data);
$page
->selectFieldOption('edit-format', $format);
$page
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldValueEquals('edit-title-0-value', $title);
$this
->assertSession()
->fieldValueEquals('edit-bibcite-year-0-value', $year);
}
public function testSettingsImportForm() {
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/config/bibcite/settings/import');
$page = $this
->getSession()
->getPage();
$page
->uncheckField('edit-contributor-deduplication');
$page
->uncheckField('edit-keyword-deduplication');
$page
->checkField('edit-contributor-deduplication');
$page
->checkField('edit-keyword-deduplication');
$page
->pressButton('edit-submit');
$this
->assertSession()
->statusCodeEquals(200);
}
public function importDataProvider() {
$yaml_text = file_get_contents(__DIR__ . '/data/testEntityList.data.yml');
return Yaml::parse($yaml_text);
}
}