Add additional properties for AR (#98)

这个提交包含在:
Mark A. Hershberger 2018-02-03 08:25:14 -05:00 提交者 mwjames
父节点 1811ff98e7
当前提交 1fe2bcd01c
共有 17 个文件被更改,包括 966 次插入11 次删除

查看文件

@ -51,6 +51,30 @@
"label": "Approved revision",
"desc": "sesp-property-approved-rev-desc"
},
"_APPROVEDBY": {
"id": "___APPROVEDBY",
"type": "_wpg",
"show": false,
"alias": "sesp-property-approved-by",
"label": "Approved by",
"desc": "sesp-property-approved-by-desc"
},
"_APPROVEDDATE": {
"id": "___APPROVEDDATE",
"type": "_dat",
"show": false,
"alias": "sesp-property-approved-date",
"label": "Approved date",
"desc": "sesp-property-approved-date-desc"
},
"_APPROVEDSTATUS": {
"id": "___APPROVEDSTATUS",
"type": "_txt",
"show": false,
"alias": "sesp-property-approved-status",
"label": "Approval status",
"desc": "sesp-property-approved-status-desc"
},
"_SUBP": {
"id": "___SUBP",
"type": "_wpg",

查看文件

@ -24,6 +24,12 @@
"sesp-property-shorturl": "Short URL",
"sesp-property-approved-rev": "Approved revision",
"sesp-property-approved-rev-desc": "\"$1\" identifies the revision ID of a page that has been approved (via the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties SESP] extension).",
"sesp-property-approved-by": "Approved by",
"sesp-property-approved-by-desc": "\"$1\" identifies the user who set the approval status of the page (via the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties SESP] extension).",
"sesp-property-approved-date": "Approved date",
"sesp-property-approved-date-desc": "\"$1\" identifies the time when the approval status of the page was set (via the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties SESP] extension).",
"sesp-property-approved-status": "Approval status",
"sesp-property-approved-status-desc": "\"$1\" identifies the approval status of a page that is covered by ApprovedRevs (via the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Extra_Special_Properties SESP] extension).",
"sesp-property-user-registration-date": "User registration date",
"sesp-property-user-edit-count": "User edit count",
"sesp-property-exif-data": "Exif data",

查看文件

@ -25,4 +25,4 @@
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>

查看文件

@ -197,4 +197,14 @@ class AppFactory implements LoggerAwareInterface {
return User::newFromId( $id );
}
/**
* @since 2.0
*
* @param null|Title $title to get the DBLogReader
* @param string $type which log entries to get (default: approval)
* @return DatabaseLogReader
*/
public function newDatabaseLogReader( Title $title = null, $type = 'approval' ) {
return new DatabaseLogReader( $this->getConnection(), $title, $type );
}
}

158
src/DatabaseLogReader.php 普通文件
查看文件

