summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/SemanticDataSortKeyUpdateDBIntegrationTest.php
blob: 6af6b620988ba38e90e6dd210fdd496c9e40754f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

namespace SMW\Tests\Integration;

use SMW\DIProperty;
use SMW\Tests\MwDBaseUnitTestCase;
use SMW\Tests\Utils\UtilityFactory;
use SMWDIBlob as DIBlob;
use Title;

/**
 * @group SMW
 * @group SMWExtension
 *
 * @group semantic-mediawiki-integration
 * @group mediawiki-database
 *
 * @group medium
 *
 * @license GNU GPL v2+
 * @since 2.1
 *
 * @author mwjames
 */
class SemanticDataSortKeyUpdateDBIntegrationTest extends MwDBaseUnitTestCase {

	private $semanticDataFactory;
	private $subjects = [];

	protected function setUp() {
		parent::setUp();

		$this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();

		$this->mwHooksHandler = UtilityFactory::getInstance()->newMwHooksHandler();
		$this->mwHooksHandler->deregisterListedHooks();
	}

	protected function tearDown() {

		$pageDeleter = UtilityFactory::getInstance()->newPageDeleter();
		$pageDeleter->doDeletePoolOfPages( $this->subjects );
		$this->mwHooksHandler->restoreListedHooks();

		parent::tearDown();
	}

	public function testSubjectSortKeySetter() {

		$semanticData = $this->semanticDataFactory->newEmptySemanticData( __METHOD__ );

		$subject = $semanticData->getSubject();
		$subject->setSortKey( 'a_b_c' );

		$this->getStore()->updateData( $semanticData );

		$semanticDataFromDB = $this->getStore()->getSemanticData( $subject );

		$this->assertEquals(
			'a b c',
			$semanticDataFromDB->getSubject()->getSortKey()
		);

		foreach ( $semanticDataFromDB->getPropertyValues( new DIProperty( '_SKEY' ) ) as $value ) {
			$this->assertEquals(
				'a b c',
				$value->getString()
			);
		}

		$this->subjects[] = $semanticData->getSubject();
	}

	public function testDefinedSortKeyTakesPrecedenceOverSubjectSortKey() {

		$semanticData = $this->semanticDataFactory
			->newEmptySemanticData( __METHOD__ );

		$subject = $semanticData->getSubject();
		$subject->setSortKey( '1_2_3' );

		$semanticData->addPropertyObjectValue(
			new DIProperty( '_SKEY' ),
			new DIBlob( 'x_y_z' )
		);

		$this->getStore()->updateData( $semanticData );
		$this->getStore()->clear();

		$semanticDataFromDB = $this->getStore()->getSemanticData( $subject );

		$this->assertEquals(
			'x y z',
			$semanticDataFromDB->getSubject()->getSortKey()
		);

		foreach ( $semanticDataFromDB->getPropertyValues( new DIProperty( '_SKEY' ) ) as $value ) {
			$this->assertEquals(
				'x y z',
				$value->getString()
			);
		}

		$this->subjects[] = $semanticData->getSubject();
	}

}