From a0acfce4ba3a7c3be2b5c29bb6ef9e042fea4919 Mon Sep 17 00:00:00 2001 From: nagyad Date: Wed, 8 Apr 2020 10:19:11 +0200 Subject: [PATCH] OPENEUROPA-2659: Simplify file creation with path. --- tests/Behat/MediaContext.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/Behat/MediaContext.php b/tests/Behat/MediaContext.php index 578fc104..7b4f8b5c 100644 --- a/tests/Behat/MediaContext.php +++ b/tests/Behat/MediaContext.php @@ -119,9 +119,7 @@ public function createMediaDocuments(TableNode $table): void { // Retrieve the url table from the test scenario. $files = $table->getColumnsHash(); foreach ($files as $properties) { - $file_name = basename($properties['file']); - $file_path = strpos($properties['file'], '/') ? dirname($properties['file']) . '/' : ''; - $file = $this->createFileEntity($file_name, $file_path); + $file = $this->createFileEntity($properties['file']); $media = \Drupal::entityTypeManager() ->getStorage('media')->create([ 'bundle' => 'document', @@ -157,9 +155,7 @@ public function createMediaImages(TableNode $table): void { // Retrieve the url table from the test scenario. $files = $table->getColumnsHash(); foreach ($files as $properties) { - $file_name = basename($properties['file']); - $file_path = strpos($properties['file'], '/') ? dirname($properties['file']) . '/' : ''; - $file = $this->createFileEntity($file_name, $file_path); + $file = $this->createFileEntity($properties['file']); $media = \Drupal::entityTypeManager() ->getStorage('media')->create([ 'bundle' => 'image', @@ -268,14 +264,12 @@ protected function getConfigContext(): ConfigContext { * * @param string $file_name * File name, relative to Mink 'files_path' location. - * @param string $path - * The relative file path. * * @return \Drupal\file\FileInterface * File entity object. */ - protected function createFileEntity(string $file_name, string $path = ''): FileInterface { - $file = file_save_data(file_get_contents($this->getMinkParameter('files_path') . $path . $file_name), 'public://' . $file_name); + protected function createFileEntity(string $file_name): FileInterface { + $file = file_save_data(file_get_contents($this->getMinkParameter('files_path') . $file_name), 'public://' . basename($file_name)); $file->setPermanent(); $file->save();