Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
224
Merge Requests
224
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
fd046df3
Unverified
Commit
fd046df3
authored
Jun 15, 2020
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3150474
by jungle, munish.kumar: Inaccurate return type of \Drupal\views\Views::getView()
(cherry picked from commit
19d2c39d
)
parent
57735992
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
core/modules/views/src/Views.php
core/modules/views/src/Views.php
+3
-2
core/modules/views/tests/src/Unit/ViewsTest.php
core/modules/views/tests/src/Unit/ViewsTest.php
+16
-0
No files found.
core/modules/views/src/Views.php
View file @
fd046df3
...
...
@@ -115,14 +115,15 @@ public static function handlerManager($type) {
* @param string $id
* The view ID to load.
*
* @return \Drupal\views\ViewExecutable
* A view executable instance
, from the loaded entity
.
* @return \Drupal\views\ViewExecutable
|null
* A view executable instance
or NULL if the view does not exist
.
*/
public
static
function
getView
(
$id
)
{
$view
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'view'
)
->
load
(
$id
);
if
(
$view
)
{
return
static
::
executableFactory
()
->
get
(
$view
);
}
return
NULL
;
}
/**
...
...
core/modules/views/tests/src/Unit/ViewsTest.php
View file @
fd046df3
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\views\Unit
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\views\Views
;
...
...
@@ -72,6 +73,21 @@ public function testGetView() {
$this
->
assertEquals
(
spl_object_hash
(
$view
),
spl_object_hash
(
$executable
->
storage
));
}
/**
* Tests the getView() method against a non-existent view.
*
* @covers ::getView
*/
public
function
testGetNonExistentView
()
{
$entity_type_manager
=
$this
->
prophesize
(
EntityTypeManagerInterface
::
class
);
$storage
=
$this
->
prophesize
(
EntityStorageInterface
::
class
);
$storage
->
load
(
'test_view_non_existent'
)
->
willReturn
(
NULL
);
$entity_type_manager
->
getStorage
(
'view'
)
->
willReturn
(
$storage
->
reveal
());
$this
->
container
->
set
(
'entity_type.manager'
,
$entity_type_manager
->
reveal
());
$executable_does_not_exist
=
Views
::
getView
(
'test_view_non_existent'
);
$this
->
assertNull
(
$executable_does_not_exist
);
}
/**
* @covers ::getApplicableViews
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment