1<?php
2
3/**
4 * @group Search
5 * @covers SearchIndexFieldDefinition
6 */
7class SearchIndexFieldTest extends \MediaWikiUnitTestCase {
8
9	public function getMergeCases() {
10		return [
11			[ 0, 'test', 0, 'test', true ],
12			[ SearchIndexField::INDEX_TYPE_NESTED, 'test',
13				SearchIndexField::INDEX_TYPE_NESTED, 'test', false ],
14			[ 0, 'test', 0, 'test2', true ],
15			[ 0, 'test', 1, 'test', false ],
16		];
17	}
18
19	/**
20	 * @dataProvider getMergeCases
21	 * @param int $t1
22	 * @param string $n1
23	 * @param int $t2
24	 * @param string $n2
25	 * @param bool $result
26	 */
27	public function testMerge( $t1, $n1, $t2, $n2, $result ) {
28		$field1 =
29			$this->getMockBuilder( SearchIndexFieldDefinition::class )
30				->onlyMethods( [ 'getMapping' ] )
31				->setConstructorArgs( [ $n1, $t1 ] )
32				->getMock();
33		$field2 =
34			$this->getMockBuilder( SearchIndexFieldDefinition::class )
35				->onlyMethods( [ 'getMapping' ] )
36				->setConstructorArgs( [ $n2, $t2 ] )
37				->getMock();
38
39		if ( $result ) {
40			$this->assertNotFalse( $field1->merge( $field2 ) );
41		} else {
42			$this->assertFalse( $field1->merge( $field2 ) );
43		}
44
45		$field1->setFlag( 0xFF );
46		$this->assertFalse( $field1->merge( $field2 ) );
47
48		$field1->setMergeCallback(
49			static function ( $a, $b ) {
50				return "test";
51			}
52		);
53		$this->assertEquals( "test", $field1->merge( $field2 ) );
54	}
55
56}
57