Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / file_mdm / tests / src / Kernel / FileMetadataManagerTestBase.php
1 <?php
2
3 namespace Drupal\Tests\file_mdm\Kernel;
4
5 use Drupal\file_mdm\FileMetadataInterface;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Base test class for File Metadata Manager.
10  */
11 abstract class FileMetadataManagerTestBase extends KernelTestBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function setUp() {
17     parent::setUp();
18     $this->installConfig(['file_mdm']);
19   }
20
21   /**
22    * Returns the count of metadata keys found in the file.
23    *
24    * @param \Drupal\file_mdm\FileMetadataInterface $file_md
25    *   The FileMetadata object.
26    * @param string $metadata_id
27    *   The file metadata plugin id.
28    * @param mixed $options
29    *   (optional) Allows specifying additional options to control the list of
30    *   metadata keys returned.
31    *
32    * @return int
33    *   The count of metadata keys found in the file.
34    */
35   protected function countMetadataKeys(FileMetadataInterface $file_md, $metadata_id, $options = NULL) {
36     $supported_keys = $file_md->getSupportedKeys($metadata_id, $options);
37     $count = 0;
38     foreach ($supported_keys as $key) {
39       if ($file_md->getMetadata($metadata_id, $key)) {
40         $count++;
41       }
42     }
43     return $count;
44   }
45
46 }