class DirectoryFetcherTest in Feeds 8.3
Same name in this branch
- 8.3 tests/src/Unit/Feeds/Fetcher/DirectoryFetcherTest.php \Drupal\Tests\feeds\Unit\Feeds\Fetcher\DirectoryFetcherTest
- 8.3 tests/src/Kernel/Feeds/Fetcher/DirectoryFetcherTest.php \Drupal\Tests\feeds\Kernel\Feeds\Fetcher\DirectoryFetcherTest
@coversDefaultClass \Drupal\feeds\Feeds\Fetcher\DirectoryFetcher @group feeds
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
- class \Drupal\Tests\feeds\Unit\Feeds\Fetcher\DirectoryFetcherTest
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
Expanded class hierarchy of DirectoryFetcherTest
File
- tests/
src/ Unit/ Feeds/ Fetcher/ DirectoryFetcherTest.php, line 16
Namespace
Drupal\Tests\feeds\Unit\Feeds\FetcherView source
class DirectoryFetcherTest extends FeedsUnitTestCase {
/**
* The Feeds fetcher plugin under test.
*
* @var \Drupal\feeds\Feeds\Fetcher\DirectoryFetcher
*/
protected $fetcher;
/**
* The state object.
*
* @var \Drupal\feeds\StateInterface
*/
protected $state;
/**
* The feed entity.
*
* @var \Drupal\feeds\FeedInterface
*/
protected $feed;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$feed_type = $this
->createMock('Drupal\\feeds\\FeedTypeInterface');
$container = new ContainerBuilder();
$container
->set('stream_wrapper_manager', $this
->getMockStreamWrapperManager());
$this->fetcher = new DirectoryFetcher([
'feed_type' => $feed_type,
], 'directory', []);
$this->fetcher
->setStringTranslation($this
->getStringTranslationStub());
$this->state = new State();
$this->feed = $this
->createMock('Drupal\\feeds\\FeedInterface');
$this->feed
->expects($this
->any())
->method('getSource')
->will($this
->returnValue('vfs://feeds'));
// Prepare filesystem.
touch('vfs://feeds/test_file_1.txt');
touch('vfs://feeds/test_file_2.txt');
touch('vfs://feeds/test_file_3.txt');
touch('vfs://feeds/test_file_3.mp3');
chmod('vfs://feeds/test_file_3.txt', 0333);
mkdir('vfs://feeds/subdir');
touch('vfs://feeds/subdir/test_file_4.txt');
touch('vfs://feeds/subdir/test_file_4.mp3');
}
/**
* Tests fetching a file.
*
* @covers ::fetch
*/
public function testFetchFile() {
$feed = $this
->createMock('Drupal\\feeds\\FeedInterface');
$feed
->expects($this
->any())
->method('getSource')
->will($this
->returnValue('vfs://feeds/test_file_1.txt'));
$result = $this->fetcher
->fetch($feed, $this->state);
$this
->assertSame('vfs://feeds/test_file_1.txt', $result
->getFilePath());
}
/**
* Tests fetching from a directory on which we don't have read permissions.
*
* @covers ::fetch
*/
public function testFetchDir() {
$result = $this->fetcher
->fetch($this->feed, $this->state);
$this
->assertSame($this->state->total, 2);
$this
->assertSame('vfs://feeds/test_file_1.txt', $result
->getFilePath());
$this
->assertSame('vfs://feeds/test_file_2.txt', $this->fetcher
->fetch($this->feed, $this->state)
->getFilePath());
chmod('vfs://feeds', 0333);
$this
->expectException(RuntimeException::class);
$result = $this->fetcher
->fetch($this->feed, $this->state);
}
/**
* Tests fetching a directory resursively.
*
* @covers ::fetch
*/
public function testRecursiveFetchDir() {
$this->fetcher
->setConfiguration([
'recursive_scan' => TRUE,
]);
$result = $this->fetcher
->fetch($this->feed, $this->state);
$this
->assertSame($this->state->total, 3);
$this
->assertSame('vfs://feeds/test_file_1.txt', $result
->getFilePath());
$this
->assertSame('vfs://feeds/test_file_2.txt', $this->fetcher
->fetch($this->feed, $this->state)
->getFilePath());
$this
->assertSame('vfs://feeds/subdir/test_file_4.txt', $this->fetcher
->fetch($this->feed, $this->state)
->getFilePath());
}
/**
* Tests fetching an empty directory.
*
* @covers ::fetch
*/
public function testEmptyDirectory() {
mkdir('vfs://feeds/emptydir');
$feed = $this
->createMock('Drupal\\feeds\\FeedInterface');
$feed
->expects($this
->any())
->method('getSource')
->will($this
->returnValue('vfs://feeds/emptydir'));
$this
->expectException(EmptyFeedException::class);
$result = $this->fetcher
->fetch($feed, $this->state);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DirectoryFetcherTest:: |
protected | property | The feed entity. | |
DirectoryFetcherTest:: |
protected | property | The Feeds fetcher plugin under test. | |
DirectoryFetcherTest:: |
protected | property | The state object. | |
DirectoryFetcherTest:: |
public | function |
Overrides FeedsUnitTestCase:: |
|
DirectoryFetcherTest:: |
public | function | Tests fetching an empty directory. | |
DirectoryFetcherTest:: |
public | function | Tests fetching from a directory on which we don't have read permissions. | |
DirectoryFetcherTest:: |
public | function | Tests fetching a file. | |
DirectoryFetcherTest:: |
public | function | Tests fetching a directory resursively. | |
FeedsMockingTrait:: |
protected | function | Mocks an account object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked AccountSwitcher object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed entity. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed type entity. | |
FeedsMockingTrait:: |
protected | function | Mocks a field definition. | 1 |
FeedsMockingTrait:: |
protected | function | Mocks the file system. | |
FeedsReflectionTrait:: |
protected | function | Calls a protected method on the given object. | |
FeedsReflectionTrait:: |
protected | function | Gets a ReflectionMethod for a class method. | |
FeedsReflectionTrait:: |
protected | function | Returns a dynamically created closure for the object's method. | |
FeedsReflectionTrait:: |
protected | function | Sets a protected property. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the Feeds module. | |
FeedsUnitTestCase:: |
protected | function | Defines stub constants. | |
FeedsUnitTestCase:: |
protected | function | Returns a mock stream wrapper manager. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the resources folder. | |
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. |