Skip to content

Commit b31cd83

Browse files
authored
lint codebase, add lint/test to CI, add some tests (Islandora#86)
* Add lint/test CI * phpcbf * phpcs * Add some tests * fix bug
1 parent bd31da7 commit b31cd83

15 files changed

Lines changed: 1196 additions & 497 deletions

.github/workflows/build-2.x.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ 2.x ]
6+
pull_request:
7+
branches: [ 2.x ]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-24.04
17+
continue-on-error: false
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php-versions: ["8.3", "8.4"]
22+
drupal-version: ["10.5", "10.6", "11.2", "11.3"]
23+
name: PHP ${{ matrix.php-versions }} | drupal ${{ matrix.drupal-version }}
24+
steps:
25+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
26+
27+
- name: create docker network
28+
run: docker network create ci-default
29+
30+
- name: Start chromedriver
31+
run: |-
32+
docker run -d \
33+
--name chromedriver \
34+
--network ci-default \
35+
drupalci/webdriver-chromedriver:production \
36+
chromedriver --log-path=/dev/null --verbose --allowed-ips= --allowed-origins=*
37+
38+
- name: PHPUNIT tests
39+
run: |
40+
docker run \
41+
--rm \
42+
--name drupal \
43+
--hostname drupal \
44+
--volume $(pwd):/var/www/drupal/web/modules/contrib/$ENABLE_MODULES:ro \
45+
--env ENABLE_MODULES \
46+
--network ci-default \
47+
ghcr.io/islandora/ci:${{ matrix.drupal-version }}-php${{ matrix.php-versions }}
48+
env:
49+
ENABLE_MODULES: advanced_search

advanced_search.module

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use Drupal\Core\Form\FormStateInterface;
1818
use Drupal\advanced_search\AdvancedSearchQuery;
1919
use Drupal\advanced_search\Form\SettingsForm;
2020
use Drupal\advanced_search\Utilities;
21-
use Drupal\search_api\Query\QueryInterface as DrupalQueryInterface;
2221
use Drupal\views\ViewExecutable;
23-
use Solarium\Core\Query\QueryInterface as SolariumQueryInterface;
2422

