Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
navigation
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
navigation
Commits
f7224ff8
Commit
f7224ff8
authored
Mar 18, 2024
by
m4olivei
Committed by
Cristina Chumillas
Mar 18, 2024
Browse files
Options
Downloads
Patches
Plain Diff
Resolve
#3426529
"Add unit tests"
parent
7ba14b7d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!185
Resolve #3426529 "Add unit tests"
Pipeline
#122568
passed with warnings
Mar 18, 2024
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/NavigationBlockInterface.php
+9
-9
9 additions, 9 deletions
src/NavigationBlockInterface.php
tests/src/Unit/NavigationBlockFormTest.php
+166
-0
166 additions, 0 deletions
tests/src/Unit/NavigationBlockFormTest.php
with
175 additions
and
9 deletions
src/NavigationBlockInterface.php
+
9
−
9
View file @
f7224ff8
...
...
@@ -14,8 +14,8 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
/**
* Returns the plugin instance.
*
* @return \Drupal\
Core\Block\
BlockPluginInterface
* The plugin instance for this block.
* @return \Drupal\
navigation\Navigation
BlockPluginInterface
* The plugin instance for this
navigation
block.
*/
public
function
getPlugin
();
...
...
@@ -23,15 +23,15 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
* Returns the plugin ID.
*
* @return string
* The plugin ID for this block.
* The plugin ID for this
navigation
block.
*/
public
function
getPluginId
();
/**
* Returns the region this block is placed in.
* Returns the region this
navigation
block is placed in.
*
* @return string
* The region this block is placed in.
* The region this
navigation
block is placed in.
*/
public
function
getRegion
();
...
...
@@ -44,7 +44,7 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
public
function
getVisibility
();
/**
* Gets conditions for this block.
* Gets conditions for this
navigation
block.
*
* @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginCollection
* An array or collection of configured condition plugins.
...
...
@@ -75,7 +75,7 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
public
function
setVisibilityConfig
(
$instance_id
,
array
$configuration
);
/**
* Returns the weight of this block (used for sorting).
* Returns the weight of this
navigation
block (used for sorting).
*
* @return int
* The block weight.
...
...
@@ -83,7 +83,7 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
public
function
getWeight
();
/**
* Sets the region this block is placed in.
* Sets the region this
navigation
block is placed in.
*
* @param string $region
* The region to place this block in.
...
...
@@ -93,7 +93,7 @@ interface NavigationBlockInterface extends ConfigEntityInterface {
public
function
setRegion
(
$region
);
/**
* Sets the block weight.
* Sets the
navigation
block weight.
*
* @param int $weight
* The desired weight.
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/NavigationBlockFormTest.php
0 → 100644
+
166
−
0
View file @
f7224ff8
<?php
namespace
Drupal\Tests\navigation\Unit
;
use
Drupal\Core\Plugin\PluginFormFactoryInterface
;
use
Drupal\navigation\Entity\NavigationBlock
;
use
Drupal\navigation\Form\NavigationBlockForm
;
use
Drupal\navigation\NavigationBlockPluginBase
;
use
Drupal\navigation\NavigationBlockRepository
;
use
Drupal\Tests\UnitTestCase
;
/**
* @coversDefaultClass \Drupal\navigation\Form\NavigationBlockForm
* @group navigation
*/
class
NavigationBlockFormTest
extends
UnitTestCase
{
/**
* The condition plugin manager.
*
* @var \Drupal\Core\Executable\ExecutableManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$conditionManager
;
/**
* The navigation block storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$storage
;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$language
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$entityTypeManager
;
/**
* The mocked context handler.
*
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$contextHandler
;
/**
* The mocked context repository.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected
$contextRepository
;
/**
* The plugin form manager.
*
* @var \Drupal\Core\Plugin\PluginFormFactoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected
$pluginFormFactory
;
/**
* The navigation block repository.
*
* @var \Drupal\navigation\NavigationBlockRepositoryInterface
*/
protected
$navigationBlockRepository
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
conditionManager
=
$this
->
createMock
(
'Drupal\Core\Executable\ExecutableManagerInterface'
);
$this
->
language
=
$this
->
createMock
(
'Drupal\Core\Language\LanguageManagerInterface'
);
$this
->
contextRepository
=
$this
->
createMock
(
'Drupal\Core\Plugin\Context\ContextRepositoryInterface'
);
$this
->
entityTypeManager
=
$this
->
createMock
(
'Drupal\Core\Entity\EntityTypeManagerInterface'
);
$this
->
storage
=
$this
->
createMock
(
'Drupal\Core\Config\Entity\ConfigEntityStorageInterface'
);
$this
->
entityTypeManager
->
expects
(
$this
->
any
())
->
method
(
'getStorage'
)
->
willReturn
(
$this
->
storage
);
$this
->
pluginFormFactory
=
$this
->
prophesize
(
PluginFormFactoryInterface
::
class
);
$this
->
contextHandler
=
$this
->
createMock
(
'Drupal\Core\Plugin\Context\ContextHandlerInterface'
);
$this
->
navigationBlockRepository
=
new
NavigationBlockRepository
(
$this
->
entityTypeManager
,
$this
->
contextHandler
);
}
/**
* Mocks a navigation block with a navigation block plugin.
*
* @param string $machine_name
* The machine name of the navigation block plugin.
*
* @return \Drupal\navigation\NavigationBlockInterface|\PHPUnit\Framework\MockObject\MockObject
* The mocked navigation block.
*/
protected
function
getNavigationBlockMockWithMachineName
(
$machine_name
)
{
$plugin
=
$this
->
getMockBuilder
(
NavigationBlockPluginBase
::
class
)
->
disableOriginalConstructor
()
->
getMock
();
$plugin
->
expects
(
$this
->
any
())
->
method
(
'getMachineNameSuggestion'
)
->
willReturn
(
$machine_name
);
$navigation_block
=
$this
->
getMockBuilder
(
NavigationBlock
::
class
)
->
disableOriginalConstructor
()
->
getMock
();
$navigation_block
->
expects
(
$this
->
any
())
->
method
(
'getPlugin'
)
->
willReturn
(
$plugin
);
return
$navigation_block
;
}
/**
* Tests the unique machine name generator.
*
* @see \Drupal\block\BlockForm::getUniqueMachineName()
*/
public
function
testGetUniqueMachineName
()
{
$navigation_blocks
=
[];
$navigation_blocks
[
'test'
]
=
$this
->
getNavigationBlockMockWithMachineName
(
'test'
);
$navigation_blocks
[
'other_test'
]
=
$this
->
getNavigationBlockMockWithMachineName
(
'other_test'
);
$navigation_blocks
[
'other_test_1'
]
=
$this
->
getNavigationBlockMockWithMachineName
(
'other_test'
);
$navigation_blocks
[
'other_test_2'
]
=
$this
->
getNavigationBlockMockWithMachineName
(
'other_test'
);
$query
=
$this
->
createMock
(
'Drupal\Core\Entity\Query\QueryInterface'
);
$query
->
expects
(
$this
->
exactly
(
5
))
->
method
(
'condition'
)
->
willReturn
(
$query
);
$query
->
expects
(
$this
->
exactly
(
5
))
->
method
(
'execute'
)
->
willReturn
([
'test'
,
'other_test'
,
'other_test_1'
,
'other_test_2'
]);
$this
->
storage
->
expects
(
$this
->
exactly
(
5
))
->
method
(
'getQuery'
)
->
willReturn
(
$query
);
$navigation_block_form
=
new
NavigationBlockForm
(
$this
->
entityTypeManager
,
$this
->
conditionManager
,
$this
->
contextRepository
,
$this
->
language
,
$this
->
pluginFormFactory
->
reveal
(),
$this
->
navigationBlockRepository
);
// Ensure that the navigation block with just one other instance gets
// the next available name suggestion.
$this
->
assertEquals
(
'test_2'
,
$navigation_block_form
->
getUniqueMachineName
(
$navigation_blocks
[
'test'
]));
// Ensure that the navigation block with already three instances (_0, _1, _
// 2) gets the 4th available name.
$this
->
assertEquals
(
'other_test_3'
,
$navigation_block_form
->
getUniqueMachineName
(
$navigation_blocks
[
'other_test'
]));
$this
->
assertEquals
(
'other_test_3'
,
$navigation_block_form
->
getUniqueMachineName
(
$navigation_blocks
[
'other_test_1'
]));
$this
->
assertEquals
(
'other_test_3'
,
$navigation_block_form
->
getUniqueMachineName
(
$navigation_blocks
[
'other_test_2'
]));
// Ensure that a navigation block without an instance yet gets the
// suggestion as unique machine name.
$last_block
=
$this
->
getNavigationBlockMockWithMachineName
(
'last_test'
);
$this
->
assertEquals
(
'last_test'
,
$navigation_block_form
->
getUniqueMachineName
(
$last_block
));
}
}
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
sign in
to comment