Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
facets
Commits
27d088d7
Commit
27d088d7
authored
Jun 09, 2018
by
borisson_
Committed by
borisson_
Jun 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2949260
by borisson_: Show active facets even when "Hide facet with 1 result" is selected
parent
3b27b114
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
src/Plugin/facets/processor/HideOnlyOneItemProcessor.php
src/Plugin/facets/processor/HideOnlyOneItemProcessor.php
+1
-1
tests/src/Functional/ProcessorIntegrationTest.php
tests/src/Functional/ProcessorIntegrationTest.php
+7
-3
tests/src/Unit/Plugin/processor/HideOnlyOneItemProcessorTest.php
...rc/Unit/Plugin/processor/HideOnlyOneItemProcessorTest.php
+19
-0
No files found.
src/Plugin/facets/processor/HideOnlyOneItemProcessor.php
View file @
27d088d7
...
@@ -24,7 +24,7 @@ class HideOnlyOneItemProcessor extends ProcessorPluginBase implements BuildProce
...
@@ -24,7 +24,7 @@ class HideOnlyOneItemProcessor extends ProcessorPluginBase implements BuildProce
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
build
(
FacetInterface
$facet
,
array
$results
)
{
public
function
build
(
FacetInterface
$facet
,
array
$results
)
{
if
(
count
(
$results
)
===
1
)
{
if
(
count
(
$results
)
===
1
&&
!
$results
[
0
]
->
isActive
()
)
{
return
[];
return
[];
}
}
...
...
tests/src/Functional/ProcessorIntegrationTest.php
View file @
27d088d7
...
@@ -768,6 +768,12 @@ class ProcessorIntegrationTest extends FacetsTestBase {
...
@@ -768,6 +768,12 @@ class ProcessorIntegrationTest extends FacetsTestBase {
public
function
testHideOnlyOneItemProcessor
()
{
public
function
testHideOnlyOneItemProcessor
()
{
$entity_test_storage
=
\
Drupal
::
entityTypeManager
()
$entity_test_storage
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'entity_test_mulrev_changed'
);
->
getStorage
(
'entity_test_mulrev_changed'
);
// Load all items and delete them.
$all
=
$entity_test_storage
->
loadMultiple
();
foreach
(
$all
as
$item
)
{
$item
->
delete
();
}
$entity_test_storage
->
create
([
$entity_test_storage
->
create
([
'name'
=>
'baz baz'
,
'name'
=>
'baz baz'
,
'body'
=>
'foo test'
,
'body'
=>
'foo test'
,
...
@@ -775,7 +781,6 @@ class ProcessorIntegrationTest extends FacetsTestBase {
...
@@ -775,7 +781,6 @@ class ProcessorIntegrationTest extends FacetsTestBase {
'keywords'
=>
[
'kiwi'
],
'keywords'
=>
[
'kiwi'
],
'category'
=>
'article_category'
,
'category'
=>
'article_category'
,
])
->
save
();
])
->
save
();
$this
->
indexItems
(
$this
->
indexId
);
$this
->
indexItems
(
$this
->
indexId
);
$facet_name
=
'Drupalcon Vienna'
;
$facet_name
=
'Drupalcon Vienna'
;
...
@@ -790,8 +795,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
...
@@ -790,8 +795,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this
->
drupalPostForm
(
$this
->
editForm
,
$form
,
'Save'
);
$this
->
drupalPostForm
(
$this
->
editForm
,
$form
,
'Save'
);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertFacetBlocksAppear
();
$this
->
assertSession
()
->
pageTextContains
(
' Displaying 1 search results'
);
$this
->
clickLink
(
'kiwi'
);
$this
->
assertNoFacetBlocksAppear
();
$this
->
assertNoFacetBlocksAppear
();
}
}
...
...
tests/src/Unit/Plugin/processor/HideOnlyOneItemProcessorTest.php
View file @
27d088d7
...
@@ -33,6 +33,25 @@ class HideOnlyOneItemProcessorTest extends UnitTestCase {
...
@@ -33,6 +33,25 @@ class HideOnlyOneItemProcessorTest extends UnitTestCase {
$this
->
assertCount
(
0
,
$processed_results
);
$this
->
assertCount
(
0
,
$processed_results
);
}
}
/**
* Tests with one result that is already active.
*
* @covers ::build
*/
public
function
testWithOneActiveResult
()
{
$processor
=
new
HideOnlyOneItemProcessor
([],
'hide_only_one_item'
,
[]);
$facet
=
new
Facet
([],
'facets_facet'
);
$results
=
[
new
Result
(
$facet
,
'1'
,
1
,
1
),
];
$results
[
0
]
->
setActiveState
(
TRUE
);
$facet
=
$this
->
getMockBuilder
(
Facet
::
class
)
->
disableOriginalConstructor
()
->
getMock
();
$processed_results
=
$processor
->
build
(
$facet
,
$results
);
$this
->
assertCount
(
1
,
$processed_results
);
}
/**
/**
* Tests with one result.
* Tests with one result.
*
*
...
...
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