@ -0,0 +1,158 @@
<?php
namespace SESP;
use ArrayIterator;
use DatabaseLogEntry;
use DatabaseBase;
use MWTimestamp;
use Title;
use User;
class DatabaseLogReader {
private static $titleCache = [];
/**
* @var DatabaseBase
*/
private $dbr;
/**
* @var string
*/
private $query;
/**
* @var string
*/
private $log;
/**
* @var string
*/
private $dbKey;
/**
* @var string
*/
private $type;
/**
* @param DatabaseaBase $dbr injected connection
* @param string $dbKey from page name
* @param string $type of log (default: approval)
*/
public function __construct( DatabaseBase $dbr, Title $title = null , $type = 'approval' ) {
$this->dbr = $dbr;
$this->dbKey = $title instanceof Title ? $title->getDBkey() : null;
$this->type = $type;
}
public function clearCache() {
self::$titleCache = [];
}
/**
* Take care of loading from the cache or filling the query.
*/
private function init() {
if ( $this->query ) {
return;
}
if ( !isset( self::$titleCache[ $this->dbKey ] ) ) {
$this->query = DatabaseLogEntry::getSelectQueryData();
$this->query['conds'] = [
'log_type' => $this->type,
'log_title' => $this->dbKey
];
$this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ];
self::$titleCache[ $this->dbKey ] = $this;
} else {
$cache = self::$titleCache[ $this->dbKey ];
$this->query = $cache->getQuery();
$this->log = $cache->getLog();
}
}
/**
* Fetch the results using our conditions
*
* @return IResultWrapper
* @throws DBError
*/
private function getLog() {
if ( !$this->log ) {
$query = $this->getQuery();
$this->log = $this->dbr->select(
$query['tables'],
$query['fields'],
$query['conds'],
__METHOD__,
$query['options'],
$query['join_conds']
);
if ( $this->log === null ) {
$this->log = new ArrayIterator( [ (object)[
'user_id' => null,
'log_timestamp' => null,
'log_action' => null
] ] );
}
}
return $this->log;
}
/**
* Fetch the query parameters for later calls
*
* @return array of parameters for SELECT call
*/
public function getQuery() {
return $this->query;
}
/**
* @return User
*/
public function getUserForLogEntry() {
$this->init();
$logLine = $this->getLog()->current();
if ( $logLine && $logLine->user_id ) {
return User::newFromID( $logLine->user_id );
}
}
/**
* @return Timestamp
*/
public function getDateOfLogEntry() {
$this->init();
$logLine = $this->getLog()->current();
if ( $logLine && $logLine->log_timestamp ) {
return new MWTimestamp( $logLine->log_timestamp );
}
}
/**
* @return string
*/
public function getStatusOfLogEntry() {
$this->init();
$logLine = $this->getLog()->current();
if ( $logLine && $logLine->log_action ) {
return $logLine->log_action;
}
}
}

查看文件

@ -0,0 +1,91 @@
<?php
namespace SESP\PropertyAnnotators;
use SESP\AppFactory;
use SESP\PropertyAnnotator;
use SESP\DatabaseLogReader;
use SMW\DIWikiPage;
use SMWDataItem as DataItem;
use SMW\DIProperty;
use SMW\SemanticData;
use Title;
use User;
/**
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
*/
class ApprovedByPropertyAnnotator implements PropertyAnnotator {
/**
* Predefined property ID
*/
const PROP_ID = '___APPROVEDBY';
/**
* @var AppFactory
*/
private $appFactory;
/**
* @var Integer|null
*/
private $approvedBy;
/**
* @param AppFactory $appFactory
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
}
/**
* @since 2.0
*
* @param User $approvedBy
*/
public function setApprovedBy( $approvedBy ) {
$this->approvedBy = $approvedBy;
}
/**
* {@inheritDoc}
*/
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === self::PROP_ID;
}
public function getDataItem() {
if ( $this->approvedBy instanceof User ) {
$userPage = $this->approvedBy->getUserPage();
if ( $userPage instanceof Title ) {
return DIWikiPage::newFromTitle( $userPage );
}
}
}
/**
* {@inheritDoc}
*/
public function addAnnotation(
DIProperty $property, SemanticData $semanticData
) {
if ( $this->approvedBy === null && class_exists( 'ApprovedRevs' ) ) {
$logReader = $this->appFactory->newDatabaseLogReader(
$semanticData->getSubject()->getTitle(), 'approval'
);
$this->approvedBy = $logReader->getUserForLogEntry();
}
$dataItem = $this->getDataItem();
if ( $dataItem ) {
$semanticData->addPropertyObjectValue( $property, $dataItem );
} else {
$semanticData->removeProperty( $property );
}
}
}

查看文件

