You are here

public function FormatDecoderTestBase::testDecode in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_import/tests/src/Kernel/FormatDecoderTestBase.php \Drupal\Tests\bibcite_import\Kernel\FormatDecoderTestBase::testDecode()

Tests a files decode.

@coversDefaultClass

File

modules/bibcite_import/tests/src/Kernel/FormatDecoderTestBase.php, line 44

Class

FormatDecoderTestBase
Base class for encode function testing.

Namespace

Drupal\Tests\bibcite_import\Kernel

Code

public function testDecode() {
  $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 . '.json';
      if (file_exists($this->resultDir . '/' . $result_file)) {
        $encoded_source = file_get_contents($this->inputDir . '/' . $file);
        $expected = json_decode(file_get_contents($this->resultDir . '/' . $result_file), TRUE);
        $decoded_source = json_decode(json_encode($this->encoder
          ->decode($encoded_source, $this->format)), TRUE);
        $this
          ->assertEquals($expected, $decoded_source);
      }
      else {
        $this
          ->fail('Result file not exist for ' . $file);
      }
    }
  }
  if (!$this
    ->getCount()) {
    $this
      ->fail('No assertions in ' . __FUNCTION__);
  }
}