Loading oai_pmh_harvester.info.yml +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 src/Event/HarvestPreMergeEvent.php +2 −3 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading src/Service/DecoderService.php +5 −3 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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; } Loading tests/src/Functional/InstallTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -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'); } } tests/src/Unit/UtilTest.php +15 −14 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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, Loading @@ -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()); } Loading Loading @@ -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); Loading Loading
oai_pmh_harvester.info.yml +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
src/Event/HarvestPreMergeEvent.php +2 −3 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading
src/Service/DecoderService.php +5 −3 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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; } Loading
tests/src/Functional/InstallTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -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'); } }
tests/src/Unit/UtilTest.php +15 −14 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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, Loading @@ -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()); } Loading Loading @@ -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); Loading