Skip to content

Commit

Permalink
OPENEUROPA-2659: Simplify file creation with path.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyad committed Apr 15, 2020
1 parent 04ae9bb commit 59bf4d9
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions tests/Behat/MediaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 59bf4d9

Please sign in to comment.