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

Follow up patches to _LINKSTO #245

Merged
merged 2 commits into from
Oct 26, 2024
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: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Property labels differ according to the language the wiki was set up. An easy wa
- `_USERRIGHT` adds a property called "User right" to user pages which records the user's assigned rights
- `_USERGROUP` adds a property called "User group" to user pages which records the user's assigned groups
- `_EXIFDATA` adds properties called "Exif data" to file pages which records image metadata (Exif data)
- `_LINKSTO` adds a property called "Links to" which records a list of pages the current page links to

#### Identifiers with further dependencies

Expand Down
14 changes: 9 additions & 5 deletions src/PropertyAnnotators/LinksToPropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @since 3.0.4
*/
class LinksToPropertyAnnotator implements PropertyAnnotator {

/**
* Predefined property ID
*/
const PROP_ID = '___LINKSTO';
public const PROP_ID = '___LINKSTO';
JeroenDeDauw marked this conversation as resolved.
Show resolved Hide resolved

/**
* @var AppFactory
Expand Down Expand Up @@ -53,7 +53,7 @@
* {@inheritDoc}
*/
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === self::PROP_ID ;
return $property->getKey() === self::PROP_ID;
}

/**
Expand All @@ -64,7 +64,11 @@
public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
$page = $semanticData->getSubject()->getTitle();

if ( $page === null || ( !empty( $this->enabledNamespaces ) && !$page->inNamespaces( $this->enabledNamespaces ) ) ) {
if (
$page === null ||
( !empty( $this->enabledNamespaces ) &&
!$page->inNamespaces( $this->enabledNamespaces ) )
) {
return;
}

Expand All @@ -89,7 +93,7 @@
[ 'page' => [ 'JOIN', 'page_id=pl_from' ] ]
);

foreach( $res as $row ) {
foreach ( $res as $row ) {

Check warning on line 96 in src/PropertyAnnotators/LinksToPropertyAnnotator.php

View check run for this annotation

Codecov / codecov/patch

src/PropertyAnnotators/LinksToPropertyAnnotator.php#L96

Added line #L96 was not covered by tests
$title = Title::newFromText( $row->sel_title, $row->sel_ns );
if ( $title !== null && $title->exists() ) {
$semanticData->addPropertyObjectValue( $property, DIWikiPage::newFromTitle( $title ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SESP\Tests\PropertyAnnotators;

use PHPUnit_Framework_TestCase;
use SESP\AppFactory;
use SESP\PropertyAnnotators\LinksToPropertyAnnotator;
use SMW\DIProperty;
Expand All @@ -14,10 +13,10 @@
* @covers \SESP\PropertyAnnotators\LinksToPropertyAnnotator
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @license GPL-2.0-or-later
* @since 2.0
*/
class LinksToPropertyAnnotatorTest extends PHPUnit_Framework_TestCase {
class LinksToPropertyAnnotatorTest extends \PHPUnit\Framework\TestCase {

private $property;
private $appFactory;
Expand All @@ -33,15 +32,13 @@ protected function setUp(): void {
}

public function testCanConstruct() {

$this->assertInstanceOf(
LinksToPropertyAnnotator::class,
new LinksToPropertyAnnotator( $this->appFactory )
);
}

public function testIsAnnotatorFor() {

$instance = new LinksToPropertyAnnotator(
$this->appFactory
);
Expand All @@ -56,7 +53,7 @@ public function testAddAnnotation() {
->disableOriginalConstructor()
->getMock();

$factory->expects( $this->once() )->method('getConnection');
$factory->expects( $this->once() )->method( 'getConnection' );

$subject = $this->getMockBuilder( DIWikiPage::class )
->disableOriginalConstructor()
Expand Down Expand Up @@ -90,7 +87,7 @@ public function testNotAddAnnotation() {
->getMock();

$factory->expects( $this->never() )
->method('getConnection');
->method( 'getConnection' );

$subject = $this->getMockBuilder( DIWikiPage::class )
->disableOriginalConstructor()
Expand Down