Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!11892
add getIteratorMock
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
add getIteratorMock
issue/drupal-3520128:3520128-create-helper-to
into
11.x
Overview
7
Commits
23
Pipelines
23
Changes
2
Open
ghost of drupal past
requested to merge
issue/drupal-3520128:3520128-create-helper-to
into
11.x
3 weeks ago
Overview
7
Commits
23
Pipelines
23
Changes
2
Expand
Closes
#3520128
0
0
Merge request reports
Compare
11.x
version 23
be478e28
3 weeks ago
version 22
58d884d9
3 weeks ago
version 21
244f05c5
3 weeks ago
version 20
86944135
3 weeks ago
version 19
7ef9eb65
3 weeks ago
version 18
f4f708b9
3 weeks ago
version 17
b6e64bbd
3 weeks ago
version 16
3cd58023
3 weeks ago
version 15
53f5366e
3 weeks ago
version 14
b78b6165
3 weeks ago
version 13
1dd34366
3 weeks ago
version 12
b78b6165
3 weeks ago
version 11
d608bbd8
3 weeks ago
version 10
39b83422
3 weeks ago
version 9
da467664
3 weeks ago
version 8
3a446a20
3 weeks ago
version 7
24ca7e56
3 weeks ago
version 6
92ee3be3
3 weeks ago
version 5
7802888c
3 weeks ago
version 4
81d69ca8
3 weeks ago
version 3
803518cd
3 weeks ago
version 2
40f21545
3 weeks ago
version 1
49ecb5e2
3 weeks ago
11.x (HEAD)
and
latest version
latest version
1c445caf
23 commits,
3 weeks ago
version 23
be478e28
22 commits,
3 weeks ago
version 22
58d884d9
21 commits,
3 weeks ago
version 21
244f05c5
20 commits,
3 weeks ago
version 20
86944135
19 commits,
3 weeks ago
version 19
7ef9eb65
18 commits,
3 weeks ago
version 18
f4f708b9
17 commits,
3 weeks ago
version 17
b6e64bbd
16 commits,
3 weeks ago
version 16
3cd58023
15 commits,
3 weeks ago
version 15
53f5366e
14 commits,
3 weeks ago
version 14
b78b6165
13 commits,
3 weeks ago
version 13
1dd34366
14 commits,
3 weeks ago
version 12
b78b6165
13 commits,
3 weeks ago
version 11
d608bbd8
12 commits,
3 weeks ago
version 10
39b83422
11 commits,
3 weeks ago
version 9
da467664
10 commits,
3 weeks ago
version 8
3a446a20
9 commits,
3 weeks ago
version 7
24ca7e56
8 commits,
3 weeks ago
version 6
92ee3be3
7 commits,
3 weeks ago
version 5
7802888c
5 commits,
3 weeks ago
version 4
81d69ca8
4 commits,
3 weeks ago
version 3
803518cd
3 commits,
3 weeks ago
version 2
40f21545
2 commits,
3 weeks ago
version 1
49ecb5e2
1 commit,
3 weeks ago
2 files
+
109
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
core/tests/Drupal/Tests/Core/Entity/EntityViewBuilderTest.php
0 → 100644
+
80
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Tests\Core\Entity
;
use
Drupal\Core\Entity\Display\EntityViewDisplayInterface
;
use
Drupal\Core\Entity\EntityViewBuilder
;
use
Drupal\Core\Entity\FieldableEntityInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Tests\UnitTestCase
;
/**
* @coversDefaultClass \Drupal\Core\Entity\EntityViewBuilder
* @group Entity
*/
class
EntityViewBuilderTest
extends
UnitTestCase
{
const
string
ENTITY_TYPE_ID
=
'test_entity_type'
;
/**
* The entity view builder under test.
*
* @var \Drupal\Core\Entity\EntityViewBuilder
*/
protected
EntityViewBuilder
$viewBuilder
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
viewBuilder
=
new
class
()
extends
EntityViewBuilder
{
public
function
__construct
()
{
$this
->
entityTypeId
=
EntityViewBuilderTest
::
ENTITY_TYPE_ID
;
}
};
}
/**
* Tests build components using a mocked Iterator.
*/
public
function
testBuildComponents
():
void
{
$field_name
=
$this
->
randomMachineName
();
$bundle
=
$this
->
randomMachineName
();
$entity_id
=
mt_rand
(
20
,
30
);
$field_item_list
=
$this
->
createStub
(
FieldItemListInterface
::
class
);
$item
=
new
\stdClass
();
$this
->
setupMockIterator
(
$field_item_list
,
[
$item
]);
$entity
=
$this
->
createConfiguredStub
(
FieldableEntityInterface
::
class
,
[
'bundle'
=>
$bundle
,
'hasField'
=>
TRUE
,
'get'
=>
$field_item_list
,
]);
$formatter_result
=
[
$entity_id
=>
[
'#'
.
$this
->
randomMachineName
()
=>
$this
->
randomString
()],
];
$display
=
$this
->
createConfiguredStub
(
EntityViewDisplayInterface
::
class
,
[
'getComponents'
=>
[
$field_name
=>
[]],
'buildMultiple'
=>
$formatter_result
,
]);
$entities
=
[
$entity_id
=>
$entity
];
$displays
=
[
$bundle
=>
$display
];
$build
=
[
$entity_id
=>
[]];
$view_mode
=
$this
->
randomMachineName
();
// Assert the hook is invoked.
$module_handler
=
$this
->
createMock
(
ModuleHandlerInterface
::
class
);
$module_handler
->
expects
(
$this
->
once
())
->
method
(
'invokeAll'
)
->
with
(
'entity_prepare_view'
,
[
self
::
ENTITY_TYPE_ID
,
$entities
,
$displays
,
$view_mode
]);
$this
->
viewBuilder
->
setModuleHandler
(
$module_handler
);
$this
->
viewBuilder
->
buildComponents
(
$build
,
$entities
,
$displays
,
$view_mode
);
$this
->
assertSame
([],
$item
->
_attributes
);
$this
->
assertSame
(
$formatter_result
,
$build
);
}
}
Loading