function ImageUploadTest::getTestImageByStat

Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/Functional/ImageUploadTest.php \Drupal\Tests\ckeditor5\Functional\ImageUploadTest::getTestImageByStat()
  2. 11.x core/modules/ckeditor5/tests/src/Functional/ImageUploadTest.php \Drupal\Tests\ckeditor5\Functional\ImageUploadTest::getTestImageByStat()

Return the first image matching $condition.

Parameters

array $images: Images created with getTestFiles().

string $stat: A key in the array returned from stat().

callable $condition: A function to compare a value of the image file.

Return value

object|bool Objects with 'uri', 'filename', and 'name' properties.

2 calls to ImageUploadTest::getTestImageByStat()
ImageUploadTest::testFileUploadLargerFileSize in core/modules/ckeditor5/tests/src/Functional/ImageUploadTest.php
Tests using the file upload route with a file size larger than allowed.
ImageUploadTest::testLockAfterFailedValidation in core/modules/ckeditor5/tests/src/Functional/ImageUploadTest.php
Test that lock is removed after a failed validation.

File

core/modules/ckeditor5/tests/src/Functional/ImageUploadTest.php, line 249

Class

ImageUploadTest
Test image upload.

Namespace

Drupal\Tests\ckeditor5\Functional

Code

protected function getTestImageByStat(array $images, string $stat, callable $condition) {
    return current(array_filter($images, function ($image) use ($condition, $stat) {
        $stats = stat($image->uri);
        return $condition($stats[$stat]);
    }));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.