class LocalTest in Flysystem 8
Same name and namespace in other branches
- 3.x tests/src/Unit/Flysystem/LocalTest.php \Drupal\Tests\flysystem\Unit\Flysystem\LocalTest
- 2.0.x tests/src/Unit/Flysystem/LocalTest.php \Drupal\Tests\flysystem\Unit\Flysystem\LocalTest
- 3.0.x tests/src/Unit/Flysystem/LocalTest.php \Drupal\Tests\flysystem\Unit\Flysystem\LocalTest
@coversDefaultClass \Drupal\flysystem\Flysystem\Local @group flysystem
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\flysystem\Unit\Flysystem\LocalTest
Expanded class hierarchy of LocalTest
File
- tests/
src/ Unit/ Flysystem/ LocalTest.php, line 19
Namespace
Drupal\Tests\flysystem\Unit\FlysystemView source
class LocalTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$GLOBALS['base_url'] = 'http://example.com';
$container = new ContainerBuilder();
$url_generator = $this
->prophesize(UrlGeneratorInterface::class);
$url_generator
->generateFromRoute(Argument::cetera())
->willReturn('download');
$container
->set('url_generator', $url_generator
->reveal());
\Drupal::setContainer($container);
(new LocalAdapter('foo/bar'))
->deleteDir('');
@rmdir('foo/bar');
@rmdir('foo');
mkdir('foo');
mkdir('foo/bar');
touch('test.txt');
}
/**
* {@inheritdoc}
*/
public function tearDown() {
(new LocalAdapter('foo'))
->deleteDir('');
@rmdir('foo');
unlink('test.txt');
@unlink('does_not_exist/.htaccess');
@rmdir('does_not_exist');
}
/**
* @covers ::__construct
* @covers ::create
*/
public function testCreateReturnsPlugin() {
$container = new ContainerBuilder();
$settings = new Settings([]);
$container
->set('settings', $settings);
$configuration = [
'root' => 'foo/bar',
];
$this
->assertInstanceOf(Local::class, Local::create($container, $configuration, '', []));
}
/**
* @covers ::getAdapter
* @covers ::ensureDirectory
*/
public function testReturnsLocalAdapter() {
$this
->assertInstanceOf(LocalAdapter::class, (new Local('foo/bar', FALSE))
->getAdapter());
}
/**
* @covers ::getAdapter
* @covers ::ensureDirectory
*/
public function testMissingAdapterReturnedWhenPathIsFile() {
$this
->assertInstanceOf(MissingAdapter::class, (new Local('test.txt'))
->getAdapter());
}
/**
* @covers ::getExternalUrl
*/
public function testReturnsValidLocalUrl() {
$plugin = new Local('foo/bar', FALSE);
$this
->assertSame('download', $plugin
->getExternalUrl('uri://test.html'));
}
/**
* @covers ::getExternalUrl
*/
public function testReturnsValidExternalUrl() {
$plugin = new Local('foo/bar', TRUE);
$this
->assertSame('http://example.com/foo/bar/test%20thing.html', $plugin
->getExternalUrl('uri://test thing.html'));
}
/**
* @covers ::ensure
* @covers ::ensureDirectory
*/
public function testDirectoryIsAutoCreatedAndHtaccessIsWritten() {
$plugin = new Local('does_not_exist');
$this
->assertTrue(is_dir('does_not_exist'));
$this
->assertTrue(is_file('does_not_exist/.htaccess'));
}
/**
* @covers ::ensure
* @covers ::writeHtaccess
*/
public function testHtaccessNotOverwritten() {
file_put_contents('foo/bar/.htaccess', 'htcontent');
$result = (new Local('foo/bar'))
->ensure();
$this
->assertSame(1, count($result));
$this
->assertSame(RfcLogLevel::INFO, $result[0]['severity']);
$this
->assertSame('htcontent', file_get_contents('foo/bar/.htaccess'));
}
/**
* @covers ::ensure
* @covers ::writeHtaccess
*/
public function testHtaccessNotOverwrittenAndFails() {
mkdir('foo/bar/.htaccess', 0777, TRUE);
$result = (new Local('foo/bar'))
->ensure(TRUE);
$this
->assertSame(1, count($result));
$this
->assertSame('https://www.drupal.org/SA-CORE-2013-003', $result[0]['context']['@url']);
}
/**
* @covers ::ensure
* @covers ::writeHtaccess
*/
public function testEnsureReturnsErrorWhenCantCreateDir() {
$result = (new Local('test.txt'))
->ensure();
$this
->assertSame('test.txt', $result[0]['context']['%root']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocalTest:: |
public | function |
Overrides UnitTestCase:: |
|
LocalTest:: |
public | function | ||
LocalTest:: |
public | function | @covers ::__construct @covers ::create | |
LocalTest:: |
public | function | @covers ::ensure @covers ::ensureDirectory | |
LocalTest:: |
public | function | @covers ::ensure @covers ::writeHtaccess | |
LocalTest:: |
public | function | @covers ::ensure @covers ::writeHtaccess | |
LocalTest:: |
public | function | @covers ::ensure @covers ::writeHtaccess | |
LocalTest:: |
public | function | @covers ::getAdapter @covers ::ensureDirectory | |
LocalTest:: |
public | function | @covers ::getAdapter @covers ::ensureDirectory | |
LocalTest:: |
public | function | @covers ::getExternalUrl | |
LocalTest:: |
public | function | @covers ::getExternalUrl | |
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. |