Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Drupal Rector to Islandora. #943

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,3 @@ jobs:
run: |
cd $DRUPAL_DIR/web/core
$DRUPAL_DIR/vendor/bin/phpunit --verbose --testsuite "${{ matrix.test-suite }}"

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function islandora_advanced_search_theme() {
function islandora_advanced_search_library_info_alter(&$libraries, $extension) {
if ($extension == 'facets') {
// Override facets module javascript with customizations.
$path = '/' . drupal_get_path('module', 'islandora_advanced_search') . '/js/facets';
$path = '/' . \Drupal::service('extension.list.module')->getPath('islandora_advanced_search') . '/js/facets';
$libraries['soft-limit']['js'] = [
"$path/soft-limit.js" => [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function testGenerateAudioDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'islandora_breadcrumbs',
];

Expand Down Expand Up @@ -56,7 +56,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create some nodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,3 @@ display:
- url.query_args
- user.permissions
tags: { }

Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,3 @@ display:
- url
- user.permissions
tags: { }

Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,3 @@ display:
- url.query_args
- user.permissions
tags: { }

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function testGenerateImageDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\File\FileSystem;
use Drupal\Core\File\FileSystemInterface;
use Drupal\file\FileRepository;
use Drupal\media\Entity\Media;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -42,14 +43,24 @@ class MediaSourceController extends ControllerBase {
*/
protected $fileSystem;

/**
* File repository service.
*
* @var \Drupal\file\FileRepository
*/
protected $fileRepository;

/**
* MediaSourceController constructor.
*
* @param \Drupal\Core\File\FileSystem $fileSystem
* Filesystem service.
* @param \Drupal\file\FileRepository $fileRepository
* File Repository service.
*/
public function __construct(FileSystem $fileSystem) {
public function __construct(FileSystem $fileSystem, FileRepository $fileRepository) {
$this->fileSystem = $fileSystem;
$this->fileRepository = $fileRepository;
}

/**
Expand All @@ -63,7 +74,8 @@ public function __construct(FileSystem $fileSystem) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('file_system')
$container->get('file_system'),
$container->get('file.repository'),
);
}

Expand Down Expand Up @@ -98,7 +110,7 @@ public function attachToMedia(
if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable");
}
$file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE);
$file = $this->fileRepository->writeData($contents, $content_location, FileSystemInterface::EXISTS_REPLACE);
if ($media->hasField($destination_field)) {
$media->{$destination_field}->setValue([
'target_id' => $file->id(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LoadTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = ['islandora_text_extraction'];
protected static $modules = ['islandora_text_extraction'];

/**
* A user with permission to administer site configuration.
Expand All @@ -29,7 +29,7 @@ class LoadTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function testGenerateVideoDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/LinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
Expand All @@ -13,7 +14,6 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -312,9 +312,9 @@ protected function generateRestLinks(EntityInterface $entity) {
/**
* Adds resource-specific link headers to appropriate responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* Event containing the response.
*/
abstract public function onResponse(FilterResponseEvent $event);
abstract public function onResponse(ResponseEvent $event);

}
4 changes: 2 additions & 2 deletions src/EventSubscriber/MediaLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\Core\Url;
use Drupal\media\MediaInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

/**
* Subscribes to MediaLinkHeader Event.
Expand All @@ -17,7 +17,7 @@ class MediaLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSub
/**
* {@inheritdoc}
*/
public function onResponse(FilterResponseEvent $event) {
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();

$media = $this->getObject($response, 'media');
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/NodeLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\node\NodeInterface;
use Drupal\islandora\IslandoraUtils;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand All @@ -17,10 +17,10 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs
/**
* Adds node-specific link headers to appropriate responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* Event containing the response.
*/
public function onResponse(FilterResponseEvent $event) {
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();

$node = $this->getObject($response, 'node');
Expand Down
14 changes: 8 additions & 6 deletions src/Flysystem/Adapter/FedoraAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\islandora\Flysystem\Adapter;

use GuzzleHttp\Psr7\Header;
use function GuzzleHttp\Psr7\parse_header;
use Drupal\Core\Logger\LoggerChannelInterface;
use Islandora\Chullo\IFedoraApi;
use League\Flysystem\AdapterInterface;
Expand Down Expand Up @@ -159,11 +161,11 @@ protected function getMetadataFromHeaders(Response $response) {
// directory.
$type = 'dir';
// phpcs:disable
if (class_exists(\GuzzleHttp\Psr7\Header::class)) {
$links = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link'));
if (class_exists(Header::class)) {
$links = Header::parse($response->getHeader('Link'));
}
else {
$links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link'));
$links = parse_header($response->getHeader('Link'));
}
// phpcs:enable
foreach ($links as $link) {
Expand Down Expand Up @@ -402,11 +404,11 @@ private function deleteTombstone($path) {
if ($response->getStatusCode() == 410) {
$return = FALSE;
// phpcs:disable
if (class_exists(\GuzzleHttp\Psr7\Header::class)) {
$link_headers = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link'));
if (class_exists(Header::class)) {
$link_headers = Header::parse($response->getHeader('Link'));
}
else {
$link_headers = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link'));
$link_headers = parse_header($response->getHeader('Link'));
}
// phpcs:enable
if ($link_headers) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/AddChildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AddChildTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->parent =
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/AddMediaToNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Functional/ContentEntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function testContentEntityType() {
'name[0][value]' => 'Test Media',
'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));
$this->assertSession()->pageTextNotContains("Hello World!");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/Functional/DeleteMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'media_test_views',
'context_ui',
'field_ui',
Expand Down Expand Up @@ -47,7 +47,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create a test user.
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Functional/DerivativeReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([
Expand Down Expand Up @@ -52,7 +52,8 @@ public function testExecuteDerivativeReaction() {
'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt',
'field_media_of[0][target_id]' => 'Test Node',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

// field_media_of is set and there's a file, so derivatives should fire.
$this->assertSession()->pageTextContains("Hello World!");
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/GenerateDerivativeTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class GenerateDerivativeTestBase extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->createUserAndLogin();
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Functional/IndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IndexingTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create an action that dsm's "Goodbye, Cruel World!".
Expand Down Expand Up @@ -63,9 +63,10 @@ public function testIndexing() {

// Add the Goodbye World reaction.
$this->addPresetReaction('test', 'delete', 'goodbye_world');
$this->drupalGet("$url/delete");

// Delete the node.
$this->drupalPostForm("$url/delete", [], $this->t('Delete'));
$this->submitForm([], $this->t('Delete'));
$this->assertSession()->statusCodeEquals(200);

// Confirm Goodbye, Cruel World! is printed to the screen.
Expand Down
11 changes: 7 additions & 4 deletions tests/src/Functional/IslandoraFunctionalTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class IslandoraFunctionalTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Delete the node rest config that's bootstrapped with Drupal.
Expand Down Expand Up @@ -314,23 +314,26 @@ protected function addPresetReaction($context_id, $reaction_type, $action_id) {
* Create a new node by posting its add form.
*/
protected function postNodeAddForm($bundle_id, $values, $button_text) {
$this->drupalPostForm("node/add/$bundle_id", $values, $this->t('@text', ['@text' => $button_text]));
$this->drupalGet("node/add/$bundle_id");
$this->submitForm($values, $this->t('@text', ['@text' => $button_text]));
$this->assertSession()->statusCodeEquals(200);
}

/**
* Create a new node by posting its add form.
*/
protected function postTermAddForm($taxomony_id, $values, $button_text) {
$this->drupalPostForm("admin/structure/taxonomy/manage/$taxomony_id/add", $values, $this->t('@text', ['@text' => $button_text]));
$this->drupalGet("admin/structure/taxonomy/manage/$taxomony_id/add");
$this->submitForm($values, $this->t('@text', ['@text' => $button_text]));
$this->assertSession()->statusCodeEquals(200);
}

/**
* Edits a node by posting its edit form.
*/
protected function postEntityEditForm($entity_url, $values, $button_text) {
$this->drupalPostForm("$entity_url/edit", $values, $this->t('@text', ['@text' => $button_text]));
$this->drupalGet("$entity_url/edit");
$this->submitForm($values, $this->t('@text', ['@text' => $button_text]));
$this->assertSession()->statusCodeEquals(200);
}

Expand Down
Loading