-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
smwgEntityCollation
to upgrade key matrix, refs 3095 (#4713)
- Loading branch information
Showing
11 changed files
with
377 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace SMW\SQLStore\TableBuilder\Examiner; | ||
|
||
use Onoi\MessageReporter\MessageReporterAwareTrait; | ||
use SMW\SQLStore\SQLStore; | ||
use SMW\SQLStore\TableBuilder; | ||
use SMW\SetupFile; | ||
use SMW\Maintenance\updateEntityCollation as UpdateEntityCollation; | ||
use SMW\Utils\CliMsgFormatter; | ||
|
||
/** | ||
* @license GNU GPL v2+ | ||
* @since 3.2 | ||
* | ||
* @author mwjames | ||
*/ | ||
class EntityCollation { | ||
|
||
use MessageReporterAwareTrait; | ||
|
||
/** | ||
* @var SQLStore | ||
*/ | ||
private $store; | ||
|
||
/** | ||
* @var SetupFile | ||
*/ | ||
private $setupFile; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $entityCollation = ''; | ||
|
||
/** | ||
* @since 3.2 | ||
* | ||
* @param SQLStore $store | ||
*/ | ||
public function __construct( SQLStore $store ) { | ||
$this->store = $store; | ||
} | ||
|
||
/** | ||
* @since 3.2 | ||
* | ||
* @param SetupFile $setupFile | ||
*/ | ||
public function setSetupFile( SetupFile $setupFile ) { | ||
$this->setupFile = $setupFile; | ||
} | ||
|
||
/** | ||
* @since 3.2 | ||
* | ||
* @param string $entityCollation | ||
*/ | ||
public function setEntityCollation( string $entityCollation ) { | ||
$this->entityCollation = $entityCollation; | ||
} | ||
|
||
/** | ||
* @since 3.2 | ||
*/ | ||
public function check() { | ||
|
||
$cliMsgFormatter = new CliMsgFormatter(); | ||
|
||
$this->messageReporter->reportMessage( | ||
$cliMsgFormatter->firstCol( "Checking entity collation type ..." ) | ||
); | ||
|
||
$entityCollation = $this->setupFile->get( SetupFile::ENTITY_COLLATION ) ?? 'identity'; | ||
|
||
if ( $this->entityCollation !== $entityCollation ) { | ||
|
||
$this->messageReporter->reportMessage( | ||
"\n ... adding incomplete task for entity collation conversion ...\n" | ||
); | ||
|
||
$this->setupFile->addIncompleteTask( UpdateEntityCollation::ENTITY_COLLATION_INCOMPLETE ); | ||
|
||
} else { | ||
$this->messageReporter->reportMessage( | ||
$cliMsgFormatter->secondCol( CliMsgFormatter::OK ) | ||
); | ||
} | ||
|
||
$this->messageReporter->reportMessage( " ... done.\n" ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/CountMapFieldTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace SMW\Tests\SQLStore\TableBuilder\Examiner; | ||
|
||
use SMW\SQLStore\TableBuilder\Examiner\CountMapField; | ||
use SMW\Tests\TestEnvironment; | ||
use SMW\Tests\PHPUnitCompat; | ||
|
||
/** | ||
* @covers \SMW\SQLStore\TableBuilder\Examiner\CountMapField | ||
* @group semantic-mediawiki | ||
* | ||
* @license GNU GPL v2+ | ||
* @since 3.2 | ||
* | ||
* @author mwjames | ||
*/ | ||
class CountMapFieldTest extends \PHPUnit_Framework_TestCase { | ||
|
||
use PHPUnitCompat; | ||
|
||
private $spyMessageReporter; | ||
private $store; | ||
private $setupFile; | ||
|
||
protected function setUp() : void { | ||
parent::setUp(); | ||
$this->spyMessageReporter = TestEnvironment::getUtilityFactory()->newSpyMessageReporter(); | ||
|
||
$this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->store->expects( $this->any() ) | ||
->method( 'getConnection' ) | ||
->will( $this->returnValue( $this->connection ) ); | ||
|
||
$this->setupFile = $this->getMockBuilder( '\SMW\SetupFile' ) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
|
||
public function testCanConstruct() { | ||
|
||
$this->assertInstanceOf( | ||
CountMapField::class, | ||
new CountMapField( $this->store ) | ||
); | ||
} | ||
|
||
public function testCheck_NewFieldTriggerIncompleteTask() { | ||
|
||
$this->connection->expects( $this->once() ) | ||
->method( 'tableName' ) | ||
->will( $this->returnValue( 'smw_objects_aux' ) ); | ||
|
||
$instance = new CountMapField( | ||
$this->store | ||
); | ||
|
||
$instance->setMessageReporter( $this->spyMessageReporter ); | ||
$instance->setSetupFile( $this->setupFile ); | ||
$instance->check( [ 'smw_objects_aux' => [ 'smw_countmap' => 'field.new' ] ]); | ||
|
||
$this->assertContains( | ||
'adding incomplete task for `smw_countmap` conversion', | ||
$this->spyMessageReporter->getMessagesAsString() | ||
); | ||
} | ||
|
||
public function testCheckOk() { | ||
|
||
$instance = new CountMapField( | ||
$this->store | ||
); | ||
|
||
$instance->setMessageReporter( $this->spyMessageReporter ); | ||
$instance->setSetupFile( $this->setupFile ); | ||
$instance->check(); | ||
|
||
$this->assertContains( | ||
'Checking smw_countmap field consistency', | ||
$this->spyMessageReporter->getMessagesAsString() | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.