@ -0,0 +1,92 @@
<?php
namespace SESP\PropertyAnnotators;
use SMW\DIProperty;
use SMW\SemanticData;
use SMWDataItem as DataItem;
use SMWDITime as DITime;
use SESP\PropertyAnnotator;
use SESP\AppFactory;
/**
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
*/
class ApprovedDatePropertyAnnotator implements PropertyAnnotator {
/**
* Predefined property ID
*/
const PROP_ID = '___APPROVEDDATE';
/**
* @var AppFactory
*/
private $appFactory;
/**
* @var Integer|null
*/
private $approvedDate;
/**
* @param AppFactory $appFactory
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
}
/**
* @since 2.0
*
* @param Integer $approvedDate
*/
public function setApprovedDate( $approvedDate ) {
$this->approvedDate = $approvedDate;
}
/**
* {@inheritDoc}
*/
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === self::PROP_ID;
}
public function getDataItem() {
if ( $this->approvedDate ) {
$date = $this->approvedDate;
return new DITime(
DITime::CM_GREGORIAN,
$date->format( 'Y' ),
$date->format( 'm' ),
$date->format( 'd' ),
$date->format( 'H' ),
$date->format( 'i' )
);
}
}
/**
* {@inheritDoc}
*/
public function addAnnotation(
DIProperty $property, SemanticData $semanticData
) {
if ( $this->approvedDate === null && class_exists( 'ApprovedRevs' ) ) {
$logReader = $this->appFactory->newDatabaseLogReader(
$semanticData->getSubject()->getTitle(), 'approval'
);
$this->approvedDate = $logReader->getDateOfLogEntry();
}
$dataItem = $this->getDataItem();
if ( $dataItem ) {
$semanticData->addPropertyObjectValue( $property, $dataItem );
} else {
$semanticData->removeProperty( $property );
}
}
}

查看文件

@ -56,6 +56,10 @@ class ApprovedRevPropertyAnnotator implements PropertyAnnotator {
return $property->getKey() === self::PROP_ID;
}
public function getDataItem() {
return new DINumber( $this->approvedRev );
}
/**
* {@inheritDoc}
*/
@ -70,7 +74,7 @@ class ApprovedRevPropertyAnnotator implements PropertyAnnotator {
if ( is_numeric( $this->approvedRev ) ) {
$semanticData->addPropertyObjectValue(
$property,
new DINumber( $this->approvedRev )
$this->getDataItem()
);
} else {
$semanticData->removeProperty( $property );

查看文件

@ -0,0 +1,83 @@
<?php
namespace SESP\PropertyAnnotators;
use SMW\DIProperty;
use SMW\SemanticData;
use SMWDIString as DIString;
use SESP\PropertyAnnotator;
use SESP\AppFactory;
use LogReader;
/**
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
*/
class ApprovedStatusPropertyAnnotator implements PropertyAnnotator {
/**
* Predefined property ID
*/
const PROP_ID = '___APPROVEDSTATUS';
/**
* @var AppFactory
*/
private $appFactory;
/**
* @var Integer|null
*/
private $approvedStatus;
/**
* @param AppFactory $appFactory
*/
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
}
/**
* @since 2.0
*
* @param string $approvedStatus
*/
public function setApprovedStatus( $approvedStatus ) {
$this->approvedStatus = $approvedStatus;
}
/**
* {@inheritDoc}
*/
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === self::PROP_ID;
}
public function getDataItem() {
return new DIString( $this->approvedStatus );
}
/**
* {@inheritDoc}
*/
public function addAnnotation(
DIProperty $property, SemanticData $semanticData
) {
if ( $this->approvedStatus === null && class_exists( 'ApprovedRevs' ) ) {
$logReader = $this->appFactory->newDatabaseLogReader(
$semanticData->getSubject()->getTitle(), 'approval'
);
$this->approvedStatus = $logReader->getStatusOfLogEntry();
}
if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== "" ) {
$semanticData->addPropertyObjectValue(
$property, $this->getDataItem()
);
} else {
$semanticData->removeProperty( $property );
}
}
}

查看文件

@ -111,10 +111,22 @@ class DispatchingPropertyAnnotator implements PropertyAnnotator {
return new PageViewsPropertyAnnotator( $appFactory );
},
ApprovedRevPropertyAnnotator::PROP_ID => function( $appFactory ) {
ApprovedRevPropertyAnnotator::PROP_ID => function ( $appFactory ) {
return new ApprovedRevPropertyAnnotator( $appFactory );
},
ApprovedByPropertyAnnotator::PROP_ID => function ( $appFactory ) {
return new ApprovedByPropertyAnnotator( $appFactory );
},
ApprovedDatePropertyAnnotator::PROP_ID => function ( $appFactory ) {
return new ApprovedDatePropertyAnnotator( $appFactory );
},
ApprovedStatusPropertyAnnotator::PROP_ID => function ( $appFactory ) {
return new ApprovedStatusPropertyAnnotator( $appFactory );
},
UserRegistrationDatePropertyAnnotator::PROP_ID => function( $appFactory ) {
return new UserRegistrationDatePropertyAnnotator( $appFactory );
},

查看文件

@ -0,0 +1,6 @@
SESP\Tests\DatabaseLogReader
[x] Can construct
[x] Get query
[x] No log
[ ] Get null

查看文件

@ -156,4 +156,15 @@ class AppFactoryTest extends \PHPUnit_Framework_TestCase {
);
}
public function testNewDatabaseLogReader() {
$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->getMock();
$appFactory = new AppFactory();
$appFactory->setConnection( $connection );
$dbLogReader = $appFactory->newDatabaseLogReader( null );
$dbLogReader->getStatusOfLogEntry();
}
}

查看文件

