Commit a57b08a5 authored by git's avatar git Committed by Rudolf Byker
Browse files

Issue #3288837 by Project Update Bot, rudolfbyker: Drupal 10 compatibility...

Issue #3288837 by Project Update Bot, rudolfbyker: Drupal 10 compatibility fixes. Also fix PHPCS issues.
parent 2b549883
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
name: 'OAI-PMH Harvester'
type: module
description: 'Harvest bibliographic records from an OAI-PMH source, like Koha, and caches them in a table so we can refer to them from fields.'
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^8 || ^9 || ^10
package: 'OAI-PMH Harvester'
dependencies:
  - auto_config_form
+2 −3
Original line number Diff line number Diff line
@@ -2,8 +2,7 @@

namespace Drupal\oai_pmh_harvester\Event;

use SimpleXMLElement;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
 * An event that should fire just before harvested data is merged into the DB.
@@ -34,7 +33,7 @@ class HarvestPreMergeEvent extends Event {
   * @param object $csl
   *   The decoded CSL data.
   */
  public function __construct(SimpleXMLElement $xml, object $csl) {
  public function __construct(\SimpleXMLElement $xml, object $csl) {
    $this->xml = $xml;
    $this->csl = $csl;
  }
+5 −3
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Drupal\oai_pmh_harvester\Service;
use Drupal\oai_pmh_harvester\Event\HarvestPreMergeEvent;
use RudolfByker\PhpMarcCsl\MarcCslVariables;
use Scriptotek\Marc\Record;
use SimpleXMLElement;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
@@ -42,11 +41,14 @@ class DecoderService {
   * @throws \Scriptotek\Marc\Exceptions\RecordNotFound
   *   When the provided XML element is not a MARC record.
   */
  public function decodeOne(SimpleXMLElement $xml): MarcCslVariables {
  public function decodeOne(\SimpleXMLElement $xml): MarcCslVariables {
    $csl = new MarcCslVariables(Record::fromSimpleXMLElement($xml));

    // Allow other modules to modify the $csl object before we return it.
    $this->dispatcher->dispatch(HarvestPreMergeEvent::EVENT_NAME, new HarvestPreMergeEvent($xml, $csl));
    $this->dispatcher->dispatch(
      new HarvestPreMergeEvent($xml, $csl),
      HarvestPreMergeEvent::EVENT_NAME
    );

    return $csl;
  }
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class InstallTest extends BrowserTestBase {
  public function testLoadFront() {
    $this->drupalGet('<front>');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertText('Log in');
    $this->assertSession()->pageTextContains('Log in');
  }

}
+15 −14
Original line number Diff line number Diff line
@@ -2,12 +2,9 @@

namespace Drupal\Tests\oai_pmh_harvester\Unit;

use Drupal;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\oai_pmh_harvester\Util;
use Drupal\Tests\UnitTestCase;
use Exception;
use InvalidArgumentException;

/**
 * Tests the Util class.
@@ -18,14 +15,17 @@ use InvalidArgumentException;
class UtilTest extends UnitTestCase {

  /**
   * Test the Util::interpretDateTime function.
   *
   * @covers ::interpretDateTime
   * @dataProvider dataForInterpretDateTime
   * Test the `Util::interpretDateTime` function.
   *
   * @param string $value
   *   The argument for `Util::interpretDateTime`.
   * @param int|null $expectedUnixTimestamp
   *   If not null, the expected return value's unix timestamp.
   * @param string|null $expectedExceptionType
   *   If not null, the exception that should be thrown.
   *
   * @covers ::interpretDateTime
   * @dataProvider dataForInterpretDateTime
   */
  public function testInterpretDateTime(
    string $value,
@@ -35,7 +35,7 @@ class UtilTest extends UnitTestCase {
    try {
      $d = Util::interpretDateTime($value);
    }
    catch (Exception $e) {
    catch (\Exception $e) {
      if (!$expectedExceptionType) {
        $this->fail($e->getMessage());
      }
@@ -67,23 +67,24 @@ class UtilTest extends UnitTestCase {
      "Using SQL date format, omitting the time zone." => [
        "2021-01-01 13:00:00",
        NULL,
        InvalidArgumentException::class,
        \InvalidArgumentException::class,
      ],
      "Garbage." => [
        "random stuff",
        NULL,
        InvalidArgumentException::class,
        \InvalidArgumentException::class,
      ],
    ];
  }

  /**
   * Test the `Util::utcRequestTime` function.
   */
  public function testUtcRequestTime() {
    // Mock the Drupal::time container.
    $container = new ContainerBuilder();
    Drupal::setContainer($container);
    $mockTime = $this->getMockBuilder('Drupal\Component\Datetime\TimeInterface')
        ->disableOriginalConstructor()
        ->getMock();
    \Drupal::setContainer($container);
    $mockTime = $this->createMock('Drupal\Component\Datetime\TimeInterface');
    $mockTime->method('getRequestTime')->willReturn(12345);
    $container->set('datetime.time', $mockTime);