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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
c8ef0bb6
Commit
c8ef0bb6
authored
Jun 3, 2019
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3046680
by claudiu.cristea, Lendude: Convert NewDefaultThemeBlocksTest into a Kernel test
parent
684c23c9
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/block/tests/src/Kernel/NewDefaultThemeBlocksTest.php
+28
-18
28 additions, 18 deletions
...ules/block/tests/src/Kernel/NewDefaultThemeBlocksTest.php
with
28 additions
and
18 deletions
core/modules/block/tests/src/
Functiona
l/NewDefaultThemeBlocksTest.php
→
core/modules/block/tests/src/
Kerne
l/NewDefaultThemeBlocksTest.php
+
28
−
18
View file @
c8ef0bb6
<?php
<?php
namespace
Drupal\Tests\block\
Functiona
l
;
namespace
Drupal\Tests\block\
Kerne
l
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\Tests\block\Traits\BlockCreationTrait
;
/**
/**
* Tests that the new default theme gets blocks.
* Tests that the new default theme gets blocks.
*
*
* @group block
* @group block
*/
*/
class
NewDefaultThemeBlocksTest
extends
BrowserTestBase
{
class
NewDefaultThemeBlocksTest
extends
KernelTestBase
{
use
BlockCreationTrait
;
/**
/**
* Modules to install.
* {@inheritdoc}
*
* @var array
*/
*/
public
static
$modules
=
[
'block'
];
protected
static
$modules
=
[
'block'
,
'system'
,
];
/**
/**
* Check the enabled Bartik blocks are correctly copied over.
* Check the enabled Bartik blocks are correctly copied over.
*/
*/
public
function
testNewDefaultThemeBlocks
()
{
public
function
testNewDefaultThemeBlocks
()
{
$theme_handler
=
$this
->
container
->
get
(
'theme_handler'
);
$default_theme
=
$this
->
config
(
'system.theme'
)
->
get
(
'default'
);
$default_theme
=
$this
->
config
(
'system.theme'
)
->
get
(
'default'
);
// Add two instances of the user login block.
// Add two instances of the user login block.
$this
->
drupalP
laceBlock
(
'user_login_block'
,
[
$this
->
p
laceBlock
(
'user_login_block'
,
[
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
]);
]);
$this
->
drupalP
laceBlock
(
'user_login_block'
,
[
$this
->
p
laceBlock
(
'user_login_block'
,
[
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
]);
]);
// Add an instance of a different block.
// Add an instance of a different block.
$this
->
drupalP
laceBlock
(
'system_powered_by_block'
,
[
$this
->
p
laceBlock
(
'system_powered_by_block'
,
[
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
'id'
=>
$default_theme
.
'_'
.
strtolower
(
$this
->
randomMachineName
(
8
)),
]);
]);
// Install a different theme.
// Install a different theme.
$new_theme
=
'bartik'
;
$new_theme
=
'bartik'
;
$this
->
assertFalse
(
$new_theme
==
$default_theme
,
'The new theme is different from the previous default theme.'
);
// The new theme is different from the previous default theme.
\Drupal
::
service
(
'theme_handler'
)
->
install
([
$new_theme
]);
$this
->
assertNotEquals
(
$new_theme
,
$default_theme
);
$theme_handler
->
install
([
$new_theme
]);
$this
->
config
(
'system.theme'
)
$this
->
config
(
'system.theme'
)
->
set
(
'default'
,
$new_theme
)
->
set
(
'default'
,
$new_theme
)
->
save
();
->
save
();
/** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
$block_storage
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
'block'
);
$block_storage
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
'block'
);
// Ensure that the new theme has all the blocks as the previous default.
// Ensure that the new default theme has the same blocks as the previous
// default theme.
$default_block_names
=
$block_storage
->
getQuery
()
$default_block_names
=
$block_storage
->
getQuery
()
->
condition
(
'theme'
,
$default_theme
)
->
condition
(
'theme'
,
$default_theme
)
->
execute
();
->
execute
();
$new_blocks
=
$block_storage
->
getQuery
()
$new_blocks
=
$block_storage
->
getQuery
()
->
condition
(
'theme'
,
$new_theme
)
->
condition
(
'theme'
,
$new_theme
)
->
execute
();
->
execute
();
$this
->
assertTrue
(
count
(
$default_block_names
)
==
count
(
$new_blocks
),
'The new default theme has the same number of blocks as the previous theme.'
);
$this
->
assertEquals
(
count
(
$default_block_names
),
count
(
$new_blocks
));
foreach
(
$default_block_names
as
$default_block_name
)
{
foreach
(
$default_block_names
as
$default_block_name
)
{
// Remove the matching block from the list of blocks in the new theme.
// Remove the matching block from the list of blocks in the new theme.
// E.g., if the old theme has block.block.stark_admin,
// E.g., if the old theme has block.block.stark_admin,
// unset block.block.bartik_admin.
// unset block.block.bartik_admin.
unset
(
$new_blocks
[
str_replace
(
$default_theme
.
'_'
,
$new_theme
.
'_'
,
$default_block_name
)]);
unset
(
$new_blocks
[
str_replace
(
$default_theme
.
'_'
,
$new_theme
.
'_'
,
$default_block_name
)]);
}
}
$this
->
assert
True
(
e
mpty
(
$new_blocks
)
,
'The new theme has exactly the same blocks as the previous default theme.'
)
;
$this
->
assert
E
mpty
(
$new_blocks
);
// Install a hidden base theme and ensure blocks are not copied.
// Install a hidden base theme and ensure blocks are not copied.
$base_theme
=
'test_basetheme'
;
$base_theme
=
'test_basetheme'
;
\Drupal
::
service
(
'
theme_handler
'
)
->
install
([
$base_theme
]);
$
theme_handler
->
install
([
$base_theme
]);
$new_blocks
=
$block_storage
->
getQuery
()
$new_blocks
=
$block_storage
->
getQuery
()
->
condition
(
'theme'
,
$base_theme
)
->
condition
(
'theme'
,
$base_theme
)
->
execute
();
->
execute
();
$this
->
assertTrue
(
empty
(
$new_blocks
),
'Installing a hidden base theme does not copy blocks from the default theme.'
);
// Installing a hidden base theme does not copy the blocks from the default
// theme.
$this
->
assertEmpty
(
$new_blocks
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment