119 lines
2.8 KiB
PHP
119 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace SMW\Tests\MediaWiki\Hooks;
|
|
|
|
use SMW\DIProperty;
|
|
use SMW\DIWikiPage;
|
|
use SMW\MediaWiki\Hooks\ArticleDelete;
|
|
use SMW\Tests\TestEnvironment;
|
|
|
|
/**
|
|
* @covers \SMW\MediaWiki\Hooks\ArticleDelete
|
|
* @group semantic-mediawiki
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
* @since 2.0
|
|
*
|
|
* @author mwjames
|
|
*/
|
|
class ArticleDeleteTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
private $testEnvironment;
|
|
private $jobFactory;
|
|
private $eventDispatcher;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->testEnvironment = new TestEnvironment(
|
|
[
|
|
'smwgEnableUpdateJobs' => false,
|
|
'smwgEnabledDeferredUpdate' => false
|
|
]
|
|
);
|
|
|
|
$this->jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\JobFactory' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$this->testEnvironment->registerObject( 'JobFactory', $this->jobFactory );
|
|
$this->testEnvironment->registerObject( 'JobQueue', $jobQueue );
|
|
|
|
$this->eventDispatcher = $this->getMockBuilder( '\Onoi\EventDispatcher\EventDispatcher' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
$this->testEnvironment->tearDown();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testCanConstruct() {
|
|
$store = $this->getMockBuilder( '\SMW\Store' )
|
|
->disableOriginalConstructor()
|
|
->getMockForAbstractClass();
|
|
|
|
$instance = new ArticleDelete( $store );
|
|
|
|
$this->assertInstanceOf(
|
|
ArticleDelete::class,
|
|
$instance
|
|
);
|
|
}
|
|
|
|
public function testProcess() {
|
|
$idTable = $this->getMockBuilder( '\SMW\SQLStore\EntityStore\EntityIdManager' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$updateDispatcherJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\UpdateDispatcherJob' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$this->jobFactory->expects( $this->atLeastOnce() )
|
|
->method( 'newUpdateDispatcherJob' )
|
|
->willReturn( $updateDispatcherJob );
|
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ );
|
|
|
|
$store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$store->expects( $this->atLeastOnce() )
|
|
->method( 'deleteSubject' );
|
|
|
|
$store->expects( $this->atLeastOnce() )
|
|
->method( 'getInProperties' )
|
|
->willReturn( [ new DIProperty( 'Foo' ) ] );
|
|
|
|
$store->expects( $this->atLeastOnce() )
|
|
->method( 'getObjectIds' )
|
|
->willReturn( $idTable );
|
|
|
|
$this->eventDispatcher->expects( $this->atLeastOnce() )
|
|
->method( 'dispatch' )
|
|
->withConsecutive(
|
|
[ $this->equalTo( 'InvalidateResultCache' ) ],
|
|
[ $this->equalTo( 'InvalidateEntityCache' ) ] );
|
|
|
|
$instance = new ArticleDelete(
|
|
$store
|
|
);
|
|
|
|
$instance->setEventDispatcher(
|
|
$this->eventDispatcher
|
|
);
|
|
|
|
$this->assertTrue(
|
|
$instance->process( $subject->getTitle() )
|
|
);
|
|
}
|
|
|
|
}
|