You are here

class RealisticDummyContentEnvironmentTest in Realistic Dummy Content 3.x

Tests for ...\includes\RealisticDummyContentEnvironment.

@group realistic_dummy_content

Hierarchy

Expanded class hierarchy of RealisticDummyContentEnvironmentTest

File

api/tests/src/Unit/includes/RealisticDummyContentEnvironmentTest.php, line 49

Namespace

Drupal\Tests\realistic_dummy_content_api\Unit\includes
View source
class RealisticDummyContentEnvironmentTest extends TestCase {

  /**
   * Test that file names are properly parsed and combined.
   */
  public function testFiles() {
    $data = [
      'one.txt' => new \stdClass(),
      'reAdme.txt' => new \stdClass(),
      'README.md' => new \stdClass(),
      'readme.jpg' => new \stdClass(),
      'two.txt' => new \stdClass(),
      'two.notanattribute.txt' => new \stdClass(),
      'two.txt.attribute.txt' => new \stdClass(),
      'two.txt.attribute1.txt' => new \stdClass(),
      'three.png' => new \stdClass(),
      'three.png.alt.txt' => new \stdClass(),
    ];
    try {
      $parsed = RealisticDummyContentEnvironment::sortCandidateFiles($data);
      $parsed_images = RealisticDummyContentEnvironment::sortCandidateFiles($data, [
        'png',
      ]);
    } catch (\Throwable $e) {
      $this
        ->assertFalse(TRUE, 'Got exception ' . $e
        ->getMessage());
    }
    $this
      ->assertTrue(count($parsed) == 4, '4 parsed files are returned, which excludes the readme riles (4 == ' . count($parsed) . ')');
    $this
      ->assertTrue(is_object($parsed['one.txt']['file']));
    $this
      ->assertTrue(is_object($parsed['two.txt']['file']));
    $this
      ->assertTrue(is_object($parsed['two.txt']['attributes']['attribute']));
    $this
      ->assertTrue(is_object($parsed['two.txt']['attributes']['attribute1']));
    $this
      ->assertTrue(is_object($parsed['three.png']['file']));
    $this
      ->assertTrue(is_object($parsed['three.png']['attributes']['alt']));
    $this
      ->assertFalse(isset($parsed_images['two.txt']['attributes']['attribute1']));
    $this
      ->assertTrue(is_object($parsed_images['three.png']['file']));
    $this
      ->assertTrue(is_object($parsed_images['three.png']['attributes']['alt']));
    $this
      ->assertTrue(is_object($parsed['two.notanattribute.txt']['file']));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RealisticDummyContentEnvironmentTest::testFiles public function Test that file names are properly parsed and combined.