From c729d48ddf1936d25a7d693463ace6ff20492a0e Mon Sep 17 00:00:00 2001 From: pheadeaux Date: Thu, 3 Dec 2015 18:27:07 +0100 Subject: [PATCH] added tests for replacing on image directly --- src/Tests/FileEntityReplaceTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Tests/FileEntityReplaceTest.php b/src/Tests/FileEntityReplaceTest.php index 4cf4531..302c970 100644 --- a/src/Tests/FileEntityReplaceTest.php +++ b/src/Tests/FileEntityReplaceTest.php @@ -97,6 +97,33 @@ public function testReplaceFile() { // Test that Upload widget does not appear for non-local file. $this->drupalGet('file/' . $file2->id() . '/edit'); $this->assertNoFieldByName('files[replace_upload]'); + } + + public function testReplaceImageFile() { + // Select the first image test file to use. + $original = $this->files['image'][1]; + $this->assertEqual($original->getFilename(), 'image-test-transparent-indexed.gif'); + + // Create a user with file edit permissions. + $user = $this->drupalCreateUser(array('bypass file access')); + $this->drupalLogin($user); + + // Get the next text file to use as a replacement. + $replacement = $this->files['image'][4]; + $this->assertEqual($replacement->getFilename(), 'image-test-no-transparency.gif'); + + // Test that the file saves when uploading a replacement file. + $edit = array(); + $edit['files[replace_upload]'] = drupal_realpath($replacement->getFileUri()); + $this->drupalPostForm('file/' . $original->id() . '/edit', $edit, t('Save')); + $this->assertText(t('@file has been updated.', array('@file' => $original->getFilename()))/*, 'File was updated with file upload.'*/); + + // Re-load the file from the database. + /** @var \Drupal\file\FileInterface $file */ + $file = File::load($original->id()); + // Test how file properties changed after the file has been replaced. + $this->assertNotEqual($file->getSize(), $original->getSize(), 'Updated file size changed from previous file.'); + $this->assertEqual($file->getSize(), $replacement->getSize(), 'Updated file size does match the new file.'); } }