Skip to content
GitLab
Explore
Sign in
project
facets
Compare revisions
b3e1b54646a5084fd3c191b42ba6057079c4f1e2 to 8.x-1.0-alpha1
Hide whitespace changes
Inline
Side-by-side
src/Processor/PreQueryProcessorInterface.php
View file @
7bd666e7
...
...
@@ -15,7 +15,7 @@ use Drupal\facets\FacetInterface;
interface
PreQueryProcessorInterface
extends
ProcessorInterface
{
/**
*
Processor r
uns before the query is executed.
*
R
uns before the query is executed.
*
* Uses the queryType and the facetSource implementation to make sure the
* alteration to the query was added before the query is executed in the
...
...
src/Processor/ProcessorPluginBase.php
View file @
7bd666e7
...
...
@@ -28,8 +28,7 @@ class ProcessorPluginBase extends PluginBase implements ProcessorInterface {
/**
* {@inheritdoc}
*/
public
function
validateConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
,
FacetInterface
$facet
)
{
}
public
function
validateConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
,
FacetInterface
$facet
)
{}
/**
* {@inheritdoc}
...
...
src/Processor/WidgetOrderPluginBase.php
View file @
7bd666e7
...
...
@@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
use
Drupal\facets\FacetInterface
;
/**
* A base class for plugins that implements
most of th
e boilerplate.
* A base class for plugins that implements
som
e boilerplate
for a widget order
.
*/
abstract
class
WidgetOrderPluginBase
extends
ProcessorPluginBase
implements
WidgetOrderProcessorInterface
{
...
...
src/Processor/WidgetOrderProcessorInterface.php
View file @
7bd666e7
...
...
@@ -13,7 +13,7 @@ namespace Drupal\facets\Processor;
interface
WidgetOrderProcessorInterface
extends
BuildProcessorInterface
{
/**
* Order results and return the new order of results.
* Order
s
results and return the new order of results.
*
* @param \Drupal\facets\Result\Result[] $results
* An array containing results.
...
...
src/QueryType/QueryTypeInterface.php
View file @
7bd666e7
...
...
@@ -12,12 +12,15 @@ namespace Drupal\facets\QueryType;
interface
QueryTypeInterface
{
/**
* Add facet info to the query using the backend native query object.
* Adds facet info to the query using the backend native query object.
*
* @return array
* Returns an array of unfiltered results
*/
public
function
execute
();
/**
* Build the facet information, so it can be rendered.
* Build
s
the facet information, so it can be rendered.
*/
public
function
build
();
...
...
src/QueryType/QueryTypePluginBase.php
View file @
7bd666e7
...
...
@@ -28,7 +28,7 @@ abstract class QueryTypePluginBase extends PluginBase implements QueryTypeInterf
}
/**
*
Holds t
he backend native query object.
*
T
he backend native query object.
*
* @var \Drupal\search_api\Query\Query $query
*/
...
...
@@ -42,7 +42,7 @@ abstract class QueryTypePluginBase extends PluginBase implements QueryTypeInterf
protected
$facet
;
/**
*
Holds t
he results for the facet.
*
T
he results for the facet.
*
* @var \Drupal\facets\Result\ResultInterface[]
*/
...
...
src/Result/Result.php
View file @
7bd666e7
...
...
@@ -45,7 +45,7 @@ class Result implements ResultInterface {
protected
$active
=
FALSE
;
/**
* Construct a new
instance of the
value object.
* Construct
s
a new
result
value object.
*
* @param mixed $raw_value
* The raw value.
...
...
src/Result/ResultInterface.php
View file @
7bd666e7
...
...
@@ -15,7 +15,7 @@ use Drupal\Core\Url;
interface
ResultInterface
{
/**
*
G
et the raw value as present in the index.
*
R
et
urns
the raw value as present in the index.
*
* @return string
* The raw value of the result.
...
...
@@ -23,7 +23,7 @@ interface ResultInterface {
public
function
getRawValue
();
/**
*
G
et the display value as present in the index.
*
R
et
urns
the display value as present in the index.
*
* @return string
* The formatted value of the result.
...
...
@@ -31,7 +31,7 @@ interface ResultInterface {
public
function
getDisplayValue
();
/**
*
G
et the count for the result.
*
R
et
urns
the count for the result.
*
* @return mixed
* The amount of items for the result.
...
...
@@ -39,7 +39,7 @@ interface ResultInterface {
public
function
getCount
();
/**
*
G
et the url.
*
R
et
urns
the url.
*
* @return \Drupal\Core\Url
* The url of the search page with the facet url appended.
...
...
@@ -47,7 +47,7 @@ interface ResultInterface {
public
function
getUrl
();
/**
* Set the url.
* Set
s
the url.
*
* @param \Drupal\Core\Url $url
* The url of the search page with the facet url appended.
...
...
@@ -55,7 +55,7 @@ interface ResultInterface {
public
function
setUrl
(
Url
$url
);
/**
* Indicate that the value is active (selected).
* Indicate
s
that the value is active (selected).
*
* @param bool $active
* A boolean indicating the active state.
...
...
@@ -71,7 +71,7 @@ interface ResultInterface {
public
function
isActive
();
/**
* Override the display value of a result.
* Override
s
the display value of a result.
*
* @param string $display_value
* Override display value.
...
...
src/Tests/ExampleContentTrait.php
View file @
7bd666e7
...
...
@@ -8,7 +8,6 @@
namespace
Drupal\facets\Tests
;
use
Drupal\search_api
\Entity\Index
;
use
Drupal\search_api
\Utility
;
/**
* Contains helpers to create data that can be used by tests.
...
...
@@ -39,42 +38,42 @@ trait ExampleContentTrait {
$entity_test_storage
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'entity_test'
);
$this
->
entities
[
1
]
=
$entity_test_storage
->
create
(
array
(
'name'
=>
'foo bar baz'
,
'body'
=>
'test test'
,
'type'
=>
'item'
,
'keywords'
=>
array
(
'orange'
),
'category'
=>
'item_category'
));
'name'
=>
'foo bar baz'
,
'body'
=>
'test test'
,
'type'
=>
'item'
,
'keywords'
=>
array
(
'orange'
),
'category'
=>
'item_category'
,
));
$this
->
entities
[
1
]
->
save
();
$this
->
entities
[
2
]
=
$entity_test_storage
->
create
(
array
(
'name'
=>
'foo test'
,
'body'
=>
'bar test'
,
'type'
=>
'item'
,
'keywords'
=>
array
(
'orange'
,
'apple'
,
'grape'
),
'category'
=>
'item_category'
));
'name'
=>
'foo test'
,
'body'
=>
'bar test'
,
'type'
=>
'item'
,
'keywords'
=>
array
(
'orange'
,
'apple'
,
'grape'
),
'category'
=>
'item_category'
,
));
$this
->
entities
[
2
]
->
save
();
$this
->
entities
[
3
]
=
$entity_test_storage
->
create
(
array
(
'name'
=>
'bar'
,
'body'
=>
'test foobar'
,
'type'
=>
'item'
,
));
'name'
=>
'bar'
,
'body'
=>
'test foobar'
,
'type'
=>
'item'
,
));
$this
->
entities
[
3
]
->
save
();
$this
->
entities
[
4
]
=
$entity_test_storage
->
create
(
array
(
'name'
=>
'foo baz'
,
'body'
=>
'test test test'
,
'type'
=>
'article'
,
'keywords'
=>
array
(
'apple'
,
'strawberry'
,
'grape'
),
'category'
=>
'article_category'
));
'name'
=>
'foo baz'
,
'body'
=>
'test test test'
,
'type'
=>
'article'
,
'keywords'
=>
array
(
'apple'
,
'strawberry'
,
'grape'
),
'category'
=>
'article_category'
,
));
$this
->
entities
[
4
]
->
save
();
$this
->
entities
[
5
]
=
$entity_test_storage
->
create
(
array
(
'name'
=>
'bar baz'
,
'body'
=>
'foo'
,
'type'
=>
'article'
,
'keywords'
=>
array
(
'orange'
,
'strawberry'
,
'grape'
,
'banana'
),
'category'
=>
'article_category'
));
'name'
=>
'bar baz'
,
'body'
=>
'foo'
,
'type'
=>
'article'
,
'keywords'
=>
array
(
'orange'
,
'strawberry'
,
'grape'
,
'banana'
),
'category'
=>
'article_category'
,
));
$this
->
entities
[
5
]
->
save
();
$count
=
\Drupal
::
entityQuery
(
'entity_test'
)
->
count
()
->
execute
()
-
$count
;
$this
->
assertEqual
(
$count
,
5
,
"
$count
items inserted."
);
...
...
@@ -95,33 +94,4 @@ trait ExampleContentTrait {
return
$index
->
indexItems
();
}
/**
* Returns the internal field ID for the given entity field name.
*
* @param string $field_name
* The field name.
*
* @return string
* The internal field ID.
*/
protected
function
getFieldId
(
$field_name
)
{
return
Utility
::
createCombinedId
(
'entity:entity_test'
,
$field_name
);
}
/**
* Returns the item IDs for the given entity IDs.
*
* @param array $entity_ids
* An array of entity IDs.
*
* @return string[]
* An array of item IDs.
*/
protected
function
getItemIds
(
array
$entity_ids
)
{
$translate_ids
=
function
(
$entity_id
)
{
return
Utility
::
createCombinedId
(
'entity:entity_test'
,
$entity_id
.
':en'
);
};
return
array_map
(
$translate_ids
,
$entity_ids
);
}
}
src/Tests/FacetSourceTest.php
View file @
7bd666e7
...
...
@@ -29,7 +29,7 @@ class FacetSourceTest extends FacetWebTestBase {
];
/**
* Test the facet source editing.
* Test
s
the facet source editing.
*/
public
function
testEditFilterKey
()
{
// Make sure we're logged in with a user that has sufficient permissions.
...
...
@@ -42,16 +42,16 @@ class FacetSourceTest extends FacetWebTestBase {
// Test the edit page.
$edit
=
array
(
'filter
K
ey'
=>
'fq'
,
'filter
_k
ey'
=>
'fq'
,
);
$this
->
assertField
(
'filter
K
ey'
);
$this
->
assertField
(
'url
P
rocessor'
);
$this
->
assertField
(
'filter
_k
ey'
);
$this
->
assertField
(
'url
_p
rocessor'
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
// Test that saving worked filterkey has the new value
$this
->
assertField
(
'filter
K
ey'
);
$this
->
assertField
(
'url
P
rocessor'
);
// Test that saving worked filter
_
key has the new value
.
$this
->
assertField
(
'filter
_k
ey'
);
$this
->
assertField
(
'url
_p
rocessor'
);
$this
->
assertRaw
(
'fq'
);
}
...
...
@@ -69,17 +69,17 @@ class FacetSourceTest extends FacetWebTestBase {
// Test the edit page.
$edit
=
array
(
'url
P
rocessor'
=>
'dummy_query'
,
'url
_p
rocessor'
=>
'dummy_query'
,
);
$this
->
assertField
(
'filter
K
ey'
);
$this
->
assertField
(
'url
P
rocessor'
);
$this
->
assertField
(
'filter
_k
ey'
);
$this
->
assertField
(
'url
_p
rocessor'
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
// Test that saving worked and that the url processor has the new value.
$this
->
assertField
(
'filter
K
ey'
);
$this
->
assertField
(
'url
P
rocessor'
);
$elements
=
$this
->
xpath
(
'//input[@id=:id]'
,
[
':id'
=>
'edit-urlprocessor-dummy-query'
]);
$this
->
assertField
(
'filter
_k
ey'
);
$this
->
assertField
(
'url
_p
rocessor'
);
$elements
=
$this
->
xpath
(
'//input[@id=:id]'
,
[
':id'
=>
'edit-url
-
processor-dummy-query'
]);
$this
->
assertEqual
(
'dummy_query'
,
$elements
[
0
][
'value'
]);
}
...
...
src/Tests/IntegrationTest.php
View file @
7bd666e7
...
...
@@ -71,9 +71,10 @@ class IntegrationTest extends FacetWebTestBase {
// Check if the overview is empty.
$this
->
checkEmptyOverview
();
// Add a new facet and edit it.
// Add a new facet and edit it.
Check adding a duplicate.
$this
->
addFacet
(
$facet_name
);
$this
->
editFacet
(
$facet_name
);
$this
->
addFacetDuplicate
(
$facet_name
);
// By default, the view should show all entities.
$this
->
drupalGet
(
'search-api-test-fulltext'
);
...
...
@@ -289,6 +290,203 @@ class IntegrationTest extends FacetWebTestBase {
$this
->
assertNoLink
(
'orange'
);
}
/**
* Tests the facet's and/or functionality.
*/
public
function
testAndOrFacet
()
{
$facet_name
=
'test & facet'
;
$facet_id
=
'test_facet'
;
$facet_edit_page
=
'admin/config/search/facets/'
.
$facet_id
.
'/display'
;
$this
->
drupalLogin
(
$this
->
adminUser
);
$this
->
addFacet
(
$facet_name
);
$this
->
createFacetBlock
(
'test_facet'
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
drupalPostForm
(
NULL
,
[
'facet_settings[query_operator]'
=>
'AND'
],
$this
->
t
(
'Save'
));
$this
->
insertExampleContent
();
$this
->
assertEqual
(
$this
->
indexItems
(
$this
->
indexId
),
5
,
'5 items were indexed.'
);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item'
);
$this
->
assertLink
(
'article'
);
$this
->
clickLink
(
'item'
);
$this
->
assertLink
(
'(-) item'
);
$this
->
assertNoLink
(
'article'
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
drupalPostForm
(
NULL
,
[
'facet_settings[query_operator]'
=>
'OR'
],
$this
->
t
(
'Save'
));
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item'
);
$this
->
assertLink
(
'article'
);
$this
->
clickLink
(
'item'
);
$this
->
assertLink
(
'(-) item'
);
$this
->
assertLink
(
'article'
);
}
/**
* Tests that we disallow unwanted values.
*/
public
function
testUnwantedValues
()
{
// Go to the Add facet page and make sure that returns a 200.
$facet_add_page
=
'/admin/config/search/facets/add-facet'
;
$this
->
drupalGet
(
$facet_add_page
);
$this
->
assertResponse
(
200
);
// Configure the facet source by selecting one of the search api views.
$this
->
drupalGet
(
$facet_add_page
);
$this
->
drupalPostForm
(
NULL
,
[
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
],
$this
->
t
(
'Configure facet source'
));
// Fill in all fields and make sure the 'field is required' message is no
// longer shown.
$facet_source_form
=
[
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
,
'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]'
=>
'type'
,
];
$this
->
drupalPostForm
(
NULL
,
$facet_source_form
,
$this
->
t
(
'Save'
));
$form_values
=
[
'name'
=>
'name 1'
,
'id'
=>
'name 1'
,
'status'
=>
1
,
'url_alias'
=>
'name'
,
];
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
assertText
(
$this
->
t
(
'The machine-readable name must contain only lowercase letters, numbers, and underscores.'
));
$form_values
=
[
'name'
=>
'name 1'
,
'id'
=>
'name:&1'
,
'status'
=>
1
,
'url_alias'
=>
'name'
,
];
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
assertText
(
$this
->
t
(
'The machine-readable name must contain only lowercase letters, numbers, and underscores.'
));
$form_values
=
[
'name'
=>
'name 1'
,
'id'
=>
'name_1'
,
'status'
=>
1
,
'url_alias'
=>
'name:1'
,
];
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
assertText
(
$this
->
t
(
'The machine-readable name must contain only lowercase letters, numbers, and underscores.'
));
$form_values
=
[
'name'
=>
'name 1'
,
'id'
=>
'name_1'
,
'status'
=>
1
,
'url_alias'
=>
'name_1'
,
];
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
assertNoText
(
$this
->
t
(
'The machine-readable name must contain only lowercase letters, numbers, and underscores.'
));
}
/**
* Tests for processor integration.
*/
public
function
testProcessorIntegration
()
{
$facet_name
=
"Snowy owl~"
;
$facet_id
=
"snowy_owl_"
;
$this
->
addFacet
(
$facet_name
);
// Go to the processors form and check that the count limit processor is not
// checked.
$this
->
drupalGet
(
'admin/config/search/facets/'
.
$facet_id
.
'/display'
);
$this
->
assertNoFieldChecked
(
'edit-facet-settings-count-limit-status'
);
$form
=
[
'facet_settings[count_limit][status]'
=>
TRUE
];
$this
->
drupalPostForm
(
NULL
,
$form
,
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
$this
->
assertFieldChecked
(
'edit-facet-settings-count-limit-status'
);
// Enable the sort processor and change sort direction.
// Test that the sort settings change persisted.
$form
=
[
'facet_sorting[active_widget_order][status]'
=>
TRUE
,
'facet_sorting[active_widget_order][settings][sort]'
=>
'DESC'
,
];
$this
->
drupalPostForm
(
NULL
,
$form
,
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
$this
->
assertFieldChecked
(
'edit-facet-sorting-active-widget-order-status'
);
$this
->
assertFieldChecked
(
'edit-facet-sorting-active-widget-order-settings-sort-desc'
);
// Add an extra processor so we can test the weights as well.
$form
=
[
'facet_settings[hide_non_narrowing_result_processor][status]'
=>
TRUE
,
'facet_settings[count_limit][status]'
=>
TRUE
,
];
$this
->
drupalPostForm
(
NULL
,
$form
,
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
$this
->
assertFieldChecked
(
'edit-facet-settings-count-limit-status'
);
$this
->
assertFieldChecked
(
'edit-facet-settings-hide-non-narrowing-result-processor-status'
);
$this
->
assertOptionSelected
(
'edit-processors-count-limit-weights-build'
,
-
10
);
$this
->
assertOptionSelected
(
'edit-processors-hide-non-narrowing-result-processor-weights-build'
,
-
10
);
// Change the weight of one of the processors and test that the weight
// change persisted.
$form
=
[
'facet_settings[hide_non_narrowing_result_processor][status]'
=>
TRUE
,
'facet_settings[count_limit][status]'
=>
TRUE
,
'processors[hide_non_narrowing_result_processor][weights][build]'
=>
5
,
];
$this
->
drupalPostForm
(
NULL
,
$form
,
$this
->
t
(
'Save'
));
$this
->
assertFieldChecked
(
'edit-facet-settings-count-limit-status'
);
$this
->
assertFieldChecked
(
'edit-facet-settings-hide-non-narrowing-result-processor-status'
);
$this
->
assertOptionSelected
(
'edit-processors-count-limit-weights-build'
,
-
10
);
$this
->
assertOptionSelected
(
'edit-processors-hide-non-narrowing-result-processor-weights-build'
,
5
);
}
/**
* Tests the facet's exclude functionality.
*/
public
function
testExcludeFacet
()
{
$facet_name
=
'test & facet'
;
$facet_id
=
'test_facet'
;
$facet_edit_page
=
'admin/config/search/facets/'
.
$facet_id
.
'/display'
;
$this
->
addFacet
(
$facet_name
);
$this
->
createFacetBlock
(
$facet_id
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
assertNoFieldChecked
(
'edit-facet-settings-exclude'
);
$this
->
drupalPostForm
(
NULL
,
[
'facet_settings[exclude]'
=>
TRUE
],
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
$this
->
assertFieldChecked
(
'edit-facet-settings-exclude'
);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertText
(
'foo bar baz'
);
$this
->
assertText
(
'foo baz'
);
$this
->
assertLink
(
'item'
);
$this
->
clickLink
(
'item'
);
$this
->
assertLink
(
'(-) item'
);
$this
->
assertText
(
'foo baz'
);
$this
->
assertText
(
'bar baz'
);
$this
->
assertNoText
(
'foo bar baz'
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
drupalPostForm
(
NULL
,
[
'facet_settings[exclude]'
=>
FALSE
],
$this
->
t
(
'Save'
));
$this
->
assertResponse
(
200
);
$this
->
assertNoFieldChecked
(
'edit-facet-settings-exclude'
);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertText
(
'foo bar baz'
);
$this
->
assertText
(
'foo baz'
);
$this
->
assertLink
(
'item'
);
$this
->
clickLink
(
'item'
);
$this
->
assertLink
(
'(-) item'
);
$this
->
assertText
(
'foo bar baz'
);
$this
->
assertText
(
'foo test'
);
$this
->
assertText
(
'bar'
);
$this
->
assertNoText
(
'foo baz'
);
}
/**
* Deletes a facet block by id.
*
...
...
@@ -303,7 +501,7 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
*
Helper function: a
sserts that a facet block does not appear.
*
A
sserts that a facet block does not appear.
*/
protected
function
assertNoFacetBlocksAppear
()
{
foreach
(
$this
->
blocks
as
$block
)
{
...
...
@@ -312,7 +510,7 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
*
Helper function: a
sserts that a facet block appears.
*
A
sserts that a facet block appears.
*/
protected
function
assertFacetBlocksAppear
()
{
foreach
(
$this
->
blocks
as
$block
)
{
...
...
@@ -383,7 +581,7 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
*
Get the facet overview page and make sure the
overview is empty.
*
Tests that the facet
overview is empty.
*/
protected
function
checkEmptyOverview
()
{
$facet_overview
=
'/admin/config/search/facets'
;
...
...
@@ -451,13 +649,47 @@ class IntegrationTest extends FacetWebTestBase {
$this
->
drupalGet
(
'admin/config/search/facets'
);
}
/**
* Tests creating a facet with an existing machine name.
*
* @param string $facet_name
* The name of the facet.
*/
protected
function
addFacetDuplicate
(
$facet_name
,
$facet_type
=
'type'
)
{
$facet_id
=
$this
->
convertNameToMachineName
(
$facet_name
);
$facet_add_page
=
'/admin/config/search/facets/add-facet'
;
$this
->
drupalGet
(
$facet_add_page
);
$form_values
=
[
'name'
=>
$facet_name
,
'id'
=>
$facet_id
,
'url_alias'
=>
$facet_id
,
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
,
];
$facet_source_configs
[
'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]'
]
=
$facet_type
;
// Try to submit a facet with a duplicate machine name after form rebuilding
// via facet source submit.
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Configure facet source'
));
$this
->
drupalPostForm
(
NULL
,
$form_values
+
$facet_source_configs
,
$this
->
t
(
'Save'
));
$this
->
assertText
(
$this
->
t
(
'The machine-readable name is already in use. It must be unique.'
));
// Try to submit a facet with a duplicate machine name after form rebuilding
// via facet source submit using AJAX.
$this
->
drupalPostAjaxForm
(
NULL
,
$form_values
,
array
(
'facet_source_configure'
=>
t
(
'Configure facet source'
)));
$this
->
drupalPostForm
(
NULL
,
$form_values
+
$facet_source_configs
,
$this
->
t
(
'Save'
));
$this
->
assertText
(
$this
->
t
(
'The machine-readable name is already in use. It must be unique.'
));
}
/**
* Tests editing of a facet through the UI.
*
* @param string $facet_name
* The name of the facet.
*/
p
ublic
function
editFacet
(
$facet_name
)
{
p
rotected
function
editFacet
(
$facet_name
)
{
$facet_id
=
$this
->
convertNameToMachineName
(
$facet_name
);
$facet_edit_page
=
'/admin/config/search/facets/'
.
$facet_id
.
'/edit'
;
...
...
@@ -489,7 +721,7 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
*
This d
eletes a
n unused
facet through the UI.
*
D
eletes a facet through the UI
that still has usages
.
*
* @param string $facet_name
* The name of the facet.
...
...
@@ -510,7 +742,7 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
*
This d
eletes a facet through the UI.
*
D
eletes a facet through the UI.
*
* @param string $facet_name
* The name of the facet.
...
...
src/Tests/UrlIntegrationTest.php
View file @
7bd666e7
...
...
@@ -8,6 +8,7 @@
namespace
Drupal\facets\Tests
;
use
Drupal\Core\Url
;
use
Drupal\facets\FacetInterface
;
use
Drupal\facets\Tests\WebTestBase
as
FacetWebTestBase
;
use
Drupal\facets\Entity\Facet
;
use
Drupal\facets\FacetSourceInterface
;
...
...
@@ -72,7 +73,7 @@ class UrlIntegrationTest extends FacetWebTestBase {
'settings'
=>
[
'region'
=>
'footer'
,
'id'
=>
str_replace
(
'_'
,
'-'
,
$id
),
]
]
,
];
$this
->
drupalPlaceBlock
(
$block_values
[
'plugin_id'
],
$block_values
[
'settings'
]);
...
...
@@ -81,6 +82,7 @@ class UrlIntegrationTest extends FacetWebTestBase {
/** @var \Drupal\facets\FacetInterface $facet */
$facet
=
Facet
::
load
(
$id
);
$this
->
assertTrue
(
$facet
instanceof
FacetInterface
);
$config
=
$facet
->
getFacetSourceConfig
();
$this
->
assertTrue
(
$config
instanceof
FacetSourceInterface
);
$this
->
assertEqual
(
NULL
,
$config
->
getFilterKey
());
...
...
@@ -93,8 +95,8 @@ class UrlIntegrationTest extends FacetWebTestBase {
$this
->
clickLink
(
$this
->
t
(
'Configure'
));
$edit
=
[
'filter
K
ey'
=>
'y'
,
'url
P
rocessor'
=>
'query_string'
,
'filter
_k
ey'
=>
'y'
,
'url
_p
rocessor'
=>
'query_string'
,
];
$this
->
drupalPostForm
(
NULL
,
$edit
,
$this
->
t
(
'Save'
));
...
...
@@ -116,8 +118,8 @@ class UrlIntegrationTest extends FacetWebTestBase {
$this
->
clickLink
(
$this
->
t
(
'Configure'
));
$edit
=
[
'filter
K
ey'
=>
'y'
,
'url
P
rocessor'
=>
'dummy_query'
,
'filter
_k
ey'
=>
'y'
,
'url
_p
rocessor'
=>
'dummy_query'
,
];
$this
->
drupalPostForm
(
NULL
,
$edit
,
$this
->
t
(
'Save'
));
...
...
@@ -150,7 +152,7 @@ class UrlIntegrationTest extends FacetWebTestBase {
$this
->
assertResponse
(
200
);
$this
->
assertLink
(
'(-) item'
);
$this
->
assert
No
Link
(
'article'
);
$this
->
assertLink
(
'article'
);
$this
->
assertUrl
(
$url
);
}
...
...
src/Tests/WebTestBase.php
View file @
7bd666e7
...
...
@@ -20,15 +20,6 @@ abstract class WebTestBase extends SimpletestWebTestBase {
use
StringTranslationTrait
;
use
ExampleContentTrait
;
/**
* Exempt from strict schema checking.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected
$strictConfigSchema
=
FALSE
;
/**
* Modules to enable for this test.
*
...
...
src/Tests/WidgetIntegrationTest.php
View file @
7bd666e7
...
...
@@ -70,7 +70,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'settings'
=>
[
'region'
=>
'footer'
,
'id'
=>
str_replace
(
'_'
,
'-'
,
$id
),
]
]
,
];
$this
->
drupalPlaceBlock
(
$block_values
[
'plugin_id'
],
$block_values
[
'settings'
]);
...
...
@@ -79,4 +79,98 @@ class WidgetIntegrationTest extends FacetWebTestBase {
$this
->
assertFieldChecked
(
'edit-type-item'
);
}
/**
* Tests links widget's basic functionality.
*/
public
function
testLinksWidget
()
{
$id
=
'links_widget'
;
$name
=
'>.Facet &* Links'
;
$facet_add_page
=
'admin/config/search/facets/add-facet'
;
$this
->
drupalGet
(
$facet_add_page
);
$form_values
=
[
'id'
=>
$id
,
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
,
'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]'
=>
'type'
,
];
$this
->
drupalPostForm
(
NULL
,
[
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
],
$this
->
t
(
'Configure facet source'
));
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
drupalPostForm
(
NULL
,
[
'widget'
=>
'links'
],
$this
->
t
(
'Save'
));
$block_values
=
[
'plugin_id'
=>
'facet_block:'
.
$id
,
'settings'
=>
[
'region'
=>
'footer'
,
'id'
=>
str_replace
(
'_'
,
'-'
,
$id
),
],
];
$this
->
drupalPlaceBlock
(
$block_values
[
'plugin_id'
],
$block_values
[
'settings'
]);
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item'
);
$this
->
assertLink
(
'article'
);
$this
->
clickLink
(
'item'
);
$this
->
assertLink
(
'(-) item'
);
}
/**
* Tests the functionality of a widget to hide/show the item-count.
*/
public
function
testLinksShowHideCount
()
{
$id
=
'links_widget'
;
$name
=
'>.Facet &* Links'
;
$facet_add_page
=
'admin/config/search/facets/add-facet'
;
$facet_edit_page
=
'admin/config/search/facets/'
.
$id
.
'/display'
;
$this
->
drupalGet
(
$facet_add_page
);
$form_values
=
[
'id'
=>
$id
,
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
,
'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]'
=>
'type'
,
];
$this
->
drupalPostForm
(
NULL
,
[
'facet_source_id'
=>
'search_api_views:search_api_test_view:page_1'
],
$this
->
t
(
'Configure facet source'
));
$this
->
drupalPostForm
(
NULL
,
$form_values
,
$this
->
t
(
'Save'
));
$this
->
drupalPostForm
(
NULL
,
[
'widget'
=>
'links'
],
$this
->
t
(
'Save'
));
$block_values
=
[
'plugin_id'
=>
'facet_block:'
.
$id
,
'settings'
=>
[
'region'
=>
'footer'
,
'id'
=>
str_replace
(
'_'
,
'-'
,
$id
),
],
];
$this
->
drupalPlaceBlock
(
$block_values
[
'plugin_id'
],
$block_values
[
'settings'
]);
// Go to the view and check that the facet links are shown with their
// default settings.
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item'
);
$this
->
assertLink
(
'article'
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
drupalPostForm
(
NULL
,
[
'widget'
=>
'links'
,
'widget_configs[show_numbers]'
=>
TRUE
],
$this
->
t
(
'Save'
));
// Go back to the same view and check that links now display the count.
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item (3)'
);
$this
->
assertLink
(
'article (2)'
);
$this
->
drupalGet
(
$facet_edit_page
);
$this
->
drupalPostForm
(
NULL
,
[
'widget'
=>
'links'
,
'widget_configs[show_numbers]'
=>
FALSE
],
$this
->
t
(
'Save'
));
// The count should be hidden again.
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertLink
(
'item'
);
$this
->
assertLink
(
'article'
);
}
}
src/UrlProcessor/UrlProcessorInterface.php
View file @
7bd666e7
...
...
@@ -42,6 +42,7 @@ interface UrlProcessorInterface {
* remembered when building the facet's urls.
*
* @param \Drupal\facets\FacetInterface $facet
* The facet that is edited.
*/
public
function
setActiveItems
(
FacetInterface
$facet
);
...
...
src/Widget/WidgetInterface.php
View file @
7bd666e7
...
...
@@ -14,7 +14,7 @@ use Drupal\facets\FacetInterface;
interface
WidgetInterface
{
/**
* Add facet info to the query using the selected query type.
* Add
s
facet info to the query using the selected query type.
*
* @return mixed
* A boolean
...
...
@@ -33,7 +33,7 @@ interface WidgetInterface {
public
function
build
(
FacetInterface
$facet
);
/**
* Pick the preferred query type for this widget.
* Pick
s
the preferred query type for this widget.
*
* @param string[] $query_types
* An array keyed with query type name and it's plugin class to load.
...
...
tests/facets_query_processor/src/Plugin/facets/url_processor/DummyQuery.php
View file @
7bd666e7
...
...
@@ -33,7 +33,7 @@ class DummyQuery extends UrlProcessorPluginBase {
*
* @var string
*/
protected
$url
_a
lias
;
protected
$url
A
lias
;
/**
* An array of active filters.
...
...
@@ -60,7 +60,7 @@ class DummyQuery extends UrlProcessorPluginBase {
$get_params
=
$this
->
request
->
query
;
// Set the url alias from the the facet object.
$this
->
url
_a
lias
=
$facet
->
getUrlAlias
();
$this
->
url
A
lias
=
$facet
->
getUrlAlias
();
// No results are found for this facet, so don't try to create urls.
if
(
empty
(
$results
))
{
...
...
@@ -69,7 +69,7 @@ class DummyQuery extends UrlProcessorPluginBase {
/** @var \Drupal\facets\Result\ResultInterface $result */
foreach
(
$results
as
&
$result
)
{
$filter_string
=
$this
->
url
_a
lias
.
self
::
SEPARATOR
.
$result
->
getRawValue
();
$filter_string
=
$this
->
url
A
lias
.
self
::
SEPARATOR
.
$result
->
getRawValue
();
$result_get_params
=
clone
$get_params
;
$filter_params
=
$result_get_params
->
get
(
$this
->
filterKey
,
[],
TRUE
);
...
...
@@ -105,18 +105,18 @@ class DummyQuery extends UrlProcessorPluginBase {
*/
public
function
setActiveItems
(
FacetInterface
$facet
)
{
// Set the url alias from the the facet object.
$this
->
url
_a
lias
=
$facet
->
getUrlAlias
();
$this
->
url
A
lias
=
$facet
->
getUrlAlias
();
// Get the filter key of the facet.
if
(
isset
(
$this
->
activeFilters
[
$this
->
url
_a
lias
]))
{
foreach
(
$this
->
activeFilters
[
$this
->
url
_a
lias
]
as
$value
)
{
if
(
isset
(
$this
->
activeFilters
[
$this
->
url
A
lias
]))
{
foreach
(
$this
->
activeFilters
[
$this
->
url
A
lias
]
as
$value
)
{
$facet
->
setActiveItem
(
trim
(
$value
,
'"'
));
}
}
}
/**
* Initialize the active filters.
* Initialize
s
the active filters.
*
* Get all the filters that are active. This method only get's all the
* filters but doesn't assign them to facets. In the processFacet method the
...
...
tests/facets_search_api_dependency/config/install/views.view.search_api_test_views_fulltext.yml
View file @
7bd666e7
...
...
@@ -19,8 +19,8 @@ display:
query
:
type
:
search_api_query
options
:
search_api_
bypass_access
:
fals
e
entity
_access
:
fals
e
bypass_access
:
tru
e
skip
_access
:
tru
e
parse_mode
:
terms
exposed_form
:
type
:
basic
...
...
tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
View file @
7bd666e7
...
...
@@ -87,7 +87,8 @@ class FacetSourcePluginManagerTest extends UnitTestCase {
*/
public
function
testConstruct
()
{
$namespaces
=
new
ArrayObject
();
$this
->
sut
=
new
FacetSourcePluginManager
(
$namespaces
,
$this
->
cache
,
$this
->
moduleHandler
);
$sut
=
new
FacetSourcePluginManager
(
$namespaces
,
$this
->
cache
,
$this
->
moduleHandler
);
$this
->
assertInstanceOf
(
'\Drupal\facets\FacetSource\FacetSourcePluginManager'
,
$sut
);
}
/**
...
...
tests/src/Unit/Plugin/Condition/OtherFacetTest.php
View file @
7bd666e7
...
...
@@ -186,4 +186,5 @@ class OtherFacetTest extends UnitTestCase {
$evaluation
=
$sut
->
evaluate
();
$this
->
assertFalse
(
$evaluation
);
}
}
Prev
1
2
3
4
Next