class HttpStreamWrapperTest in Remote Stream Wrapper 8
Same name in this branch
- 8 tests/src/Unit/HttpStreamWrapperTest.php \Drupal\Tests\remote_stream_wrapper\Unit\HttpStreamWrapperTest
- 8 tests/src/Kernel/HttpStreamWrapperTest.php \Drupal\Tests\remote_stream_wrapper\Kernel\HttpStreamWrapperTest
@group remote_stream_wrapper @coversDefaultClass \Drupal\remote_stream_wrapper\StreamWrapper\HttpStreamWrapper
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\remote_stream_wrapper\Unit\HttpStreamWrapperTest
Expanded class hierarchy of HttpStreamWrapperTest
File
- tests/
src/ Unit/ HttpStreamWrapperTest.php, line 14
Namespace
Drupal\Tests\remote_stream_wrapper\UnitView source
class HttpStreamWrapperTest extends UnitTestCase {
/**
* Test that the wrapper constants.
*
* @covers ::getType
* @covers ::getName
* @covers ::getDescription
*/
public function testStreamConfiguration() {
$type = HttpStreamWrapper::getType();
$this
->assertEquals(StreamWrapperInterface::READ & StreamWrapperInterface::HIDDEN, $type);
$this
->assertEquals($type & StreamWrapperInterface::LOCAL, 0);
$this
->assertNotEquals($type & StreamWrapperInterface::READ, 0);
$this
->assertEquals($type & StreamWrapperInterface::WRITE, 0);
$this
->assertEquals($type & StreamWrapperInterface::VISIBLE, 0);
$this
->assertNotEquals($type & StreamWrapperInterface::HIDDEN, 0);
//$this->assertEquals($type & StreamWrapperInterface::LOCAL_HIDDEN, 0);
//$this->assertEquals($type & StreamWrapperInterface::WRITE_VISIBLE, 0);
$this
->assertNotEquals($type & StreamWrapperInterface::READ_VISIBLE, 0);
//$this->assertEquals($type & StreamWrapperInterface::NORMAL, 0);
//$this->assertEquals($type & StreamWrapperInterface::LOCAL_NORMAL, 0);
$wrapper = new HttpStreamWrapper(new Client());
$this
->assertInternalType('string', $wrapper
->getName());
$this
->assertInternalType('string', $wrapper
->getDescription());
}
/**
* Test URI methods.
*
* @covers ::setUri
* @covers ::getUri
* @covers ::getExternalUrl
* @covers ::realpath
*/
public function testUri() {
$wrapper = new HttpStreamWrapper();
$uri = 'http://example.com/file.txt';
$wrapper
->setUri($uri);
$this
->assertEquals($uri, $wrapper
->getUri());
$this
->assertEquals($uri, $wrapper
->getExternalUrl());
$this
->assertEquals(FALSE, $wrapper
->realpath());
}
/**
* Test dirname().
*
* @covers ::dirname
*/
public function testDirname() {
$wrapper = new HttpStreamWrapper();
// Test dirname() with no parameters.
$wrapper
->setUri('http://example.com/test.txt');
$this
->assertEquals('http://example.com', $wrapper
->dirname());
// Test dirname() with one directory.
$wrapper
->setUri('http://example.com/directory/test.txt');
$this
->assertEquals('http://example.com/directory', $wrapper
->dirname());
// Test dirname() with two directories and a $uri parameter.
$this
->assertEquals('http://example.com/directory/directory2', $wrapper
->dirname('http://example.com/directory/directory2/test.txt'));
// Test referencing self with a dot.
$this
->assertEquals('http://', $wrapper
->dirname('http://.'));
}
/**
* Test that we always return TRUE for locks.
*
* @covers ::stream_lock
*/
public function testStreamLock() {
$wrapper = new HttpStreamWrapper();
$wrapper
->setUri('http://example.com/test.txt');
foreach ([
LOCK_SH,
LOCK_EX,
LOCK_UN,
LOCK_NB,
] as $type) {
$this
->assertTrue($wrapper
->stream_lock($type));
}
}
/**
* Test that the timeout is set properly in configuration.
*
* @covers ::stream_set_option
*/
public function testStreamSetOption() {
$wrapper = new HttpStreamWrapper();
$result = $wrapper
->stream_set_option(STREAM_OPTION_READ_TIMEOUT, 30, 50);
$this
->assertTrue($result);
$config = $wrapper
->getHttpConfig();
$this
->assertEquals($config['timeout'], 30.00005);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HttpStreamWrapperTest:: |
public | function | Test dirname(). | |
HttpStreamWrapperTest:: |
public | function | Test that the wrapper constants. | |
HttpStreamWrapperTest:: |
public | function | Test that we always return TRUE for locks. | |
HttpStreamWrapperTest:: |
public | function | Test that the timeout is set properly in configuration. | |
HttpStreamWrapperTest:: |
public | function | Test URI methods. | |
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. | |
UnitTestCase:: |
protected | function | 340 |