public static function ContentProcessorTest::assertFileFieldEqualsResponseFiles in GatherContent 8.4
Assertion for file elements.
1 call to ContentProcessorTest::assertFileFieldEqualsResponseFiles()
- ContentProcessorTest::assertFieldEqualsElement in tests/
src/ Kernel/ ContentProcessorTest.php - Assertion for Drupal field and GC element.
File
- tests/
src/ Kernel/ ContentProcessorTest.php, line 244
Class
- ContentProcessorTest
- Class for testing core node import functionality.
Namespace
Drupal\Tests\gathercontent\KernelCode
public static function assertFileFieldEqualsResponseFiles(array $field, array $files) {
// No files attached to GC item.
if (empty($files)) {
static::assertEmpty($field, 'No files should be inserted.');
return;
}
// Always insert the latest file gotten from API.
static::assertEquals(1, count($field), 'There must only be one image in the field.');
$fileId = reset($field)['target_id'];
$fileField = File::load($fileId);
static::assertNotNull($fileField, 'File was not saved.');
/** @var \Cheppers\GatherContent\DataTypes\File $fileResponse */
$fileResponse = end($files);
static::assertEquals($fileResponse->url, $fileField
->get('uri')
->getValue()[0]['value'], 'Incorrect field value.');
static::assertEquals($fileResponse->id, $fileField
->get('gc_id')
->getValue()[0]['value'], 'Incorrect field value.');
static::assertEquals($fileResponse->fileName, $fileField
->get('filename')
->getValue()[0]['value'], 'Incorrect field value.');
}