public function FormatEncoderTestBase::testEncode in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_export/tests/src/Kernel/FormatEncoderTestBase.php \Drupal\Tests\bibcite_export\Kernel\FormatEncoderTestBase::testEncode()
Tests a files encode.
@coversDefaultClass
File
- modules/
bibcite_export/ tests/ src/ Kernel/ FormatEncoderTestBase.php, line 49
Class
- FormatEncoderTestBase
- Base class for encode function testing.
Namespace
Drupal\Tests\bibcite_export\KernelCode
public function testEncode() {
$input = scandir($this->inputDir);
foreach ($input as $file) {
if (is_file($this->inputDir . '/' . $file)) {
$info = pathinfo($file);
$file_name = basename($file, '.' . $info['extension']);
$result_file = $file_name . '.' . $this->encodedExtension;
if (file_exists($this->resultDir . '/' . $result_file)) {
$source_array = json_decode(file_get_contents($this->inputDir . '/' . $file), TRUE);
$encoded_source = $this->encoder
->encode($source_array, $this->format);
$expected = file_get_contents($this->resultDir . '/' . $result_file);
$this
->assertEquals($expected, $encoded_source);
}
else {
$this
->fail('Result file not exist for ' . $file);
}
}
}
if (!$this
->getCount()) {
$this
->fail('No assertions in ' . __FUNCTION__);
}
}