Commit 5c3a1c67 authored by alexpott's avatar alexpott

Issue #2322509 by prics, cilefen, gaurav.goyal, harijari, Temoor: Replace all...

Issue #2322509 by prics, cilefen, gaurav.goyal, harijari, Temoor: Replace all instances of node_load(), node_load_multiple(), entity_load('node') and entity_load_multiple('node') with static method calls.
parent 92c25141
......@@ -37,7 +37,7 @@
* @code
* // Load a node and a user, then replace tokens in the text.
* $text = 'On [date:short], [user:name] read [node:title].';
* $node = node_load(1);
* $node = Node::load(1);
* $user = user_load(1);
*
* // [date:...] tokens use the current date automatically.
......
......@@ -29,6 +29,8 @@ class BulkFormTest extends WebTestBase {
* Tests the bulk form.
*/
public function testBulkForm() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// First, test an empty bulk form with the default style plugin to make sure
// the empty region is rendered correctly.
$this->drupalGet('test_bulk_form_empty');
......@@ -66,14 +68,14 @@ public function testBulkForm() {
$this->drupalPostForm(NULL, $edit, t('Apply'));
foreach ($nodes as $node) {
$changed_node = node_load($node->id());
$changed_node = $node_storage->load($node->id());
$this->assertTrue($changed_node->isSticky(), format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
}
$this->assertText('Make content sticky was applied to 10 items.');
// Unpublish just one node.
$node = node_load($nodes[0]->id());
$node = $node_storage->load($nodes[0]->id());
$this->assertTrue($node->isPublished(), 'The node is published.');
$edit = array('node_bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action');
......@@ -82,11 +84,13 @@ public function testBulkForm() {
$this->assertText('Unpublish content was applied to 1 item.');
// Load the node again.
$node = node_load($node->id(), TRUE);
$node_storage->resetCache(array($node->id()));
$node = $node_storage->load($node->id());
$this->assertFalse($node->isPublished(), 'A single node has been unpublished.');
// The second node should still be published.
$node = node_load($nodes[1]->id(), TRUE);
$node_storage->resetCache(array($nodes[1]->id()));
$node = $node_storage->load($nodes[1]->id());
$this->assertTrue($node->isPublished(), 'An unchecked node is still published.');
// Set up to include just the sticky actions.
......
......@@ -338,7 +338,7 @@ function book_node_prepare_form(NodeInterface $node, $operation, FormStateInterf
* @see node_delete_confirm()
*/
function book_form_node_delete_confirm_alter(&$form, FormStateInterface $form_state) {
$node = node_load($form['nid']['#value']);
$node = Node::load($form['nid']['#value']);
if (isset($node->book) && $node->book['has_children']) {
$form['book_warning'] = array(
......
......@@ -13,6 +13,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Entity\EntityStorageInterface;
/**
* Provides a 'Book navigation' block.
......@@ -39,6 +40,13 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
*/
protected $bookManager;
/**
* The node storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeStorage;
/**
* Constructs a new BookNavigationBlock instance.
*
......@@ -52,12 +60,15 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
* The request stack object.
* @param \Drupal\book\BookManagerInterface $book_manager
* The book manager.
* @param \Drupal\Core\Entity\EntityStorageInterface $node_storage
* The node storage.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, BookManagerInterface $book_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, BookManagerInterface $book_manager, EntityStorageInterface $node_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->requestStack = $request_stack;
$this->bookManager = $book_manager;
$this->nodeStorage = $node_storage;
}
/**
......@@ -69,7 +80,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('request_stack'),
$container->get('book.manager')
$container->get('book.manager'),
$container->get('entity.manager')->getStorage('node')
);
}
......@@ -132,7 +144,7 @@ public function build() {
// is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE;
// Check whether user can access the book link.
$book_node = node_load($book['nid']);
$book_node = $this->nodeStorage->load($book['nid']);
$book['access'] = $book_node->access('view');
$pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
......
......@@ -407,6 +407,7 @@ function testNavigationBlockOnAccessModuleEnabled() {
* Tests the access for deleting top-level book nodes.
*/
function testBookDelete() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$nodes = $this->createBook();
$this->drupalLogin($this->admin_user);
$edit = array();
......@@ -415,7 +416,8 @@ function testBookDelete() {
$this->drupalGet('node/' . $this->book->id() . '/outline/remove');
$this->assertResponse('403', 'Deleting top-level book node properly forbidden.');
$this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove'));
$node4 = node_load($nodes[4]->id(), TRUE);
$node_storage->resetCache(array($nodes[4]->id()));
$node4 = $node_storage->load($nodes[4]->id());
$this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.');
// Delete all child book nodes and retest top-level node deletion.
......@@ -424,7 +426,8 @@ function testBookDelete() {
}
entity_delete_multiple('node', $nids);
$this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove'));
$node = node_load($this->book->id(), TRUE);
$node_storage->resetCache(array($this->book->id()));
$node = $node_storage->load($this->book->id());
$this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
}
......
......@@ -12,6 +12,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -41,6 +42,13 @@ class CommentController extends ControllerBase {
*/
protected $commentManager;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityManager;
/**
* Constructs a CommentController object.
*
......@@ -48,10 +56,13 @@ class CommentController extends ControllerBase {
* HTTP kernel to handle requests.
* @param \Drupal\comment\CommentManagerInterface $comment_manager
* The comment manager service.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
*/
public function __construct(HttpKernelInterface $http_kernel, CommentManagerInterface $comment_manager) {
public function __construct(HttpKernelInterface $http_kernel, CommentManagerInterface $comment_manager, EntityManagerInterface $entity_manager) {
$this->httpKernel = $http_kernel;
$this->commentManager = $comment_manager;
$this->entityManager = $entity_manager;
}
/**
......@@ -60,7 +71,8 @@ public function __construct(HttpKernelInterface $http_kernel, CommentManagerInte
public static function create(ContainerInterface $container) {
return new static(
$container->get('http_kernel'),
$container->get('comment.manager')
$container->get('comment.manager'),
$container->get('entity.manager')
);
}
......@@ -285,7 +297,7 @@ public function renderNewCommentsNodeLinks(Request $request) {
$links = array();
foreach ($nids as $nid) {
$node = node_load($nid);
$node = $this->entityManager->getStorage('node')->load($nid);
$new = $this->commentManager->getCountNewComments($node);
$page_number = $this->entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node);
......
......@@ -9,6 +9,7 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\Component\Utility\String;
use Drupal\node\Entity\Node;
/**
* Tests paging of comments and their settings.
......@@ -240,7 +241,7 @@ function testCommentNewPageIndicator() {
6 => 0, // Page of comment 0
);
$node = node_load($node->id());
$node = Node::load($node->id());
foreach ($expected_pages as $new_replies => $expected_page) {
$returned_page = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node);
......@@ -259,7 +260,7 @@ function testCommentNewPageIndicator() {
);
\Drupal::entityManager()->getStorage('node')->resetCache(array($node->id()));
$node = node_load($node->id());
$node = Node::load($node->id());
foreach ($expected_pages as $new_replies => $expected_page) {
$returned_page = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node);
......
......@@ -36,6 +36,7 @@ protected function setUp() {
* Tests the node comment statistics.
*/
function testCommentNodeCommentStatistics() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Set comments to have subject and preview disabled.
$this->drupalLogin($this->admin_user);
$this->setCommentPreview(DRUPAL_DISABLED);
......@@ -45,7 +46,7 @@ function testCommentNodeCommentStatistics() {
$this->drupalLogout();
// Checks the initial values of node comment statistics with no comment.
$node = node_load($this->node->id());
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->last_comment_timestamp, $this->node->getCreatedTime(), 'The initial value of node last_comment_timestamp is the node created date.');
$this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
$this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user->id(), 'The initial value of node last_comment_uid is the node uid.');
......@@ -57,8 +58,9 @@ function testCommentNodeCommentStatistics() {
$this->postComment($this->node, $comment_text);
// Checks the new values of node comment statistics with comment #1.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->id(), TRUE);
// The node cache needs to be reset before reload.
$node_storage->resetCache(array($this->node->id()));
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
$this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is the comment #1 uid.');
$this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is 1.');
......@@ -80,8 +82,9 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #2 and
// ensure they haven't changed since the comment has not been moderated.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->id(), TRUE);
// The node needs to be reloaded with the cache reset.
$node_storage->resetCache(array($this->node->id()));
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
$this->assertEqual($node->get('comment')->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is still the comment #1 uid.');
$this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is still 1.');
......@@ -101,8 +104,9 @@ function testCommentNodeCommentStatistics() {
$comment_loaded = Comment::load($anonymous_comment->id());
// Checks the new values of node comment statistics with comment #3.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->id(), TRUE);
// The node needs to be reloaded with the cache reset.
$node_storage->resetCache(array($this->node->id()));
$node = $node_storage->load($this->node->id());
$this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->getAuthorName(), 'The value of node last_comment_name is the name of the anonymous user.');
$this->assertEqual($node->get('comment')->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
$this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.');
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
use Drupal\comment\Entity\Comment;
use Drupal\node\Entity\Node;
/**
* Generates text using placeholders for dummy content to check comment token
......@@ -101,7 +102,7 @@ function testCommentTokenReplacement() {
$this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input)));
// Load node so comment_count gets computed.
$node = node_load($node->id());
$node = Node::load($node->id());
// Generate comment tokens for the node (it has 2 comments, both new).
$tests = array();
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\Node;
/**
* Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget.
......@@ -103,7 +104,7 @@ public function testAutoCreate() {
$result = $query->execute();
$this->assertTrue($result, 'Referenced node was created.');
$referenced_nid = key($result);
$referenced_node = node_load($referenced_nid);
$referenced_node = Node::load($referenced_nid);
// Assert the referenced node is associated with referencing node.
$result = \Drupal::entityQuery('node')
......@@ -111,7 +112,7 @@ public function testAutoCreate() {
->execute();
$referencing_nid = key($result);
$referencing_node = node_load($referencing_nid);
$referencing_node = Node::load($referencing_nid);
$this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.');
// Now try to view the node and check that the referenced node is shown.
......
......@@ -54,7 +54,9 @@ function testNodeDisplay() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the default formatter is displaying with the file name.
$node = node_load($nid, TRUE);
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$file_link = array(
'#theme' => 'file_link',
......
......@@ -17,6 +17,7 @@ class FileFieldPathTest extends FileFieldTestBase {
* Tests the normal formatter display on node display.
*/
function testUploadPath() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$this->createFileField($field_name, 'node', $type_name);
......@@ -26,7 +27,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded to the file root.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
......@@ -37,7 +39,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id, TRUE);
$this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
......@@ -49,7 +52,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
// Do token replacement using the same user which uploaded the file, not
// the user running the test case.
......
......@@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\node\Entity\Node;
/**
* Ensure that files added to nodes appear correctly in RSS feeds.
*
......@@ -25,6 +27,7 @@ class FileFieldRSSContentTest extends FileFieldTestBase {
* Tests RSS enclosure formatter display for RSS feeds.
*/
function testFileFieldRSSContent() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$field_settings = array(
......@@ -58,7 +61,8 @@ function testFileFieldRSSContent() {
$nid = $this->uploadNodeFile($test_file, $field_name, $node->id());
// Get the uploaded file from the node.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
// Check that the RSS enclosure appears in the RSS feed.
......
......@@ -25,6 +25,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
* should be deleted also.
*/
function testRevisions() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name);
......@@ -37,7 +38,8 @@ function testRevisions() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file exists on disk and in the database.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file_r1 = file_load($node->{$field_name}->target_id);
$node_vid_r1 = $node->getRevisionId();
$this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.');
......@@ -46,7 +48,8 @@ function testRevisions() {
// Upload another file to the same node in a new revision.
$this->replaceNodeFile($test_file, $field_name, $nid);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file_r2 = file_load($node->{$field_name}->target_id);
$node_vid_r2 = $node->getRevisionId();
$this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.');
......@@ -64,7 +67,8 @@ function testRevisions() {
// Save a new version of the node without any changes.
// Check that the file is still the same as the previous revision.
$this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published'));
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file_r3 = file_load($node->{$field_name}->target_id);
$node_vid_r3 = $node->getRevisionId();
$this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.');
......@@ -72,7 +76,8 @@ function testRevisions() {
// Revert to the first revision and check that the original file is active.
$this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert'));
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file_r4 = file_load($node->{$field_name}->target_id);
$this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.');
$this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.');
......
......@@ -151,6 +151,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE,
$nid = $nid_or_type;
}
else {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Add a new node.
$extras['type'] = $nid_or_type;
$node = $this->drupalCreateNode($extras);
......@@ -158,7 +159,8 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE,
// Save at least one revision to better simulate a real site.
$node->setNewRevision();
$node->save();
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$this->assertNotEqual($nid, $node->getRevisionId(), 'Node revision exists.');
}
......
......@@ -24,6 +24,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
* Tests the required property on file fields.
*/
function testRequired() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$storage = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1'));
......@@ -41,7 +42,8 @@ function testRequired() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name)));
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading to the required field.');
......@@ -59,7 +61,8 @@ function testRequired() {
// Create a new node with the uploaded file into the multivalue field.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.');
$this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.');
......@@ -69,6 +72,7 @@ function testRequired() {
* Tests the max file size validator.
*/
function testFileMaxSize() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1'));
......@@ -89,7 +93,8 @@ function testFileMaxSize() {
// Create a new node with the small file, which should pass.
$nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize)));
$this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize)));
......@@ -105,7 +110,8 @@ function testFileMaxSize() {
// Upload the big file successfully.
$nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize()))));
$this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize()))));
......@@ -115,6 +121,7 @@ function testFileMaxSize() {
* Tests file extension checking.
*/
function testFileExtension() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name);
......@@ -127,7 +134,8 @@ function testFileExtension() {
// Check that the file can be uploaded with no extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.');
$this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.');
......@@ -145,7 +153,8 @@ function testFileExtension() {
// Check that the file can be uploaded with extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.');
$this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.');
......
......@@ -29,6 +29,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
* Tests upload and remove buttons for a single-valued File field.
*/
function testSingleValuedWidget() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name);
......@@ -41,7 +42,8 @@ function testSingleValuedWidget() {
// @todo This only tests a 'nojs' submission, because drupalPostAjaxForm()
// does not yet support file uploads.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'New file saved to disk on node creation.');
......@@ -74,7 +76,8 @@ function testSingleValuedWidget() {
// Save the node and ensure it does not have the file.
$this->drupalPostForm(NULL, array(), t('Save and keep published'));
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.');
}
}
......@@ -83,6 +86,7 @@ function testSingleValuedWidget() {
* Tests upload and remove buttons for multiple multi-valued File fields.
*/
function testMultiValuedWidget() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
// Use explicit names instead of random names for those fields, because of a
// bug in drupalPostForm() with multiple file uploads in one form, where the
......@@ -191,7 +195,8 @@ function testMultiValuedWidget() {
$matches = array();
preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches);
$nid = $matches[1];
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$this->assertTrue(empty($node->{$field_name}->target_id), 'Node was successfully saved without any files.');
}
}
......@@ -200,6 +205,7 @@ function testMultiValuedWidget() {
* Tests a file field with a "Private files" upload destination setting.
*/
function testPrivateFileSetting() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Grant the admin user required permissions.
user_role_grant_permissions($this->admin_user->roles[0]->target_id, array('administer node fields'));
......@@ -214,7 +220,8 @@ function testPrivateFileSetting() {
$edit = array('field_storage[settings][uri_scheme]' => 'private');
$this->drupalPostForm("admin/structure/types/manage/$type_name/fields/$field->id/storage", $edit, t('Save field settings'));
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'New file saved to disk on node creation.');
......
......@@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\node\Entity\Node;
/**
* Tests file listing page functionality.
*
......@@ -88,7 +90,7 @@ function testFileListingPages() {
'files[file_0]' => drupal_realpath($file->getFileUri()),
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$node = entity_load('node', $node->id());
$node = Node::load($node->id());
}
$this->drupalGet('admin/content/files');
......
......@@ -10,7 +10,6 @@
use Drupal\Core\Entity\Plugin\Validation\Constraint\ReferenceAccessConstraint;
use Drupal\Component\Utility\String;
use Drupal\file\Entity\File;
use Drupal\node\Entity\Node;
/**
* Uploads a test to a private node and checks access.
......@@ -37,6 +36,7 @@ protected function setUp() {
* Tests file access for file uploaded to a private node.
*/
function testPrivateFile() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private'));
......@@ -44,7 +44,7 @@ function testPrivateFile() {
$test_file = $this->getTestFile('text');
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE));
\Drupal::entityManager()->getStorage('node')->resetCache(array($nid));
$node = Node::load($nid);;
$node = $node_storage->load($nid);
$node_file = File::load($node->{$field_name}->target_id);
// Ensure the file can be viewed.
$this->drupalGet('node/' . $node->id());
......@@ -64,7 +64,7 @@ function testPrivateFile() {
$this->drupalLogin($this->admin_user);
$nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE));
\Drupal::entityManager()->getStorage('node')->resetCache(array($nid));
$node = Node::load($nid);
$node = $node_storage->load($nid);
$node_file = File::load($node->{$no_access_field_name}->target_id);
// Ensure the file cannot be downloaded.
......
......@@ -20,6 +20,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
* Creates a file, then tests the tokens generated from it.
*/
function testFileTokenReplacement() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$token_service = \Drupal::token();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
......@@ -37,7 +38,8 @@ function testFileTokenReplacement() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Load the node and the file.
$node = node_load($nid, TRUE);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$file = file_load($node->{$field_name}->target_id);
// Generate and test sanitized tokens.
......