From a2e13f9dc20f99e3ac8c1b4a7b8e8dd9a5dd41d1 Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Fri, 5 Aug 2016 10:06:46 -0500 Subject: [PATCH 01/10] Fix exception. --- .../PalantirBehatExtension/NotUpdatedException.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php index 448910f..67247e4 100644 --- a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php +++ b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php @@ -6,10 +6,12 @@ */ namespace Palantirnet\PalantirBehatExtension; +use Behat\Behat\Context\Exception\ContextException; +use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException; /** * Exception for when a method has not yet been updated for Drupal 8. */ -class NotUpdatedException extends Exception +class NotUpdatedException extends InvalidDefinitionException implements ContextException { }//end class From 173b303d51baba3e5f8cea4beb8c4bea8c15f337 Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Fri, 5 Aug 2016 10:45:32 -0500 Subject: [PATCH 02/10] Provide a message. --- .../PalantirBehatExtension/NotUpdatedException.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php index 67247e4..8ff61b5 100644 --- a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php +++ b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php @@ -14,4 +14,18 @@ */ class NotUpdatedException extends InvalidDefinitionException implements ContextException { + + /** + * NotUpdatedException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + */ + public function __construct($message, $code, \Exception $previous) + { + $this->message = "Context not updated for Drupal 8. $message"; + parent::__construct($message, $code, $previous); + } + }//end class From e8bef5464794793ae615a2cf2c1a82be3c42682a Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Fri, 5 Aug 2016 14:40:52 -0500 Subject: [PATCH 03/10] Oh yeah... phpcs. --- .../PalantirBehatExtension/NotUpdatedException.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php index 8ff61b5..6bcc956 100644 --- a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php +++ b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php @@ -16,11 +16,11 @@ class NotUpdatedException extends InvalidDefinitionException implements ContextE { /** - * NotUpdatedException constructor. + * Construct the NotUpdatedException. * - * @param string $message - * @param int $code - * @param \Exception $previous + * @param String $message [optional] The Exception message to throw. + * @param Int $code [optional] The Exception code. + * @param \Exception $previous [optional] The previous exception used. */ public function __construct($message, $code, \Exception $previous) { From bcb3598bd9be89a989e703312fb0be4e4904b345 Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Fri, 5 Aug 2016 14:47:58 -0500 Subject: [PATCH 04/10] More whitespace for phpcs. --- .../PalantirBehatExtension/NotUpdatedException.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php index 6bcc956..00138a7 100644 --- a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php +++ b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php @@ -15,6 +15,7 @@ class NotUpdatedException extends InvalidDefinitionException implements ContextException { + /** * Construct the NotUpdatedException. * @@ -26,6 +27,8 @@ public function __construct($message, $code, \Exception $previous) { $this->message = "Context not updated for Drupal 8. $message"; parent::__construct($message, $code, $previous); - } + + }//end __construct() + }//end class From b5f52b6b8533d280a22b7eb3d19667109d2f8cbd Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Sun, 7 Aug 2016 17:11:06 -0500 Subject: [PATCH 05/10] Remove overiding construct. It was broken. --- .../NotUpdatedException.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php index 00138a7..67247e4 100644 --- a/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php +++ b/src/Palantirnet/PalantirBehatExtension/NotUpdatedException.php @@ -14,21 +14,4 @@ */ class NotUpdatedException extends InvalidDefinitionException implements ContextException { - - - /** - * Construct the NotUpdatedException. - * - * @param String $message [optional] The Exception message to throw. - * @param Int $code [optional] The Exception code. - * @param \Exception $previous [optional] The previous exception used. - */ - public function __construct($message, $code, \Exception $previous) - { - $this->message = "Context not updated for Drupal 8. $message"; - parent::__construct($message, $code, $previous); - - }//end __construct() - - }//end class From 18821000474afa5c1db734680a5540e6e8c2a882 Mon Sep 17 00:00:00 2001 From: Ryan Price Date: Fri, 5 Aug 2016 11:23:38 -0700 Subject: [PATCH 06/10] attempt to update Drupal 8 file object --- .../Context/DrupalFileContext.php | 14 ++++-- .../Context/SharedDrupalContext.php | 43 ++++++++++--------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php index 4ffb1a4..556c1e3 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php @@ -9,6 +9,7 @@ use Behat\Gherkin\Node\TableNode; use Palantirnet\PalantirBehatExtension\NotUpdatedException; +use Drupal\file\Entity\File; /** * Behat context class with additional file-related steps. @@ -31,10 +32,15 @@ public function createFile($filename, $status = 1) { throw new NotUpdatedException(); - $file = (object) array( - 'filename' => $filename, - 'status' => $status, - ); + $file = new File(array('filename' => $filename, 'status' => 1), 'file'); +// $file->setFilename($filename); +// $file->setPermanent(); +// $file->save(); + +// $file = (object) array( +// 'filename' => $filename, +// 'status' => $status, +// ); $file = $this->expandFile($file); diff --git a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php index a814b13..12ee730 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php @@ -15,6 +15,7 @@ use Drupal\DrupalExtension\Context\RawDrupalContext; use Palantirnet\PalantirBehatExtension\NotUpdatedException; +use Drupal\file\Entity\File; /** * Behat context class with functionality that is shared across custom contexts. @@ -167,14 +168,14 @@ public function fileCreate($file) throw new NotUpdatedException(); // Save the file and overwrite if it already exists. - $dest = file_build_uri(drupal_basename($file->uri)); + $dest = file_build_uri(drupal_basename($file->GetFileUri())); $result = file_copy($file, $dest, FILE_EXISTS_REPLACE); // Stash the file object for later cleanup. - if (empty($result->fid) === false) { + if (empty($result->id()) === false) { $this->files[] = $result; } else { - throw new \Exception(sprintf('File "%s" could not be copied from "%s" to "%s".', $file->filename, $file->uri, $result->uri)); + throw new \Exception(sprintf('File "%s" could not be copied from "%s" to "%s".', $file->getFilename(), $file->GetFileUri(), $result->GetFileUri())); } return $result; @@ -196,33 +197,33 @@ public function expandFile($file) { throw new NotUpdatedException(); - if (empty($file->filename) === true) { + 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."); } // Set the URI to the path to the file within the MinkExtension's // files_path parameter. - $file->uri = rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->filename; + $file->setFileUri(rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename()); // Assign authorship if none exists and `author` is passed. - if (isset($file->uid) === false && empty($file->author) === false) { - $account = user_load_by_name($file->author); - if ($account !== false) { - $file->uid = $account->uid; - } - } +// if (isset($file->getOwnerId()) === false && empty($file->author) === false) { +// $account = user_load_by_name($file->author); +// if ($account !== false) { +// $file->uid = $account->uid; +// } +// } // Add default values. - $defaults = array( - 'uid' => 0, - 'status' => 1, - ); - - foreach ($defaults as $key => $default) { - if (isset($file->$key) === false) { - $file->$key = $default; - } - } +// $defaults = array( +// 'uid' => 0, +// 'status' => 1, +// ); +// +// foreach ($defaults as $key => $default) { +// if (isset($file->$key) === false) { +// $file->$key = $default; +// } +// } return $file; From 39c6f061c6401c2179a45acb6264695ce279310c Mon Sep 17 00:00:00 2001 From: Ryan Price Date: Fri, 5 Aug 2016 11:32:11 -0700 Subject: [PATCH 07/10] last checkin was the wrong code --- .../Context/DrupalFileContext.php | 13 +++---- .../Context/SharedDrupalContext.php | 36 +++++++++---------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php index 556c1e3..674490f 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php @@ -32,15 +32,10 @@ public function createFile($filename, $status = 1) { throw new NotUpdatedException(); - $file = new File(array('filename' => $filename, 'status' => 1), 'file'); -// $file->setFilename($filename); -// $file->setPermanent(); -// $file->save(); - -// $file = (object) array( -// 'filename' => $filename, -// 'status' => $status, -// ); + $file = new File(array(), 'file'); + $file->setFilename($filename); + $file->setPermanent(); + // $file->save(); //needs to happen somewhere $file = $this->expandFile($file); diff --git a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php index 12ee730..f261c78 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php @@ -206,24 +206,24 @@ public function expandFile($file) $file->setFileUri(rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename()); // Assign authorship if none exists and `author` is passed. -// if (isset($file->getOwnerId()) === false && empty($file->author) === false) { -// $account = user_load_by_name($file->author); -// if ($account !== false) { -// $file->uid = $account->uid; -// } -// } - - // Add default values. -// $defaults = array( -// 'uid' => 0, -// 'status' => 1, -// ); -// -// foreach ($defaults as $key => $default) { -// if (isset($file->$key) === false) { -// $file->$key = $default; -// } -// } + /* if (isset($file->getOwnerId()) === false && empty($file->author) === false) { + $account = user_load_by_name($file->author); + if ($account !== false) { + $file->uid = $account->uid; + } + } + + Add default values. + $defaults = array( + 'uid' => 0, + 'status' => 1, + ); + + foreach ($defaults as $key => $default) { + if (isset($file->$key) === false) { + $file->$key = $default; + } + } */ return $file; From b9fadd480cbfd4bec53a5ace6e81e6f74ad22428 Mon Sep 17 00:00:00 2001 From: Ryan Price Date: Fri, 5 Aug 2016 11:36:22 -0700 Subject: [PATCH 08/10] formatting makes the linter happy --- .../PalantirBehatExtension/Context/DrupalFileContext.php | 4 +++- .../PalantirBehatExtension/Context/SharedDrupalContext.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php index 674490f..3b30166 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php @@ -35,7 +35,9 @@ public function createFile($filename, $status = 1) $file = new File(array(), 'file'); $file->setFilename($filename); $file->setPermanent(); - // $file->save(); //needs to happen somewhere + /* + $file->save(); //needs to happen somewhere + */ $file = $this->expandFile($file); diff --git a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php index f261c78..c29a27f 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/SharedDrupalContext.php @@ -206,7 +206,8 @@ public function expandFile($file) $file->setFileUri(rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename()); // Assign authorship if none exists and `author` is passed. - /* if (isset($file->getOwnerId()) === false && empty($file->author) === false) { + /* + if (isset($file->getOwnerId()) === false && empty($file->author) === false) { $account = user_load_by_name($file->author); if ($account !== false) { $file->uid = $account->uid; From a9bfcaaed75c5335a58a5727c666583119a84411 Mon Sep 17 00:00:00 2001 From: Ryan Price Date: Sat, 6 Aug 2016 14:32:41 -0700 Subject: [PATCH 09/10] 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) { From d51d72911404fda18cbf9b14cdbc507edcc6162a Mon Sep 17 00:00:00 2001 From: Andrea R Soper Date: Sun, 7 Aug 2016 18:04:07 -0500 Subject: [PATCH 10/10] Simplify status conditional and use FILE_STATUS_PERMANENT. --- .../Context/DrupalFileContext.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php index c6a3dbf..98ebdac 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalFileContext.php @@ -24,21 +24,16 @@ class DrupalFileContext extends SharedDrupalContext * @Given the file :filename * * @param string $filename The name of a file within the MinkExtension's files_path directory. - * @param int $status 1 if the file is permanent and should not be deleted; 0 if the file is temporary. Defaults to 1. + * @param int $status FILE_STATUS_PERMANENT or 0 if the file is temporary. Defaults to FILE_STATUS_PERMANENT. * * @return void */ - public function createFile($filename, $status = 1) + public function createFile($filename, $status = FILE_STATUS_PERMANENT) { $file = new File(array(), 'file'); $file->setFilename($filename); - if($status) { - $file->setPermanent(); - } - else { - $file->setTemporary(); - } + $file->set('status', $status); $file = $this->expandFile($file); @@ -68,12 +63,10 @@ public function createFiles(TableNode $filesTable) foreach ($filesTable->getHash() as $fileHash) { $file = new File(array(), 'file'); $file->setFilename($fileHash['filename']); - if($fileHash['status']) { - $file->setPermanent(); - } - else { - $file->setTemporary(); - } + + $status = isset($fileHash['status']) ?: FILE_STATUS_PERMANENT; + $file->set('status', $status); + $file = $this->expandFile($file); $this->fileCreate($file);