Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / file_mdm / tests / src / Kernel / FileMetadataManagerTestBase.php
diff --git a/web/modules/contrib/file_mdm/tests/src/Kernel/FileMetadataManagerTestBase.php b/web/modules/contrib/file_mdm/tests/src/Kernel/FileMetadataManagerTestBase.php
new file mode 100644 (file)
index 0000000..72de719
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Tests\file_mdm\Kernel;
+
+use Drupal\file_mdm\FileMetadataInterface;
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Base test class for File Metadata Manager.
+ */
+abstract class FileMetadataManagerTestBase extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+    $this->installConfig(['file_mdm']);
+  }
+
+  /**
+   * Returns the count of metadata keys found in the file.
+   *
+   * @param \Drupal\file_mdm\FileMetadataInterface $file_md
+   *   The FileMetadata object.
+   * @param string $metadata_id
+   *   The file metadata plugin id.
+   * @param mixed $options
+   *   (optional) Allows specifying additional options to control the list of
+   *   metadata keys returned.
+   *
+   * @return int
+   *   The count of metadata keys found in the file.
+   */
+  protected function countMetadataKeys(FileMetadataInterface $file_md, $metadata_id, $options = NULL) {
+    $supported_keys = $file_md->getSupportedKeys($metadata_id, $options);
+    $count = 0;
+    foreach ($supported_keys as $key) {
+      if ($file_md->getMetadata($metadata_id, $key)) {
+        $count++;
+      }
+    }
+    return $count;
+  }
+
+}