@ -0,0 +1,176 @@
<?php
namespace SESP\Tests;
use SESP\DatabaseLogReader;
use SESP\AppFactory;
/**
* @covers \SESP\DatabaseLogReader
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class DatabaseLogReaderTest extends \PHPUnit_Framework_TestCase {
private $appFactory;
private $connection;
protected function setUp() {
parent::setUp();
$this->appFactory = new AppFactory;
$this->connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->getMock();
}
protected function prepSelect( \Title $title = null, $calls ) {
$titleKey = $title === null ? null : $title->getDBkey();
$this->appFactory->setConnection( $this->connection );
return $this->connection->expects( $calls )
->method( "select" )
->with( [ 'logging', 'user' ],
[
'log_id', 'log_type', 'log_action', 'log_timestamp',
'log_user', 'log_user_text', 'log_namespace',
'log_title', 'log_params', 'log_deleted', 'user_id',
'user_name', 'user_editcount',
'log_comment_text' => 'log_comment',
'log_comment_data' => 'NULL',
'log_comment_cid' => 'NULL',
], [ 'log_type' => 'approval', 'log_title' => $titleKey ],
'SESP\DatabaseLogReader::getLog',
[ 'ORDER BY' => 'log_timestamp desc' ],
[ 'user' => [ 'LEFT JOIN', 'log_user=user_id' ] ] );
}
public function testCanConstruct() {
$this->assertInstanceOf(
DatabaseLogReader::class,
$this->appFactory->newDatabaseLogReader()
);
}
public function testGetQuery() {
$log = $this->appFactory->newDatabaseLogReader();
$this->assertNull(
$log->getQuery()
);
}
public function testNoLog() {
$log = $this->appFactory->newDatabaseLogReader();
$this->assertNull(
$log->getUserForLogEntry()
);
}
public function testGetNull() {
$title = \Title::newFromText( "none" );
$log = $this->appFactory->newDatabaseLogReader( $title );
$this->assertNull(
$log->getUserForLogEntry()
);
$this->assertNull(
$log->getDateOfLogEntry()
);
$this->assertNull(
$log->getStatusOfLogEntry()
);
$query = $log->getQuery();
$this->assertEquals(
[ 'tables', 'fields', 'conds', 'options', 'join_conds' ],
array_keys( $query )
);
}
public function testGetLogAndQuery() {
$title = \Title::newFromText( __METHOD__ );
$row = new \stdClass;
$row->user_id = 1;
$row->log_timestamp = 5;
$row->log_action = 'bloop';
$this->connection->expects( $this->any() )
->method( 'select' )
->will( $this->returnValue( new \ArrayIterator( [ $row ] ) ) );
$this->appFactory->setConnection(
$this->connection
);
$log = $this->appFactory->newDatabaseLogReader( $title );
$this->assertEquals(
\User::newFromID( 1 ),
$log->getUserForLogEntry()
);
$this->assertEquals(
new \MWTimestamp( 5 ),
$log->getDateOfLogEntry()
);
$this->assertEquals(
'bloop',
$log->getStatusOfLogEntry()
);
$query = $log->getQuery();
$this->assertEquals(
[ 'tables', 'fields', 'conds', 'options', 'join_conds' ],
array_keys( $query )
);
}
public function testCache() {
$title = \Title::newFromText( __METHOD__ );
$row = new \stdClass;
$row->user_id = 1;
$row->log_timestamp = 5;
$row->log_action = 'bloop';
$this->connection->expects( $this->once() )
->method( 'select' )
->will( $this->returnValue( new \ArrayIterator( [ $row ] ) ) );
$this->appFactory->setConnection(
$this->connection
);
$log = $this->appFactory->newDatabaseLogReader( $title );
$log->clearCache();
$this->assertEquals(
\User::newFromID( 1 ),
$log->getUserForLogEntry()
);
// Second call on same title instance should be made from cache
$this->assertEquals(
\User::newFromID( 1 ),
$log->getUserForLogEntry()
);
}
}

查看文件

@ -0,0 +1,90 @@
<?php
namespace SESP\Tests\PropertyAnnotators;
use SESP\PropertyAnnotators\ApprovedByPropertyAnnotator;
use SMW\DIProperty;
use SMW\DIWikiPage;
use User;
/**
* @covers \SESP\PropertyAnnotators\ApprovedByPropertyAnnotator
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class ApprovedByPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
private $property;
private $appFactory;
protected function setUp() {
parent::setUp();
$this->appFactory = $this->getMockBuilder( '\SESP\AppFactory' )
->disableOriginalConstructor()
->getMock();
$this->property = new DIProperty( '___APPROVEDBY' );
}
public function testCanConstruct() {
$this->assertInstanceOf(
ApprovedByPropertyAnnotator::class,
new ApprovedByPropertyAnnotator( $this->appFactory )
);
}
public function testIsAnnotatorFor() {
$annotator = new ApprovedByPropertyAnnotator(
$this->appFactory
);
$this->assertTrue(
$annotator->isAnnotatorFor( $this->property )
);
}
public function testAddAnnotation() {
$user = User::newFromName( "UnitTest" );
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'addPropertyObjectValue' )
->with(
$this->equalTo( $this->property ),
$this->equalTo( DIWikiPage::newFromTitle( $user->getUserPage() ) ) );
$annotator = new ApprovedByPropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedBy( $user );
$annotator->addAnnotation( $this->property, $semanticData );
}
public function testRemoval() {
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'removeProperty' )
->with( $this->equalTo( $this->property ) );
$annotator = new ApprovedByPropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedBy( false );
$annotator->addAnnotation( $this->property, $semanticData );
}
}

查看文件

@ -0,0 +1,103 @@
<?php
namespace SESP\Tests\PropertyAnnotators;
use SESP\PropertyAnnotators\ApprovedDatePropertyAnnotator;
use SMW\DIProperty;
use MWTimestamp;
use SMWDITime as DITime;
/**
* @covers \SESP\PropertyAnnotators\ApprovedDatePropertyAnnotator
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class ApprovedDatePropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
private $property;
private $appFactory;
protected function setUp() {
parent::setUp();
$this->appFactory = $this->getMockBuilder( '\SESP\AppFactory' )
->disableOriginalConstructor()
->getMock();
$this->property = new DIProperty( '___APPROVEDDATE' );
}
public function testCanConstruct() {
$this->assertInstanceOf(
ApprovedDatePropertyAnnotator::class,
new ApprovedDatePropertyAnnotator( $this->appFactory )
);
}
public function testIsAnnotatorFor() {
$annotator = new ApprovedDatePropertyAnnotator(
$this->appFactory
);
$this->assertTrue(
$annotator->isAnnotatorFor( $this->property )
);
}
protected static function getDITime( MWTimestamp $time ) {
return new DITime(
DITime::CM_GREGORIAN,
$time->format( 'Y' ),
$time->format( 'm' ),
$time->format( 'd' ),
$time->format( 'H' ),
$time->format( 'i' )
);
}
public function testAddAnnotation() {
$now = new MWTimestamp( wfTimestampNow() );
$time = self::getDITime( $now );
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'addPropertyObjectValue' )
->with(
$this->equalTo( $this->property ),
$this->equalTo( $time )
);
$annotator = new ApprovedDatePropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedDate( $now );
$annotator->addAnnotation( $this->property, $semanticData );
}
public function testRemoval() {
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'removeProperty' )
->with( $this->equalTo( $this->property ) );
$annotator = new ApprovedDatePropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedDate( false );
$annotator->addAnnotation( $this->property, $semanticData );
}
}

查看文件

@ -41,12 +41,12 @@ class ApprovedRevPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
public function testIsAnnotatorFor() {
$instance = new ApprovedRevPropertyAnnotator(
$annotator = new ApprovedRevPropertyAnnotator(
$this->appFactory
);
$this->assertTrue(
$instance->isAnnotatorFor( $this->property )
$annotator->isAnnotatorFor( $this->property )
);
}
@ -61,13 +61,13 @@ class ApprovedRevPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
$this->equalTo( $this->property ),
$this->equalTo( new DINumber( 42 ) ) );
$instance = new ApprovedRevPropertyAnnotator(
$annotator = new ApprovedRevPropertyAnnotator(
$this->appFactory
);
$instance->setApprovedRev( 42 );
$annotator->setApprovedRev( 42 );
$instance->addAnnotation( $this->property, $semanticData );
$annotator->addAnnotation( $this->property, $semanticData );
}
public function testRemoval() {
@ -79,12 +79,12 @@ class ApprovedRevPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
->method( 'removeProperty' )
->with( $this->equalTo( $this->property ) );
$instance = new ApprovedRevPropertyAnnotator(
$annotator = new ApprovedRevPropertyAnnotator(
$this->appFactory
);
$instance->setApprovedRev( false );
$annotator->setApprovedRev( false );
$instance->addAnnotation( $this->property, $semanticData );
$annotator->addAnnotation( $this->property, $semanticData );
}
}

查看文件

@ -0,0 +1,89 @@
<?php
namespace SESP\Tests\PropertyAnnotators;
use SESP\PropertyAnnotators\ApprovedStatusPropertyAnnotator;
use SMW\DIProperty;
use SMWDIString as DIString;
/**
* @covers \SESP\PropertyAnnotators\ApprovedStatusPropertyAnnotator
* @group semantic-extra-special-properties
*
* @license GNU GPL v2+
* @since 2.0
*
* @author mwjames
*/
class ApprovedStatusPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
private $property;
private $appFactory;
protected function setUp() {
parent::setUp();
$this->appFactory = $this->getMockBuilder( '\SESP\AppFactory' )
->disableOriginalConstructor()
->getMock();
$this->property = new DIProperty( '___APPROVEDSTATUS' );
}
public function testCanConstruct() {
$this->assertInstanceOf(
ApprovedStatusPropertyAnnotator::class,
new ApprovedStatusPropertyAnnotator( $this->appFactory )
);
}
public function testIsAnnotatorFor() {
$annotator = new ApprovedStatusPropertyAnnotator(
$this->appFactory
);
$this->assertTrue(
$annotator->isAnnotatorFor( $this->property )
);
}
public function testAddAnnotation() {
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'addPropertyObjectValue' )
->with(
$this->equalTo( $this->property ),
$this->equalTo( new DIString( "checkme" ) ) );
$annotator = new ApprovedStatusPropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedStatus( "checkme" );
$annotator->addAnnotation( $this->property, $semanticData );
}
public function testRemoval() {
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
->disableOriginalConstructor()
->getMock();
$semanticData->expects( $this->once() )
->method( 'removeProperty' )
->with( $this->equalTo( $this->property ) );
$annotator = new ApprovedStatusPropertyAnnotator(
$this->appFactory
);
$annotator->setApprovedStatus( false );
$annotator->addAnnotation( $this->property, $semanticData );
}
}