From 8117ecf0f305c5f617337c2ca905aa9b6f4efc62 Mon Sep 17 00:00:00 2001 From: Ryan Price Date: Sat, 6 Aug 2016 14:32:41 -0700 Subject: [PATCH] use the correct Drupal 8 file methods --- .../Context/DrupalFileContext.php | 21 ++++++++++++------- .../Context/SharedDrupalContext.php | 8 +++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php index 3b30166..c6a3dbf 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php @@ -30,14 +30,15 @@ class DrupalFileContext extends SharedDrupalContext */ public function createFile($filename, $status = 1) { - throw new NotUpdatedException(); $file = new File(array(), 'file'); $file->setFilename($filename); - $file->setPermanent(); - /* - $file->save(); //needs to happen somewhere - */ + if($status) { + $file->setPermanent(); + } + else { + $file->setTemporary(); + } $file = $this->expandFile($file); @@ -63,10 +64,16 @@ public function createFile($filename, $status = 1) */ public function createFiles(TableNode $filesTable) { - throw new NotUpdatedException(); foreach ($filesTable->getHash() as $fileHash) { - $file = (object) $fileHash; + $file = new File(array(), 'file'); + $file->setFilename($fileHash['filename']); + if($fileHash['status']) { + $file->setPermanent(); + } + else { + $file->setTemporary(); + } $file = $this->expandFile($file); $this->fileCreate($file); diff --git a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php index c29a27f..f9b4fd5 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php @@ -165,8 +165,6 @@ public function findUserByName($userName) */ public function fileCreate($file) { - throw new NotUpdatedException(); - // Save the file and overwrite if it already exists. $dest = file_build_uri(drupal_basename($file->GetFileUri())); $result = file_copy($file, $dest, FILE_EXISTS_REPLACE); @@ -195,8 +193,6 @@ public function fileCreate($file) */ public function expandFile($file) { - throw new NotUpdatedException(); - if (empty($file->getFilename()) === true) { throw new \Exception("Can't create file with no source filename; this should be the name of a file within the MinkExtension's files_path directory."); } @@ -205,6 +201,10 @@ public function expandFile($file) // files_path parameter. $file->setFileUri(rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename()); + $file->set('langcode', $file->language()->getId()); + + $file->setChangedTime(time()); + // Assign authorship if none exists and `author` is passed. /* if (isset($file->getOwnerId()) === false && empty($file->author) === false) {