FetcherResultTest.php in Feeds 8.3
File
tests/src/Unit/Result/FetcherResultTest.php
View source
<?php
namespace Drupal\Tests\feeds\Unit\Result;
use Drupal\feeds\Result\FetcherResult;
use Drupal\Tests\feeds\Unit\FeedsUnitTestCase;
use RuntimeException;
class FetcherResultTest extends FeedsUnitTestCase {
public function testGetRaw() {
file_put_contents('vfs://feeds/test_file', pack('CCC', 0xef, 0xbb, 0xbf) . 'I am test data.');
$result = new FetcherResult('vfs://feeds/test_file');
$this
->assertSame('I am test data.', $result
->getRaw());
}
public function testGetFilePath() {
file_put_contents('vfs://feeds/test_file', 'I am test data.');
$result = new FetcherResult('vfs://feeds/test_file');
$this
->assertSame('vfs://feeds/test_file', $result
->getFilePath());
}
public function testGetSanitizedFilePath() {
file_put_contents('vfs://feeds/test_file', pack('CCC', 0xef, 0xbb, 0xbf) . 'I am test data.');
$result = new FetcherResult('vfs://feeds/test_file');
$this
->assertSame('I am test data.', file_get_contents($result
->getFilePath()));
}
public function testNonExistantFile() {
$result = new FetcherResult('IDONOTEXIST');
$this
->expectException(RuntimeException::class);
$result
->getRaw();
}
public function testNonReadableFile() {
file_put_contents('vfs://feeds/test_file', 'I am test data.');
chmod('vfs://feeds/test_file', 00);
$result = new FetcherResult('vfs://feeds/test_file');
$this
->expectException(RuntimeException::class);
$result
->getRaw();
}
public function testNonWritableFile() {
file_put_contents('vfs://feeds/test_file', pack('CCC', 0xef, 0xbb, 0xbf) . 'I am test data.');
chmod('vfs://feeds/test_file', 0444);
$result = new FetcherResult('vfs://feeds/test_file');
$this
->expectException(RuntimeException::class);
$result
->getFilePath();
}
}