Skip to content
Closed
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
20 changes: 12 additions & 8 deletions src/includes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7263,14 +7263,18 @@ public function set_free_doi_access(): void {
if ($doi !== '') {
foreach (DOI_FREE_PREFIX as $prefix) {
if (mb_stripos($doi, $prefix) === 0) {
$p = new Parameter();
$p->pre = $this->param[0]->pre;
$p->param = 'doi-access';
$p->eq = '=';
$p->val = 'free';
$p->post = '';
$this->param[] = $p;
report_add(echoable("Adding doi-access: free"));
if ($this->has_but_maybe_blank('doi-access')) {
$this->set('doi-access', 'free');
} else {
$p = new Parameter();
$p->pre = $this->param[0]->pre;
$p->param = 'doi-access';
$p->eq = '=';
$p->val = 'free';
$p->post = '';
$this->param[] = $p;
report_add(echoable("Adding doi-access: free"));
}
break;
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/includes/templatePart4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,22 @@ public function testDoiFreePrefixPreservesLeadingSpace(): void {
$this->assertStringContainsString('10.1186/s12915-020-00940-y| doi-access=free', $doi_t->parsed_text());
}

public function testDoiFreePrefixDoesNotDuplicateExistingAccess(): void {
$doi_t = new Template();
$doi_t->parse_text('{{doi|10.1186/s12915-020-00940-y|doi-access=free}}');
$doi_t->set_free_doi_access();
$this->assertSame(1, substr_count($doi_t->parsed_text(), 'doi-access=free'));
$this->assertSame('free', $doi_t->get2('doi-access'));
}

public function testDoiFreePrefixUpgradesExistingRestrictedAccess(): void {
$doi_t = new Template();
$doi_t->parse_text('{{doi|10.1186/s12915-020-00940-y|doi-access=limited}}');
$doi_t->set_free_doi_access();
$this->assertSame('free', $doi_t->get2('doi-access'));
$this->assertSame(1, substr_count($doi_t->parsed_text(), 'doi-access='));
}

public function testDoiNonFreePrefixNotDetected(): void {
$doi_t = new Template();
$doi_t->parse_text('{{doi|10.1234/nonfree-example}}');
Expand Down
Loading