.../comment/Controller/CommentController.php | 20 ++++++++++++++++---- .../comment/Tests/CommentNewIndicatorTest.php | 8 ++++---- .../history/Controller/HistoryController.php | 8 ++++---- .../lib/Drupal/history/Tests/HistoryTest.php | 4 ++-- .../system/Tests/Theme/ThemeInfoStylesTest.php | 20 ++++++++++---------- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index ca1d401..652997f 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -11,6 +11,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -34,6 +35,13 @@ class CommentController implements ControllerInterface { protected $urlGenerator; /** + * The current user service. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** * The HTTP kernel. * * @var \Symfony\Component\HttpKernel\HttpKernelInterface @@ -45,11 +53,14 @@ class CommentController implements ControllerInterface { * * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The url generator service. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user service. * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel * HTTP kernel to handle requests. */ - public function __construct(UrlGeneratorInterface $url_generator, HttpKernelInterface $httpKernel) { + public function __construct(UrlGeneratorInterface $url_generator, AccountInterface $current_user, HttpKernelInterface $httpKernel) { $this->urlGenerator = $url_generator; + $this->currentUser = $current_user; $this->httpKernel = $httpKernel; } /** @@ -58,6 +69,7 @@ public function __construct(UrlGeneratorInterface $url_generator, HttpKernelInte public static function create(ContainerInterface $container) { return new static( $container->get('url_generator'), + $container->get('current_user'), $container->get('http_kernel') ); } @@ -143,7 +155,7 @@ public function commentPermalink(Request $request, CommentInterface $comment) { * The JSON response. */ public function renderNewCommentsNodeLinks(Request $request) { - if ($request->attributes->get('_account')->isAnonymous()) { + if ($this->currentUser->isAnonymous()) { throw new AccessDeniedHttpException(); } @@ -157,11 +169,11 @@ public function renderNewCommentsNodeLinks(Request $request) { $links = array(); foreach ($nids as $nid) { $node = node_load($nid); - $new = comment_num_new($node->nid); + $new = comment_num_new($node->id()); $query = comment_new_page_count($node->comment_count, $new, $node); $links[$nid] = array( 'new_comment_count' => (int)$new, - 'first_new_comment_link' => url("node/$node->nid", array('query' => $query, 'fragment' => 'new')), + 'first_new_comment_link' => url('node/' . $node->id(), array('query' => $query, 'fragment' => 'new')), ); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php index e8c37ac..d777cd6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -110,12 +110,12 @@ public function testCommentNewCommentsIndicator() { // node received a comment after the user last viewed it, and hence it would // perform an HTTP request to render the "new comments" node link. $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->changed->value . '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.'); - $response = $this->renderNewCommentsNodeLinks(array($this->node->nid)); + $response = $this->renderNewCommentsNodeLinks(array($this->node->id())); $this->assertResponse(200); $json = drupal_json_decode($response); - $expected = array($this->node->nid => array( + $expected = array($this->node->id() => array( 'new_comment_count' => 1, - 'first_new_comment_link' => url('node/' . $this->node->nid, array('fragment' => 'new')), + 'first_new_comment_link' => url('node/' . $this->node->id(), array('fragment' => 'new')), )); $this->assertIdentical($expected, $json); @@ -125,7 +125,7 @@ public function testCommentNewCommentsIndicator() { // Accessing the endpoint as the anonymous user should return a 403. $this->drupalLogout(); - $this->renderNewCommentsNodeLinks(array($this->node->nid)); + $this->renderNewCommentsNodeLinks(array($this->node->id())); $this->assertResponse(403); $this->renderNewCommentsNodeLinks(array()); $this->assertResponse(403); diff --git a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php index f3db58e..1c4849c 100644 --- a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php +++ b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php @@ -7,17 +7,17 @@ namespace Drupal\history\Controller; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Drupal\Core\Controller\ControllerBase; use Drupal\node\NodeInterface; /** * Returns responses for History module routes. */ -class HistoryController { +class HistoryController extends ControllerBase { /** * Returns a set of nodes' last read timestamps. @@ -29,7 +29,7 @@ class HistoryController { * The JSON response. */ public function getNodeReadTimestamps(Request $request) { - if ($request->attributes->get('_account')->isAnonymous()) { + if ($this->currentUser()->isAnonymous()) { throw new AccessDeniedHttpException(); } @@ -56,7 +56,7 @@ public function getNodeReadTimestamps(Request $request) { * The node whose "last read" timestamp should be updated. */ public function readNode(Request $request, NodeInterface $node) { - if ($request->attributes->get('_account')->isAnonymous()) { + if ($this->currentUser()->isAnonymous()) { throw new AccessDeniedHttpException(); } diff --git a/core/modules/history/lib/Drupal/history/Tests/HistoryTest.php b/core/modules/history/lib/Drupal/history/Tests/HistoryTest.php index 6b165a7..84356f2 100644 --- a/core/modules/history/lib/Drupal/history/Tests/HistoryTest.php +++ b/core/modules/history/lib/Drupal/history/Tests/HistoryTest.php @@ -93,7 +93,7 @@ protected function getNodeReadTimestamps(array $node_ids) { /** * Mark a node as read for the current user. * - * @param $node_id + * @param int $node_id * A node ID. * * @return string @@ -112,7 +112,7 @@ protected function markNodeAsRead($node_id) { * Verifies that the history endpoints work. */ function testHistory() { - $nid = $this->test_node->nid; + $nid = $this->test_node->id(); // Retrieve "last read" timestamp for test node, for the current user. $response = $this->getNodeReadTimestamps(array($nid)); diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php index bae08f9..c152a27 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeInfoStylesTest.php @@ -47,19 +47,19 @@ function testStylesheets() { $this->drupalGet('theme-test/info/stylesheets'); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$base/base-add.css')]")), "$base/base-add.css found"); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$base/base-override.css')]")), "$base/base-override.css found"); - $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-remove.css')]")), "base-remove.css not found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$base/base-add.css')]")), "$base/base-add.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$base/base-override.css')]")), "$base/base-override.css found"); + $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-remove.css')]")), "base-remove.css not found"); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/sub-add.css')]")), "$sub/sub-add.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/sub-add.css')]")), "$sub/sub-add.css found"); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/sub-override.css')]")), "$sub/sub-override.css found"); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/base-add.sub-override.css')]")), "$sub/base-add.sub-override.css found"); - $this->assertTrue(1 === count($this->xpath("//link[contains(@href, '$sub/base-remove.sub-override.css')]")), "$sub/base-remove.sub-override.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/sub-override.css')]")), "$sub/sub-override.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/base-add.sub-override.css')]")), "$sub/base-add.sub-override.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/base-remove.sub-override.css')]")), "$sub/base-remove.sub-override.css found"); - $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'sub-remove.css')]")), "sub-remove.css not found"); - $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-add.sub-remove.css')]")), "base-add.sub-remove.css not found"); - $this->assertTrue(0 === count($this->xpath("//link[contains(@href, 'base-override.sub-remove.css')]")), "base-override.sub-remove.css not found"); + $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'sub-remove.css')]")), "sub-remove.css not found"); + $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-add.sub-remove.css')]")), "base-add.sub-remove.css not found"); + $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-override.sub-remove.css')]")), "base-override.sub-remove.css not found"); } }