mediawiki-extensions-Cite/tests/phpunit/unit/Parsoid/ReferencesDataTest.php
Adam Wight e4e6b59306 No-op wiring to get ref "extends" into Parsoid
This doesn't change behavior yet, it's pure wiring to make the
attribute available to Parsoid logic.

Bug: T378567
Change-Id: I6182b601f6fee66a9c32d5006d0a36150eb47e7f
2024-10-31 13:20:02 +01:00

100 lines
2.8 KiB
PHP

<?php
namespace Cite\Tests\Unit;
use Cite\Cite;
use Cite\Parsoid\ReferencesData;
use Cite\Parsoid\RefGroupItem;
use MediaWikiUnitTestCase;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
/**
* @covers \Cite\Parsoid\ReferencesData
* @license GPL-2.0-or-later
*/
class ReferencesDataTest extends MediaWikiUnitTestCase {
public function testMinimalSetup() {
$data = new ReferencesData();
$this->assertSame( [], $data->embeddedErrors );
$this->assertSame( Cite::DEFAULT_GROUP, $data->referencesGroup );
$this->assertFalse( $data->inReferencesContent() );
$this->assertFalse( $data->inEmbeddedContent() );
$this->assertNull( $data->getRefGroup( Cite::DEFAULT_GROUP ) );
$this->assertSame( [], $data->getRefGroups() );
}
public function testAllocIfMissing() {
$data = new ReferencesData();
$group = $data->getRefGroup( 'note', true );
$this->assertSame( 'note', $group->name );
$data->removeRefGroup( 'note' );
$this->assertNull( $data->getRefGroup( 'note' ) );
}
public function testEmbeddedInAnyContent() {
$data = new ReferencesData();
$data->pushEmbeddedContentFlag();
$this->assertTrue( $data->inEmbeddedContent() );
$this->assertFalse( $data->inReferencesContent() );
$data->popEmbeddedContentFlag();
$this->assertFalse( $data->inEmbeddedContent() );
}
public function testEmbeddedInReferencesContent() {
$data = new ReferencesData();
$data->pushEmbeddedContentFlag( 'references' );
$this->assertTrue( $data->inEmbeddedContent() );
$this->assertTrue( $data->inReferencesContent() );
$data->popEmbeddedContentFlag();
$this->assertFalse( $data->inReferencesContent() );
}
public function testAddUnnamedRef() {
$data = new ReferencesData();
$ref = $data->add(
$this->createNoOpMock( ParsoidExtensionAPI::class ),
Cite::DEFAULT_GROUP,
'',
null,
''
);
$expected = new RefGroupItem();
$expected->key = 'cite_ref-1';
$expected->id = 'cite_ref-1';
$expected->target = 'cite_note-1';
$this->assertEquals( $expected, $ref );
$group = $data->getRefGroup( Cite::DEFAULT_GROUP );
$this->assertEquals( [ $expected ], $group->refs );
$this->assertSame( [], $group->indexByName );
}
public function testAddNamedRef() {
$data = new ReferencesData();
$ref = $data->add(
$this->createNoOpMock( ParsoidExtensionAPI::class ),
'note',
'wales',
'main',
'rtl'
);
$expected = new RefGroupItem();
$expected->dir = 'rtl';
$expected->group = 'note';
$expected->key = 'cite_ref-wales_1';
$expected->id = 'cite_ref-wales_1-0';
$expected->name = 'wales';
$expected->extendsRef = 'main';
$expected->target = 'cite_note-wales-1';
$this->assertEquals( $expected, $ref );
$group = $data->getRefGroup( 'note' );
$this->assertEquals( [ $expected ], $group->refs );
$this->assertEquals( [ 'wales' => $expected ], $group->indexByName );
}
}