Commit 65873ade authored by catch's avatar catch
Browse files

Issue #3204163 by jonathanshaw: EntityQuery accessCheck: tests should not...

Issue #3204163 by jonathanshaw: EntityQuery accessCheck: tests should not check access unless relevant
parent 3f057d61
...@@ -25,7 +25,10 @@ public function testCron() { ...@@ -25,7 +25,10 @@ public function testCron() {
// Create feed and test basic updating on cron. // Create feed and test basic updating on cron.
$this->createSampleNodes(); $this->createSampleNodes();
$feed = $this->createFeed(); $feed = $this->createFeed();
$count_query = \Drupal::entityQuery('aggregator_item')->condition('fid', $feed->id())->count(); $count_query = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('fid', $feed->id())
->count();
$this->cronRun(); $this->cronRun();
$this->assertEqual(5, $count_query->execute()); $this->assertEqual(5, $count_query->execute());
......
...@@ -80,7 +80,11 @@ public function createFeed($feed_url = NULL, array $edit = []) { ...@@ -80,7 +80,11 @@ public function createFeed($feed_url = NULL, array $edit = []) {
// Verify that the creation message contains a link to a feed. // Verify that the creation message contains a link to a feed.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]'); $this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
$fids = \Drupal::entityQuery('aggregator_feed')->condition('title', $edit['title[0][value]'])->condition('url', $edit['url[0][value]'])->execute(); $fids = \Drupal::entityQuery('aggregator_feed')
->accessCheck(FALSE)
->condition('title', $edit['title[0][value]'])
->condition('url', $edit['url[0][value]'])
->execute();
$this->assertNotEmpty($fids, 'The feed found in database.'); $this->assertNotEmpty($fids, 'The feed found in database.');
return Feed::load(array_values($fids)[0]); return Feed::load(array_values($fids)[0]);
} }
...@@ -195,7 +199,10 @@ public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) { ...@@ -195,7 +199,10 @@ public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
$this->clickLink('Update items'); $this->clickLink('Update items');
// Ensure we have the right number of items. // Ensure we have the right number of items.
$item_ids = \Drupal::entityQuery('aggregator_item')->condition('fid', $feed->id())->execute(); $item_ids = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('fid', $feed->id())
->execute();
$feed->items = array_values($item_ids); $feed->items = array_values($item_ids);
if ($expected_count !== NULL) { if ($expected_count !== NULL) {
...@@ -224,7 +231,10 @@ public function deleteFeedItems(FeedInterface $feed) { ...@@ -224,7 +231,10 @@ public function deleteFeedItems(FeedInterface $feed) {
* Expected number of feed items. * Expected number of feed items.
*/ */
public function updateAndDelete(FeedInterface $feed, $expected_count) { public function updateAndDelete(FeedInterface $feed, $expected_count) {
$count_query = \Drupal::entityQuery('aggregator_item')->condition('fid', $feed->id())->count(); $count_query = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('fid', $feed->id())
->count();
$this->updateFeedItems($feed, $expected_count); $this->updateFeedItems($feed, $expected_count);
$count = $count_query->execute(); $count = $count_query->execute();
$this->assertGreaterThan(0, $count); $this->assertGreaterThan(0, $count);
...@@ -245,7 +255,12 @@ public function updateAndDelete(FeedInterface $feed, $expected_count) { ...@@ -245,7 +255,12 @@ public function updateAndDelete(FeedInterface $feed, $expected_count) {
* TRUE if feed is unique. * TRUE if feed is unique.
*/ */
public function uniqueFeed($feed_name, $feed_url) { public function uniqueFeed($feed_name, $feed_url) {
$result = \Drupal::entityQuery('aggregator_feed')->condition('title', $feed_name)->condition('url', $feed_url)->count()->execute(); $result = \Drupal::entityQuery('aggregator_feed')
->accessCheck(FALSE)
->condition('title', $feed_name)
->condition('url', $feed_url)
->count()
->execute();
return (1 == $result); return (1 == $result);
} }
......
...@@ -48,7 +48,12 @@ public function testDeleteFeed() { ...@@ -48,7 +48,12 @@ public function testDeleteFeed() {
$this->assertSession()->statusCodeEquals(404); $this->assertSession()->statusCodeEquals(404);
// Check database for feed. // Check database for feed.
$result = \Drupal::entityQuery('aggregator_feed')->condition('title', $feed1->label())->condition('url', $feed1->getUrl())->count()->execute(); $result = \Drupal::entityQuery('aggregator_feed')
->accessCheck(FALSE)
->condition('title', $feed1->label())
->condition('url', $feed1->getUrl())
->count()
->execute();
$this->assertEquals(0, $result, 'Feed not found in database'); $this->assertEquals(0, $result, 'Feed not found in database');
} }
......
...@@ -64,7 +64,10 @@ public function testAtomSample() { ...@@ -64,7 +64,10 @@ public function testAtomSample() {
$this->assertText('Atom-Powered Robots Run Amok'); $this->assertText('Atom-Powered Robots Run Amok');
$this->assertSession()->linkByHrefExists('http://example.org/2003/12/13/atom03'); $this->assertSession()->linkByHrefExists('http://example.org/2003/12/13/atom03');
$this->assertText('Some text.'); $this->assertText('Some text.');
$item_ids = \Drupal::entityQuery('aggregator_item')->condition('link', 'http://example.org/2003/12/13/atom03')->execute(); $item_ids = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('link', 'http://example.org/2003/12/13/atom03')
->execute();
$item = Item::load(array_values($item_ids)[0]); $item = Item::load(array_values($item_ids)[0]);
$this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.'); $this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.');
...@@ -72,7 +75,10 @@ public function testAtomSample() { ...@@ -72,7 +75,10 @@ public function testAtomSample() {
$this->assertText('We tried to stop them, but we failed.'); $this->assertText('We tried to stop them, but we failed.');
$this->assertSession()->linkByHrefExists('http://example.org/2003/12/14/atom03'); $this->assertSession()->linkByHrefExists('http://example.org/2003/12/14/atom03');
$this->assertText('Some other text.'); $this->assertText('Some other text.');
$item_ids = \Drupal::entityQuery('aggregator_item')->condition('link', 'http://example.org/2003/12/14/atom03')->execute(); $item_ids = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('link', 'http://example.org/2003/12/14/atom03')
->execute();
$item = Item::load(array_values($item_ids)[0]); $item = Item::load(array_values($item_ids)[0]);
$this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.'); $this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a', $item->getGuid(), 'Atom entry id element is parsed correctly.');
} }
......
...@@ -57,7 +57,7 @@ public function openImportForm() { ...@@ -57,7 +57,7 @@ public function openImportForm() {
* Submits form filled with invalid fields. * Submits form filled with invalid fields.
*/ */
public function validateImportFormFields() { public function validateImportFormFields() {
$count_query = \Drupal::entityQuery('aggregator_feed')->count(); $count_query = \Drupal::entityQuery('aggregator_feed')->accessCheck(FALSE)->count();
$before = $count_query->execute(); $before = $count_query->execute();
$edit = []; $edit = [];
...@@ -85,7 +85,7 @@ public function validateImportFormFields() { ...@@ -85,7 +85,7 @@ public function validateImportFormFields() {
* Submits form with invalid, empty, and valid OPML files. * Submits form with invalid, empty, and valid OPML files.
*/ */
protected function submitImportForm() { protected function submitImportForm() {
$count_query = \Drupal::entityQuery('aggregator_feed')->count(); $count_query = \Drupal::entityQuery('aggregator_feed')->accessCheck(FALSE)->count();
$before = $count_query->execute(); $before = $count_query->execute();
// Attempting to upload invalid XML. // Attempting to upload invalid XML.
......
...@@ -49,11 +49,17 @@ public function testUpdateFeedItem() { ...@@ -49,11 +49,17 @@ public function testUpdateFeedItem() {
// Verify that the creation message contains a link to a feed. // Verify that the creation message contains a link to a feed.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]'); $this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
$fids = \Drupal::entityQuery('aggregator_feed')->condition('url', $edit['url[0][value]'])->execute(); $fids = \Drupal::entityQuery('aggregator_feed')
->accessCheck(FALSE)
->condition('url', $edit['url[0][value]'])
->execute();
$feed = Feed::load(array_values($fids)[0]); $feed = Feed::load(array_values($fids)[0]);
$feed->refreshItems(); $feed->refreshItems();
$item_ids = \Drupal::entityQuery('aggregator_item')->condition('fid', $feed->id())->execute(); $item_ids = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('fid', $feed->id())
->execute();
$before = Item::load(array_values($item_ids)[0])->getPostedTime(); $before = Item::load(array_values($item_ids)[0])->getPostedTime();
// Sleep for 3 second. // Sleep for 3 second.
......
...@@ -37,7 +37,10 @@ protected function setUp(): void { ...@@ -37,7 +37,10 @@ protected function setUp(): void {
*/ */
public function testImport() { public function testImport() {
// Custom block ID must be a number that is not in the database. // Custom block ID must be a number that is not in the database.
$max_id = (int) \Drupal::entityQueryAggregate('block_content')->aggregate('id', 'max')->execute()[0]['id_max']; $max_id = (int) \Drupal::entityQueryAggregate('block_content')
->accessCheck(FALSE)
->aggregate('id', 'max')
->execute()[0]['id_max'];
$test_id = $max_id + mt_rand(1000, 1000000); $test_id = $max_id + mt_rand(1000, 1000000);
$info = $this->randomMachineName(8); $info = $this->randomMachineName(8);
$block_array = [ $block_array = [
......
...@@ -37,7 +37,10 @@ public function testPageEdit() { ...@@ -37,7 +37,10 @@ public function testPageEdit() {
$this->drupalPostForm('block/add/basic', $edit, 'Save'); $this->drupalPostForm('block/add/basic', $edit, 'Save');
// Check that the block exists in the database. // Check that the block exists in the database.
$blocks = \Drupal::entityQuery('block_content')->condition('info', $edit['info[0][value]'])->execute(); $blocks = \Drupal::entityQuery('block_content')
->accessCheck(FALSE)
->condition('info', $edit['info[0][value]'])
->execute();
$block = BlockContent::load(reset($blocks)); $block = BlockContent::load(reset($blocks));
$this->assertNotEmpty($block, 'Custom block found in database.'); $this->assertNotEmpty($block, 'Custom block found in database.');
......
...@@ -121,14 +121,20 @@ public function setUp(): void { ...@@ -121,14 +121,20 @@ public function setUp(): void {
*/ */
public function testQueriesNotAltered() { public function testQueriesNotAltered() {
// Ensure that queries without all the tags are not altered. // Ensure that queries without all the tags are not altered.
$query = $this->entityTypeManager->getStorage('block_content')->getQuery(); $query = $this->entityTypeManager->getStorage('block_content')
->getQuery()
->accessCheck(FALSE);
$this->assertCount(2, $query->execute()); $this->assertCount(2, $query->execute());
$query = $this->entityTypeManager->getStorage('block_content')->getQuery(); $query = $this->entityTypeManager->getStorage('block_content')
->getQuery()
->accessCheck(FALSE);
$query->addTag('block_content_access'); $query->addTag('block_content_access');
$this->assertCount(2, $query->execute()); $this->assertCount(2, $query->execute());
$query = $this->entityTypeManager->getStorage('block_content')->getQuery(); $query = $this->entityTypeManager->getStorage('block_content')
->getQuery()
->accessCheck(FALSE);
$query->addTag('entity_query_block_content'); $query->addTag('entity_query_block_content');
$this->assertCount(2, $query->execute()); $this->assertCount(2, $query->execute());
} }
......
...@@ -258,6 +258,7 @@ public function testCommentedTranslationDeletion() { ...@@ -258,6 +258,7 @@ public function testCommentedTranslationDeletion() {
$count_query = \Drupal::entityTypeManager() $count_query = \Drupal::entityTypeManager()
->getStorage('comment') ->getStorage('comment')
->getQuery() ->getQuery()
->accessCheck(FALSE)
->count(); ->count();
$before_count = $count_query->execute(); $before_count = $count_query->execute();
// Post 2 anonymous comments without contact info. // Post 2 anonymous comments without contact info.
......
...@@ -132,6 +132,7 @@ public function testCommentLanguage() { ...@@ -132,6 +132,7 @@ public function testCommentLanguage() {
// Check that comment language matches the current content language. // Check that comment language matches the current content language.
$cids = \Drupal::entityQuery('comment') $cids = \Drupal::entityQuery('comment')
->accessCheck(FALSE)
->condition('entity_id', $node->id()) ->condition('entity_id', $node->id())
->condition('entity_type', 'node') ->condition('entity_type', 'node')
->condition('field_name', 'comment') ->condition('field_name', 'comment')
......
...@@ -192,6 +192,7 @@ protected function getAllRevisionNames(EntityTestMulRevPub $entity) { ...@@ -192,6 +192,7 @@ protected function getAllRevisionNames(EntityTestMulRevPub $entity) {
return array_map(function ($revision_id) use ($storage) { return array_map(function ($revision_id) use ($storage) {
return $storage->loadRevision($revision_id)->name->value; return $storage->loadRevision($revision_id)->name->value;
}, array_keys($storage->getQuery() }, array_keys($storage->getQuery()
->accessCheck(FALSE)
->allRevisions() ->allRevisions()
->condition('id', $entity->id()) ->condition('id', $entity->id())
->sort('revision_id', 'ASC') ->sort('revision_id', 'ASC')
......
...@@ -127,7 +127,7 @@ public function testMultilingual() { ...@@ -127,7 +127,7 @@ public function testMultilingual() {
protected function assertModerationState($revision_id, $langcode, $expected_state, $expected_workflow = 'editorial') { protected function assertModerationState($revision_id, $langcode, $expected_state, $expected_workflow = 'editorial') {
$moderation_state_storage = $this->entityTypeManager->getStorage('content_moderation_state'); $moderation_state_storage = $this->entityTypeManager->getStorage('content_moderation_state');
$query = $moderation_state_storage->getQuery(); $query = $moderation_state_storage->getQuery()->accessCheck(FALSE);
$results = $query->allRevisions() $results = $query->allRevisions()
->condition('content_entity_revision_id', $revision_id) ->condition('content_entity_revision_id', $revision_id)
->condition('langcode', $langcode) ->condition('langcode', $langcode)
......
...@@ -111,7 +111,7 @@ public function testAutoCreate() { ...@@ -111,7 +111,7 @@ public function testAutoCreate() {
$new_title = $this->randomMachineName(); $new_title = $this->randomMachineName();
// Assert referenced node does not exist. // Assert referenced node does not exist.
$base_query = \Drupal::entityQuery('node'); $base_query = \Drupal::entityQuery('node')->accessCheck(FALSE);
$base_query $base_query
->condition('type', $this->referencedType) ->condition('type', $this->referencedType)
->condition('title', $new_title); ->condition('title', $new_title);
...@@ -135,6 +135,7 @@ public function testAutoCreate() { ...@@ -135,6 +135,7 @@ public function testAutoCreate() {
// Assert the referenced node is associated with referencing node. // Assert the referenced node is associated with referencing node.
$result = \Drupal::entityQuery('node') $result = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('type', $this->referencingType) ->condition('type', $this->referencingType)
->execute(); ->execute();
...@@ -270,6 +271,7 @@ public function testNoBundles() { ...@@ -270,6 +271,7 @@ public function testNoBundles() {
// Assert referenced entity was created. // Assert referenced entity was created.
$result = \Drupal::entityQuery('entity_test_no_bundle_with_label') $result = \Drupal::entityQuery('entity_test_no_bundle_with_label')
->accessCheck(FALSE)
->condition('name', $name) ->condition('name', $name)
->execute(); ->execute();
$this->assertNotEmpty($result, 'Referenced entity was created.'); $this->assertNotEmpty($result, 'Referenced entity was created.');
...@@ -277,6 +279,7 @@ public function testNoBundles() { ...@@ -277,6 +279,7 @@ public function testNoBundles() {
// Assert the referenced entity is associated with referencing node. // Assert the referenced entity is associated with referencing node.
$result = \Drupal::entityQuery('node') $result = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('type', $this->referencingType) ->condition('type', $this->referencingType)
->execute(); ->execute();
$this->assertCount(1, $result); $this->assertCount(1, $result);
......
...@@ -168,6 +168,7 @@ public function testDeleteField() { ...@@ -168,6 +168,7 @@ public function testDeleteField() {
// There are 10 entities of this bundle. // There are 10 entities of this bundle.
$found = $storage $found = $storage
->getQuery() ->getQuery()
->accessCheck(FALSE)
->condition('type', $bundle) ->condition('type', $bundle)
->execute(); ->execute();
$this->assertCount(10, $found, 'Correct number of entities found before deleting'); $this->assertCount(10, $found, 'Correct number of entities found before deleting');
...@@ -197,6 +198,7 @@ public function testDeleteField() { ...@@ -197,6 +198,7 @@ public function testDeleteField() {
// There are 0 entities of this bundle with non-deleted data. // There are 0 entities of this bundle with non-deleted data.
$found = $storage $found = $storage
->getQuery() ->getQuery()
->accessCheck(FALSE)
->condition('type', $bundle) ->condition('type', $bundle)
->condition("$field_name.deleted", 0) ->condition("$field_name.deleted", 0)
->execute(); ->execute();
...@@ -206,6 +208,7 @@ public function testDeleteField() { ...@@ -206,6 +208,7 @@ public function testDeleteField() {
// their values are correct. // their values are correct.
$found = $storage $found = $storage
->getQuery() ->getQuery()
->accessCheck(FALSE)
->condition('type', $bundle) ->condition('type', $bundle)
->condition("$field_name.deleted", 1) ->condition("$field_name.deleted", 1)
->sort('id') ->sort('id')
...@@ -334,6 +337,7 @@ public function testPurgeField() { ...@@ -334,6 +337,7 @@ public function testPurgeField() {
// There are $count deleted entities left. // There are $count deleted entities left.
$found = \Drupal::entityQuery('entity_test') $found = \Drupal::entityQuery('entity_test')
->accessCheck(FALSE)
->condition('type', $bundle) ->condition('type', $bundle)
->condition($field_name . '.deleted', 1) ->condition($field_name . '.deleted', 1)
->execute(); ->execute();
......
...@@ -74,7 +74,10 @@ public function getTestFile($type_name, $size = NULL) { ...@@ -74,7 +74,10 @@ public function getTestFile($type_name, $size = NULL) {
* Retrieves the fid of the last inserted file. * Retrieves the fid of the last inserted file.
*/ */
public function getLastFileId() { public function getLastFileId() {
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; return (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->aggregate('fid', 'max')
->execute()[0]['fid_max'];
} }
/** /**
......
...@@ -76,7 +76,10 @@ protected function setUp(): void { ...@@ -76,7 +76,10 @@ protected function setUp(): void {
$this->phpfile = current($this->drupalGetTestFiles('php')); $this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertFileExists($this->phpfile->uri); $this->assertFileExists($this->phpfile->uri);
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->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');
...@@ -99,7 +102,10 @@ protected function setUp(): void { ...@@ -99,7 +102,10 @@ protected function setUp(): void {
* 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 = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $max_fid_after = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->aggregate('fid', 'max')
->execute()[0]['fid_max'];
// Verify that a new file was created. // Verify that a new file was created.
$this->assertGreaterThan($this->maxFidBefore, $max_fid_after); $this->assertGreaterThan($this->maxFidBefore, $max_fid_after);
$file1 = File::load($max_fid_after); $file1 = File::load($max_fid_after);
...@@ -118,7 +124,10 @@ public function testNormal() { ...@@ -118,7 +124,10 @@ public function testNormal() {
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, 'Submit'); $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, 'Submit');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertRaw(t('You WIN!')); $this->assertRaw(t('You WIN!'));
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $max_fid_after = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->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']);
......
...@@ -73,7 +73,10 @@ protected function setUp(): void { ...@@ -73,7 +73,10 @@ protected function setUp(): void {
$this->phpfile = current($this->drupalGetTestFiles('php')); $this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertFileExists($this->phpfile->uri); $this->assertFileExists($this->phpfile->uri);
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->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 = [
...@@ -95,7 +98,10 @@ protected function setUp(): void { ...@@ -95,7 +98,10 @@ protected function setUp(): void {
* Test the file_save_upload() function. * Test the file_save_upload() function.
*/ */
public function testNormal() { public function testNormal() {
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $max_fid_after = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->aggregate('fid', 'max')
->execute()[0]['fid_max'];
// Verify that a new file was created. // Verify that a new file was created.
$this->assertGreaterThan($this->maxFidBefore, $max_fid_after); $this->assertGreaterThan($this->maxFidBefore, $max_fid_after);
$file1 = File::load($max_fid_after); $file1 = File::load($max_fid_after);
...@@ -112,7 +118,10 @@ public function testNormal() { ...@@ -112,7 +118,10 @@ public function testNormal() {
$this->drupalPostForm('file-test/upload', $edit, 'Submit'); $this->drupalPostForm('file-test/upload', $edit, 'Submit');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertRaw(t('You WIN!')); $this->assertRaw(t('You WIN!'));
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']; $max_fid_after = (int) \Drupal::entityQueryAggregate('file')
->accessCheck(FALSE)
->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']);
...@@ -149,7 +158,10 @@ public function testDuplicate() { ...@@ -149,7 +158,10 @@ public function testDuplicate() {
$image1 = current($this->drupalGetTestFiles('image')); $image1 = current($this->drupalGetTestFiles('image'));
$edit = ['files[file_test_upload]' => \Drupal::service