2523
/**
2624
* Implements hook_theme().

src/AdvancedSearchQuery.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
151151
$field_mapping = $backend->getSolrFieldNamesKeyedByLanguage($language_ids, $index);
152152

153153
// Disable for Lucene and wildcard
154-
//$q[] = "{!boost b=boost_document}";
155-
154+
// $q[] = "{!boost b=boost_document}";
156155
// Create a flag for active/inactive dismax.
157156
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
158157
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
@@ -207,10 +206,11 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
207206
if ($isSearchAllFields) {
208207
// Get configured query fields from settings.
209208
$configured_query_fields = $config->get(SettingsForm::QUERY_FIELDS) ?: [];
210-
211-
// field_mapping structure: [field_id => [language => solr_field_name]]
209+
210+
// field_mapping structure:
211+
// [field_id => [language => solr_field_name]].
212212
foreach ($field_mapping as $field_id => $languages) {
213-
foreach ($languages as $lang => $solr_field_name) {
213+
foreach ($languages as $solr_field_name) {
214214
// bs_ are boolean fields, do not work well with text search.
215215
if (substr($solr_field_name, 0, 3) !== "bs_") {
216216

@@ -230,7 +230,7 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
230230
$dismax->setQueryFields($query_fields);
231231
}
232232

233-
// if all fields are searched, use the query_fields for highlighting.
233+
// If all fields are searched, use the query_fields for highlighting.
234234
if ($isSearchAllFields && isset($query_fields)) {
235235
// Convert back to an array.
236236
$highlight_source_fields = explode(" ", $query_fields);
@@ -241,7 +241,7 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
241241

242242
if ($backend->getConfiguration()['highlight_data']) {
243243
// Just highlight string and text fields to avoid Solr exceptions.
244-
// Exclude tm_X3b_*_fulltext_title
244+
// Exclude tm_X3b_*_fulltext_title.
245245
$highlighted_fields = array_filter(array_unique($highlight_source_fields), function ($v) {
246246
return !empty($v) && (preg_match('/^t.*?[sm]_/', $v) || preg_match('/^s[sm]_/', $v)) && !preg_match('/^tm_X3b_.*_fulltext_title$/', $v);
247247
});
@@ -256,7 +256,7 @@ public function alterQuery(Request $request, SolariumQueryInterface &$solarium_q
256256
// Since we are getting the highlighting result from Solr instead
257257
// of using the Search API processor to create one, we just need
258258
// make this field non-empty.
259-
//$search_api_query->keys("advanced search");
259+
// $search_api_query->keys("advanced search");.
260260
}
261261

262262
$solarium_query->setQuery($q);

src/AdvancedSearchQueryTerm.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ public function toSolrQuery(array $solr_field_mapping) {
321321
}
322322
}
323323
// Fixed for https://github.com/digitalutsc/advanced_search/issues/4
324-
if ($this->field !== "all"){
324+
if ($this->field !== "all") {
325325
$search_fields = "(";
326326
foreach ($solr_field_mapping[$this->field] as $field) {
327-
$search_fields .= " $field:$value";
327+
$search_fields .= " $field:$value";
328328
}
329329
$search_fields .= ")";
330330
return $search_fields;
@@ -386,7 +386,6 @@ public function toSolrQuery(array $solr_field_mapping) {
386386
*/
387387
public function toSolrFields(array $solr_field_mapping) {
388388
$terms = [];
389-
$query_helper = \Drupal::service('solarium.query_helper');
390389

391390
if ($this->field !== "all") {
392391
foreach ($solr_field_mapping[$this->field] as $field) {

src/Controller/AjaxBlocksController.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\Core\Routing\CurrentRouteMatch;
1212
use Symfony\Component\DependencyInjection\ContainerInterface;
1313
use Symfony\Component\HttpFoundation\Request;
14+
use Symfony\Component\HttpFoundation\RequestStack;
1415
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1516
use Symfony\Component\Routing\RouterInterface;
1617

@@ -68,6 +69,13 @@ class AjaxBlocksController extends ControllerBase {
6869
*/
6970
protected $container;
7071

72+
/**
73+
* The request stack.
74+
*
75+
* @var \Symfony\Component\HttpFoundation\RequestStack
76+
*/
77+
protected $requestStack;
78+
7179
/**
7280
* Constructs a FacetBlockAjaxController object.
7381
*
@@ -83,15 +91,26 @@ class AjaxBlocksController extends ControllerBase {
8391
* The current route match service.
8492
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
8593
* The drupal container.
94+
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
95+
* The request stack.
8696
*/
87-
final public function __construct(RendererInterface $renderer, CurrentPathStack $currentPath, RouterInterface $router, PathProcessorManager $pathProcessor, CurrentRouteMatch $currentRouteMatch, ContainerInterface $container) {
97+
final public function __construct(
98+
RendererInterface $renderer,
99+
CurrentPathStack $currentPath,
100+
RouterInterface $router,
101+
PathProcessorManager $pathProcessor,
102+
CurrentRouteMatch $currentRouteMatch,
103+
ContainerInterface $container,
104+
RequestStack $request_stack,
105+
) {
88106
$this->storage = $this->entityTypeManager()->getStorage('block');
89107
$this->renderer = $renderer;
90108
$this->currentPath = $currentPath;
91109
$this->router = $router;
92110
$this->pathProcessor = $pathProcessor;
93111
$this->currentRouteMatch = $currentRouteMatch;
94112
$this->container = $container;
113+
$this->requestStack = $request_stack;
95114
}
96115

97116
/**
@@ -104,7 +123,8 @@ public static function create(ContainerInterface $container) {
104123
$container->get('router'),
105124
$container->get('path_processor_manager'),
106125
$container->get('current_route_match'),
107-
$container
126+
$container,
127+
$container->get('request_stack')
108128
);
109129
}
110130

@@ -136,7 +156,7 @@ public function respond(Request $request) {
136156

137157
$new_request = Request::create($path);
138158
$new_request->setSession($request->getSession());
139-
$request_stack = \Drupal::requestStack();
159+
$request_stack = $this->requestStack;
140160
$processed = $this->pathProcessor->processInbound($new_request->getPathInfo(), $new_request);
141161

142162
$this->currentPath->setPath($processed);

0 commit comments

Comments
 (0)