testEnvironment = new TestEnvironment(); $this->user = new MockSuperUser(); $settings = [ 'smwgMainCacheType' => 'hash', 'smwgAutoRefreshOnPageMove' => true, 'smwgNamespacesWithSemanticLinks' => [ NS_MAIN => true, NS_HELP => false ] ]; $this->testEnvironment->withConfiguration( $settings ); $this->namespaceExaminer = $this->getMockBuilder( '\SMW\NamespaceExaminer' ) ->disableOriginalConstructor() ->getMock(); $this->eventDispatcher = $this->getMockBuilder( '\Onoi\EventDispatcher\EventDispatcher' ) ->disableOriginalConstructor() ->getMock(); } protected function tearDown(): void { $this->testEnvironment->tearDown(); parent::tearDown(); } public function testCanConstruct() { $this->assertInstanceOf( PageMoveComplete::class, new PageMoveComplete( $this->namespaceExaminer ) ); } public function testChangeSubjectForSupportedSemanticNamespace() { $titleFactory = MediaWikiServices::getInstance()->getTitleFactory(); $this->eventDispatcher->expects( $this->atLeastOnce() ) ->method( 'dispatch' ) ->withConsecutive( [ $this->equalTo( 'InvalidateResultCache' ) ], [ $this->equalTo( 'InvalidateResultCache' ) ], [ $this->equalTo( 'InvalidateEntityCache' ) ], [ $this->equalTo( 'InvalidateEntityCache' ) ] ); $oldTitle = $titleFactory->newFromText( 'Old' ); $newTitle = $titleFactory->newFromText( 'New' ); $store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); $store->expects( $this->never() ) ->method( 'changeTitle' ); $this->testEnvironment->registerObject( 'Store', $store ); $instance = new PageMoveComplete( $this->namespaceExaminer ); $instance->setEventDispatcher( $this->eventDispatcher ); $this->assertTrue( $instance->process( $oldTitle, $newTitle, $this->user, 0, 0 ) ); } public function testDeleteSubjectForNotSupportedSemanticNamespace() { $titleFactory = MediaWikiServices::getInstance()->getTitleFactory(); $this->eventDispatcher->expects( $this->atLeastOnce() ) ->method( 'dispatch' ) ->withConsecutive( [ $this->equalTo( 'InvalidateResultCache' ) ], [ $this->equalTo( 'InvalidateResultCache' ) ], [ $this->equalTo( 'InvalidateEntityCache' ) ], [ $this->equalTo( 'InvalidateEntityCache' ) ] ); $oldTitle = $titleFactory->newFromText( 'Old' ); $newTitle = $titleFactory->newFromText( 'New', NS_HELP ); $store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); $store->expects( $this->once() ) ->method( 'deleteSubject' ) ->with( $oldTitle ); $this->testEnvironment->registerObject( 'Store', $store ); $instance = new PageMoveComplete( $this->namespaceExaminer ); $instance->setEventDispatcher( $this->eventDispatcher ); $this->assertTrue( $instance->process( $oldTitle, $newTitle, $this->user, 0, 0 ) ); } }