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 @@ ...@@ -37,7 +37,7 @@
* @code * @code
* // Load a node and a user, then replace tokens in the text. * // Load a node and a user, then replace tokens in the text.
* $text = 'On [date:short], [user:name] read [node:title].'; * $text = 'On [date:short], [user:name] read [node:title].';
* $node = node_load(1); * $node = Node::load(1);
* $user = user_load(1); * $user = user_load(1);
* *
* // [date:...] tokens use the current date automatically. * // [date:...] tokens use the current date automatically.
......
...@@ -29,6 +29,8 @@ class BulkFormTest extends WebTestBase { ...@@ -29,6 +29,8 @@ class BulkFormTest extends WebTestBase {
* Tests the bulk form. * Tests the bulk form.
*/ */
public function testBulkForm() { 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 // First, test an empty bulk form with the default style plugin to make sure
// the empty region is rendered correctly. // the empty region is rendered correctly.
$this->drupalGet('test_bulk_form_empty'); $this->drupalGet('test_bulk_form_empty');
...@@ -66,14 +68,14 @@ public function testBulkForm() { ...@@ -66,14 +68,14 @@ public function testBulkForm() {
$this->drupalPostForm(NULL, $edit, t('Apply')); $this->drupalPostForm(NULL, $edit, t('Apply'));
foreach ($nodes as $node) { 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->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.'); $this->assertText('Make content sticky was applied to 10 items.');
// Unpublish just one node. // 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.'); $this->assertTrue($node->isPublished(), 'The node is published.');
$edit = array('node_bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action'); $edit = array('node_bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action');
...@@ -82,11 +84,13 @@ public function testBulkForm() { ...@@ -82,11 +84,13 @@ public function testBulkForm() {
$this->assertText('Unpublish content was applied to 1 item.'); $this->assertText('Unpublish content was applied to 1 item.');
// Load the node again. // 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.'); $this->assertFalse($node->isPublished(), 'A single node has been unpublished.');
// The second node should still be published. // 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.'); $this->assertTrue($node->isPublished(), 'An unchecked node is still published.');
// Set up to include just the sticky actions. // Set up to include just the sticky actions.
......
...@@ -338,7 +338,7 @@ function book_node_prepare_form(NodeInterface $node, $operation, FormStateInterf ...@@ -338,7 +338,7 @@ function book_node_prepare_form(NodeInterface $node, $operation, FormStateInterf
* @see node_delete_confirm() * @see node_delete_confirm()
*/ */
function book_form_node_delete_confirm_alter(&$form, FormStateInterface $form_state) { 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']) { if (isset($node->book) && $node->book['has_children']) {
$form['book_warning'] = array( $form['book_warning'] = array(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Entity\EntityStorageInterface;
/** /**
* Provides a 'Book navigation' block. * Provides a 'Book navigation' block.
...@@ -39,6 +40,13 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt ...@@ -39,6 +40,13 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
*/ */
protected $bookManager; protected $bookManager;
/**
* The node storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeStorage;
/** /**
* Constructs a new BookNavigationBlock instance. * Constructs a new BookNavigationBlock instance.
* *
...@@ -52,12 +60,15 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt ...@@ -52,12 +60,15 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
* The request stack object. * The request stack object.
* @param \Drupal\book\BookManagerInterface $book_manager * @param \Drupal\book\BookManagerInterface $book_manager
* The 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); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->requestStack = $request_stack; $this->requestStack = $request_stack;
$this->bookManager = $book_manager; $this->bookManager = $book_manager;
$this->nodeStorage = $node_storage;
} }
/** /**
...@@ -69,7 +80,8 @@ public static function create(ContainerInterface $container, array $configuratio ...@@ -69,7 +80,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('request_stack'), $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() { ...@@ -132,7 +144,7 @@ public function build() {
// is no reason to run an additional menu tree query for each book. // is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE; $book['in_active_trail'] = FALSE;
// Check whether user can access the book link. // 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'); $book['access'] = $book_node->access('view');
$pseudo_tree[0]['link'] = $book; $pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree); $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
......
...@@ -407,6 +407,7 @@ function testNavigationBlockOnAccessModuleEnabled() { ...@@ -407,6 +407,7 @@ function testNavigationBlockOnAccessModuleEnabled() {
* Tests the access for deleting top-level book nodes. * Tests the access for deleting top-level book nodes.
*/ */
function testBookDelete() { function testBookDelete() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$nodes = $this->createBook(); $nodes = $this->createBook();
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
$edit = array(); $edit = array();
...@@ -415,7 +416,8 @@ function testBookDelete() { ...@@ -415,7 +416,8 @@ function testBookDelete() {
$this->drupalGet('node/' . $this->book->id() . '/outline/remove'); $this->drupalGet('node/' . $this->book->id() . '/outline/remove');
$this->assertResponse('403', 'Deleting top-level book node properly forbidden.'); $this->assertResponse('403', 'Deleting top-level book node properly forbidden.');
$this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove')); $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.'); $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.');
// Delete all child book nodes and retest top-level node deletion. // Delete all child book nodes and retest top-level node deletion.
...@@ -424,7 +426,8 @@ function testBookDelete() { ...@@ -424,7 +426,8 @@ function testBookDelete() {
} }
entity_delete_multiple('node', $nids); entity_delete_multiple('node', $nids);
$this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove')); $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.'); $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
...@@ -41,6 +42,13 @@ class CommentController extends ControllerBase { ...@@ -41,6 +42,13 @@ class CommentController extends ControllerBase {
*/ */
protected $commentManager; protected $commentManager;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityManager;
/** /**
* Constructs a CommentController object. * Constructs a CommentController object.
* *
...@@ -48,10 +56,13 @@ class CommentController extends ControllerBase { ...@@ -48,10 +56,13 @@ class CommentController extends ControllerBase {
* HTTP kernel to handle requests. * HTTP kernel to handle requests.
* @param \Drupal\comment\CommentManagerInterface $comment_manager * @param \Drupal\comment\CommentManagerInterface $comment_manager
* The comment manager service. * 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->httpKernel = $http_kernel;
$this->commentManager = $comment_manager; $this->commentManager = $comment_manager;
$this->entityManager = $entity_manager;
} }
/** /**
...@@ -60,7 +71,8 @@ public function __construct(HttpKernelInterface $http_kernel, CommentManagerInte ...@@ -60,7 +71,8 @@ public function __construct(HttpKernelInterface $http_kernel, CommentManagerInte
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('http_kernel'), $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) { ...@@ -285,7 +297,7 @@ public function renderNewCommentsNodeLinks(Request $request) {
$links = array(); $links = array();
foreach ($nids as $nid) { foreach ($nids as $nid) {
$node = node_load($nid); $node = $this->entityManager->getStorage('node')->load($nid);
$new = $this->commentManager->getCountNewComments($node); $new = $this->commentManager->getCountNewComments($node);
$page_number = $this->entityManager()->getStorage('comment') $page_number = $this->entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node); ->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\comment\CommentManagerInterface; use Drupal\comment\CommentManagerInterface;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\node\Entity\Node;
/** /**
* Tests paging of comments and their settings. * Tests paging of comments and their settings.
...@@ -240,7 +241,7 @@ function testCommentNewPageIndicator() { ...@@ -240,7 +241,7 @@ function testCommentNewPageIndicator() {
6 => 0, // Page of comment 0 6 => 0, // Page of comment 0
); );
$node = node_load($node->id()); $node = Node::load($node->id());
foreach ($expected_pages as $new_replies => $expected_page) { foreach ($expected_pages as $new_replies => $expected_page) {
$returned_page = \Drupal::entityManager()->getStorage('comment') $returned_page = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node); ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node);
...@@ -259,7 +260,7 @@ function testCommentNewPageIndicator() { ...@@ -259,7 +260,7 @@ function testCommentNewPageIndicator() {
); );
\Drupal::entityManager()->getStorage('node')->resetCache(array($node->id())); \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) { foreach ($expected_pages as $new_replies => $expected_page) {
$returned_page = \Drupal::entityManager()->getStorage('comment') $returned_page = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node); ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node);
......
...@@ -36,6 +36,7 @@ protected function setUp() { ...@@ -36,6 +36,7 @@ protected function setUp() {
* Tests the node comment statistics. * Tests the node comment statistics.
*/ */
function testCommentNodeCommentStatistics() { function testCommentNodeCommentStatistics() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Set comments to have subject and preview disabled. // Set comments to have subject and preview disabled.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
$this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentPreview(DRUPAL_DISABLED);
...@@ -45,7 +46,7 @@ function testCommentNodeCommentStatistics() { ...@@ -45,7 +46,7 @@ function testCommentNodeCommentStatistics() {
$this->drupalLogout(); $this->drupalLogout();
// Checks the initial values of node comment statistics with no comment. // 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_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_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.'); $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() { ...@@ -57,8 +58,9 @@ function testCommentNodeCommentStatistics() {
$this->postComment($this->node, $comment_text); $this->postComment($this->node, $comment_text);
// Checks the new values of node comment statistics with comment #1. // Checks the new values of node comment statistics with comment #1.
// The node needs to be reloaded with a node_load_multiple cache reset. // The node cache needs to be reset before reload.
$node = node_load($this->node->id(), TRUE); $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_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')->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.'); $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is 1.');
...@@ -80,8 +82,9 @@ function testCommentNodeCommentStatistics() { ...@@ -80,8 +82,9 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #2 and // Checks the new values of node comment statistics with comment #2 and
// ensure they haven't changed since the comment has not been moderated. // 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. // The node needs to be reloaded with the cache reset.
$node = node_load($this->node->id(), TRUE); $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_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')->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.'); $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is still 1.');
...@@ -101,8 +104,9 @@ function testCommentNodeCommentStatistics() { ...@@ -101,8 +104,9 @@ function testCommentNodeCommentStatistics() {
$comment_loaded = Comment::load($anonymous_comment->id()); $comment_loaded = Comment::load($anonymous_comment->id());
// Checks the new values of node comment statistics with comment #3. // Checks the new values of node comment statistics with comment #3.
// The node needs to be reloaded with a node_load_multiple cache reset. // The node needs to be reloaded with the cache reset.
$node = node_load($this->node->id(), TRUE); $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_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')->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.'); $this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.');
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\Comment;
use Drupal\node\Entity\Node;
/** /**
* Generates text using placeholders for dummy content to check comment token * Generates text using placeholders for dummy content to check comment token
...@@ -101,7 +102,7 @@ function testCommentTokenReplacement() { ...@@ -101,7 +102,7 @@ function testCommentTokenReplacement() {
$this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input))); $this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input)));
// Load node so comment_count gets computed. // 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). // Generate comment tokens for the node (it has 2 comments, both new).
$tests = array(); $tests = array();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\node\Entity\Node;
/** /**
* Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget. * Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget.
...@@ -103,7 +104,7 @@ public function testAutoCreate() { ...@@ -103,7 +104,7 @@ public function testAutoCreate() {
$result = $query->execute(); $result = $query->execute();
$this->assertTrue($result, 'Referenced node was created.'); $this->assertTrue($result, 'Referenced node was created.');
$referenced_nid = key($result); $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. // Assert the referenced node is associated with referencing node.
$result = \Drupal::entityQuery('node') $result = \Drupal::entityQuery('node')
...@@ -111,7 +112,7 @@ public function testAutoCreate() { ...@@ -111,7 +112,7 @@ public function testAutoCreate() {
->execute(); ->execute();
$referencing_nid = key($result); $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.'); $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. // Now try to view the node and check that the referenced node is shown.
......
...@@ -54,7 +54,9 @@ function testNodeDisplay() { ...@@ -54,7 +54,9 @@ function testNodeDisplay() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the default formatter is displaying with the file 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); $node_file = file_load($node->{$field_name}->target_id);
$file_link = array( $file_link = array(
'#theme' => 'file_link', '#theme' => 'file_link',
......
...@@ -17,6 +17,7 @@ class FileFieldPathTest extends FileFieldTestBase { ...@@ -17,6 +17,7 @@ class FileFieldPathTest extends FileFieldTestBase {
* Tests the normal formatter display on node display. * Tests the normal formatter display on node display.
*/ */
function testUploadPath() { function testUploadPath() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = strtolower($this->randomMachineName()); $field_name = strtolower($this->randomMachineName());
$type_name = 'article'; $type_name = 'article';
$this->createFileField($field_name, 'node', $type_name); $this->createFileField($field_name, 'node', $type_name);
...@@ -26,7 +27,8 @@ function testUploadPath() { ...@@ -26,7 +27,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded to the file root. // 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); $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()))); $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() { ...@@ -37,7 +39,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory. // 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); $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()))); $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() { ...@@ -49,7 +52,8 @@ function testUploadPath() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory. // 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); $node_file = file_load($node->{$field_name}->target_id);
// Do token replacement using the same user which uploaded the file, not // Do token replacement using the same user which uploaded the file, not
// the user running the test case. // the user running the test case.
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;