class FixtureTest in Mini site 8
Class FixtureTest.
Tests for fixture creation trait (tests for test helpers).
@group minisite
@package Drupal\testmode\Tests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\minisite\Unit\FixtureTest uses FixtureTrait
Expanded class hierarchy of FixtureTest
File
- tests/
src/ Unit/ FixtureTest.php, line 19
Namespace
Drupal\Tests\minisite\UnitView source
class FixtureTest extends UnitTestCase {
use FixtureTrait;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this
->fixtureSetUp();
}
/**
* {@inheritdoc}
*/
protected function tearDown() {
parent::tearDown();
$this
->fixtureTearDown();
}
/**
* Test SetUp and TearDown methods for the trait.
*/
public function testSetupTeardown() {
// $fixtureDir is already populated from the setUp() of this test,
// so we need to remove it.
$fs = new Filesystem();
$fs
->remove($this->fixtureDir);
$this
->fixtureSetUp();
$first_dir = $this->fixtureDir;
$this
->assertNotEmpty($first_dir, 'fixtureSetUp() populates $fixtureDir variable');
$this
->assertDirectoryExists($first_dir, 'fixtureSetUp() creates directory');
$this
->fixtureSetUp();
$second_dir = $this->fixtureDir;
$this
->assertNotEmpty($second_dir, 'fixtureSetUp() populates $fixtureDir variable');
$this
->assertDirectoryExists($second_dir, 'fixtureSetUp() creates directory');
$this
->assertNotEquals($first_dir, $second_dir, 'fixtureSetUp() creates new directory on every call');
$this
->fixtureTearDown();
$this
->assertDirectoryNotExists($second_dir, 'fixtureTearDown() removes directory');
$this
->assertEmpty($this->fixtureDir, 'fixtureTearDown() removes the value from $fixtureDir');
}
/**
* Test fixtureCreateFiles() method.
*/
public function testFixtureCreateFiles() {
// @codingStandardsIgnoreStart
$files = [
'dir1',
'file1' => 'content1',
'dir2/file21' => 'content21',
'dir2/file22' => 'content22',
'dir3/dir31/dir/311',
];
// @codingStandardsIgnoreEnd
$expected_files = [
$this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir1' => 'dir1',
$this->fixtureDir . \DIRECTORY_SEPARATOR . 'file1' => 'file1',
$this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir2/file21' => 'dir2/file21',
$this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir2/file22' => 'dir2/file22',
$this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir3/dir31/dir/311' => 'dir3/dir31/dir/311',
];
$actual_files = $this
->fixtureCreateFiles($files);
$this
->assertEquals($expected_files, $actual_files);
$this
->assertDirectoryExists($this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir1');
$this
->assertFileExists($this->fixtureDir . \DIRECTORY_SEPARATOR . 'file1');
$this
->assertStringEqualsFile($this->fixtureDir . \DIRECTORY_SEPARATOR . 'file1', 'content1');
$this
->assertStringEqualsFile($this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir2/file21', 'content21');
$this
->assertStringEqualsFile($this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir2/file22', 'content22');
$this
->assertDirectoryExists($this->fixtureDir . \DIRECTORY_SEPARATOR . 'dir3/dir31/dir/311');
}
/**
* Test fixtureCreateArchive() method.
*/
public function testFixtureCreateArchive() {
// @codingStandardsIgnoreStart
$files = [
'dir1',
'file1' => 'content1',
'dir2/file21' => 'content21',
'dir2/file22' => 'content22',
'dir3/dir31/dir/311',
];
// @codingStandardsIgnoreEnd
$expected_files = [
'dir1/',
'file1',
'dir2/file21',
'dir2/file22',
'dir3/dir31/dir/311/',
];
$archive_filename = $this
->fixtureCreateArchive($files, 'zip');
$this
->assertFileExists($archive_filename);
$archive = new Zip($archive_filename);
$actual_files = $archive
->listContents();
sort($expected_files);
sort($actual_files);
$this
->assertEquals($expected_files, $actual_files);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FixtureTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FixtureTest:: |
protected | function | ||
FixtureTest:: |
public | function | Test fixtureCreateArchive() method. | |
FixtureTest:: |
public | function | Test fixtureCreateFiles() method. | |
FixtureTest:: |
public | function | Test SetUp and TearDown methods for the trait. | |
FixtureTrait:: |
protected | property | The directory where fixture files reside for this test. | |
FixtureTrait:: |
public | function | Create archive from an array of specified files. | |
FixtureTrait:: |
public | function | Create a single file with content. | |
FixtureTrait:: |
public | function | Create directories and files with content. | |
FixtureTrait:: |
public | function | Create a fixture HTML page. | |
FixtureTrait:: |
public | function | Create a fixture link. | |
FixtureTrait:: |
protected | function | Set up functionality. | |
FixtureTrait:: |
protected | function | Tear down functionality. | |
FixtureTrait:: |
public | function | Get the path to the directory with fixture files. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |