Issue #3014950 by goodboy, mondrake, alexpott: Replace all db calls to file_managed table with Entity APIs
parent
d7999461e7
commit
c503bb6a93
|
|
@ -59,7 +59,7 @@ abstract class FileFieldTestBase extends WebTestBase {
|
||||||
* Retrieves the fid of the last inserted file.
|
* Retrieves the fid of the last inserted file.
|
||||||
*/
|
*/
|
||||||
public function getLastFileId() {
|
public function getLastFileId() {
|
||||||
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,8 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
||||||
|
|
||||||
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
||||||
// of the file is older than the system.file.temporary_maximum_age
|
// of the file is older than the system.file.temporary_maximum_age
|
||||||
// configuration value.
|
// configuration value. We use an UPDATE statement because using the API
|
||||||
|
// would set the timestamp.
|
||||||
$connection = Database::getConnection();
|
$connection = Database::getConnection();
|
||||||
$connection->update('file_managed')
|
$connection->update('file_managed')
|
||||||
->fields([
|
->fields([
|
||||||
|
|
@ -135,7 +136,8 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
||||||
$this->drupalPostForm('node/' . $nid . '/delete', [], t('Delete'));
|
$this->drupalPostForm('node/' . $nid . '/delete', [], t('Delete'));
|
||||||
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
||||||
// of the file is older than the system.file.temporary_maximum_age
|
// of the file is older than the system.file.temporary_maximum_age
|
||||||
// configuration value.
|
// configuration value. We use an UPDATE statement because using the API
|
||||||
|
// would set the timestamp.
|
||||||
$connection->update('file_managed')
|
$connection->update('file_managed')
|
||||||
->fields([
|
->fields([
|
||||||
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ abstract class FileFieldTestBase extends BrowserTestBase {
|
||||||
* Retrieves the fid of the last inserted file.
|
* Retrieves the fid of the last inserted file.
|
||||||
*/
|
*/
|
||||||
public function getLastFileId() {
|
public function getLastFileId() {
|
||||||
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class SaveUploadFormTest extends FileManagedTestBase {
|
||||||
$this->phpfile = current($this->drupalGetTestFiles('php'));
|
$this->phpfile = current($this->drupalGetTestFiles('php'));
|
||||||
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
|
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
|
||||||
|
|
||||||
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
|
|
||||||
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
|
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
|
||||||
$file_system = \Drupal::service('file_system');
|
$file_system = \Drupal::service('file_system');
|
||||||
|
|
@ -89,7 +89,7 @@ class SaveUploadFormTest extends FileManagedTestBase {
|
||||||
* Tests the _file_save_upload_from_form() function.
|
* Tests the _file_save_upload_from_form() function.
|
||||||
*/
|
*/
|
||||||
public function testNormal() {
|
public function testNormal() {
|
||||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
|
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
|
||||||
$file1 = File::load($max_fid_after);
|
$file1 = File::load($max_fid_after);
|
||||||
$this->assertTrue($file1, 'Loaded the file.');
|
$this->assertTrue($file1, 'Loaded the file.');
|
||||||
|
|
@ -107,7 +107,7 @@ class SaveUploadFormTest extends FileManagedTestBase {
|
||||||
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
|
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
|
||||||
$this->assertResponse(200, 'Received a 200 response for posted test file.');
|
$this->assertResponse(200, 'Received a 200 response for posted test file.');
|
||||||
$this->assertRaw(t('You WIN!'));
|
$this->assertRaw(t('You WIN!'));
|
||||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
|
|
||||||
// Check that the correct hooks were called.
|
// Check that the correct hooks were called.
|
||||||
$this->assertFileHooksCalled(['validate', 'insert']);
|
$this->assertFileHooksCalled(['validate', 'insert']);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class SaveUploadTest extends FileManagedTestBase {
|
||||||
$this->phpfile = current($this->drupalGetTestFiles('php'));
|
$this->phpfile = current($this->drupalGetTestFiles('php'));
|
||||||
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
|
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
|
||||||
|
|
||||||
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
|
|
||||||
// Upload with replace to guarantee there's something there.
|
// Upload with replace to guarantee there's something there.
|
||||||
$edit = [
|
$edit = [
|
||||||
|
|
@ -82,7 +82,7 @@ class SaveUploadTest extends FileManagedTestBase {
|
||||||
* Test the file_save_upload() function.
|
* Test the file_save_upload() function.
|
||||||
*/
|
*/
|
||||||
public function testNormal() {
|
public function testNormal() {
|
||||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
|
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
|
||||||
$file1 = File::load($max_fid_after);
|
$file1 = File::load($max_fid_after);
|
||||||
$this->assertTrue($file1, 'Loaded the file.');
|
$this->assertTrue($file1, 'Loaded the file.');
|
||||||
|
|
@ -98,7 +98,7 @@ class SaveUploadTest extends FileManagedTestBase {
|
||||||
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
|
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
|
||||||
$this->assertResponse(200, 'Received a 200 response for posted test file.');
|
$this->assertResponse(200, 'Received a 200 response for posted test file.');
|
||||||
$this->assertRaw(t('You WIN!'));
|
$this->assertRaw(t('You WIN!'));
|
||||||
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
|
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
|
|
||||||
// Check that the correct hooks were called.
|
// Check that the correct hooks were called.
|
||||||
$this->assertFileHooksCalled(['validate', 'insert']);
|
$this->assertFileHooksCalled(['validate', 'insert']);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Drupal\Tests\file\FunctionalJavascript;
|
namespace Drupal\Tests\file\FunctionalJavascript;
|
||||||
|
|
||||||
use Drupal\Core\Database\Database;
|
|
||||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,7 +94,7 @@ class FileManagedFileElementTest extends WebDriverTestBase {
|
||||||
* Retrieves the fid of the last inserted file.
|
* Retrieves the fid of the last inserted file.
|
||||||
*/
|
*/
|
||||||
protected function getLastFileId() {
|
protected function getLastFileId() {
|
||||||
return (int) Database::getConnection()->query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,8 @@ class DeleteTest extends FileManagedUnitTestBase {
|
||||||
|
|
||||||
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
// Call file_cron() to clean up the file. Make sure the changed timestamp
|
||||||
// of the file is older than the system.file.temporary_maximum_age
|
// of the file is older than the system.file.temporary_maximum_age
|
||||||
// configuration value.
|
// configuration value. We use an UPDATE statement because using the API
|
||||||
|
// would set the timestamp.
|
||||||
Database::getConnection()->update('file_managed')
|
Database::getConnection()->update('file_managed')
|
||||||
->fields([
|
->fields([
|
||||||
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ abstract class ImageFieldTestBase extends WebTestBase {
|
||||||
* Retrieves the fid of the last inserted file.
|
* Retrieves the fid of the last inserted file.
|
||||||
*/
|
*/
|
||||||
protected function getLastFileId() {
|
protected function getLastFileId() {
|
||||||
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ abstract class ImageFieldTestBase extends BrowserTestBase {
|
||||||
* Retrieves the fid of the last inserted file.
|
* Retrieves the fid of the last inserted file.
|
||||||
*/
|
*/
|
||||||
protected function getLastFileId() {
|
protected function getLastFileId() {
|
||||||
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,8 @@ class UserPictureTest extends BrowserTestBase {
|
||||||
|
|
||||||
// Call file_cron() to clean up the file. Make sure the timestamp
|
// Call file_cron() to clean up the file. Make sure the timestamp
|
||||||
// of the file is older than the system.file.temporary_maximum_age
|
// of the file is older than the system.file.temporary_maximum_age
|
||||||
// configuration value.
|
// configuration value. We use an UPDATE statement because using the API
|
||||||
|
// would set the timestamp.
|
||||||
Database::getConnection()->update('file_managed')
|
Database::getConnection()->update('file_managed')
|
||||||
->fields([
|
->fields([
|
||||||
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue