summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php
new file mode 100644
index 00000000..3497f40f
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/TableBuilder/Examiner/HashFieldTest.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace SMW\Tests\SQLStore\TableBuilder\Examiner;
+
+use SMW\SQLStore\TableBuilder\Examiner\HashField;
+use SMW\Tests\TestEnvironment;
+
+/**
+ * @covers \SMW\SQLStore\TableBuilder\Examiner\HashField
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 3.1
+ *
+ * @author mwjames
+ */
+class HashFieldTest extends \PHPUnit_Framework_TestCase {
+
+ private $spyMessageReporter;
+ private $store;
+ private $populateHashField;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->spyMessageReporter = TestEnvironment::getUtilityFactory()->newSpyMessageReporter();
+
+ $this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->populateHashField = $this->getMockBuilder( '\SMW\Maintenance\PopulateHashField' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ HashField::class,
+ new HashField( $this->store )
+ );
+ }
+
+ public function testCheck_Populate() {
+
+ $resultWrapper = $this->getMockBuilder( '\ResultWrapper' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $resultWrapper->expects( $this->once() )
+ ->method( 'numRows' )
+ ->will( $this->returnValue( HashField::threshold() - 1 ) );
+
+ $this->populateHashField->expects( $this->atLeastOnce() )
+ ->method( 'populate' );
+
+ $this->populateHashField->expects( $this->once() )
+ ->method( 'fetchRows' )
+ ->will( $this->returnValue( $resultWrapper ) );
+
+ $instance = new HashField(
+ $this->store,
+ $this->populateHashField
+ );
+
+ $instance->setMessageReporter( $this->spyMessageReporter );
+ $instance->check();
+
+ $this->assertContains(
+ 'Checking smw_hash field consistency',
+ $this->spyMessageReporter->getMessagesAsString()
+ );
+ }
+
+ public function testCheck_Incomplete() {
+
+ $resultWrapper = $this->getMockBuilder( '\ResultWrapper' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $resultWrapper->expects( $this->once() )
+ ->method( 'numRows' )
+ ->will( $this->returnValue( HashField::threshold() + 1 ) );
+
+ $this->populateHashField->expects( $this->atLeastOnce() )
+ ->method( 'setComplete' );
+
+ $this->populateHashField->expects( $this->once() )
+ ->method( 'fetchRows' )
+ ->will( $this->returnValue( $resultWrapper ) );
+
+ $instance = new HashField(
+ $this->store,
+ $this->populateHashField
+ );
+
+ $instance->setMessageReporter( $this->spyMessageReporter );
+ $instance->check();
+
+ $this->assertContains(
+ 'Checking smw_hash field consistency',
+ $this->spyMessageReporter->getMessagesAsString()
+ );
+ }
+
+}