2019-11-22 17:28:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2019-12-09 16:08:57 +00:00
|
|
|
use Cite\ErrorReporter;
|
2019-11-22 17:28:51 +00:00
|
|
|
use Cite\ReferenceStack;
|
2019-12-16 16:11:42 +00:00
|
|
|
use LogicException;
|
2019-12-11 15:05:19 +00:00
|
|
|
use Parser;
|
2019-11-22 17:28:51 +00:00
|
|
|
use StripState;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \Cite\ReferenceStack
|
2019-11-27 10:08:00 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-12-10 15:24:49 +00:00
|
|
|
class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
2019-11-22 17:28:51 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-27 10:08:00 +00:00
|
|
|
* @covers ::__construct
|
2019-11-22 17:28:51 +00:00
|
|
|
* @covers ::pushInvalidRef
|
|
|
|
*/
|
|
|
|
public function testPushInvalidRef() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
$stack->pushInvalidRef();
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertSame( [ false ], $stack->refCallStack );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::pushRef
|
|
|
|
* @dataProvider providePushRef
|
|
|
|
*/
|
|
|
|
public function testPushRefs(
|
|
|
|
array $refs,
|
2019-11-26 14:44:14 +00:00
|
|
|
array $expectedOutputs,
|
2019-11-22 17:28:51 +00:00
|
|
|
array $finalRefs,
|
|
|
|
array $finalCallStack
|
|
|
|
) {
|
|
|
|
$mockStripState = $this->createMock( StripState::class );
|
|
|
|
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
2019-12-19 09:16:14 +00:00
|
|
|
/** @var StripState $mockStripState */
|
2019-11-22 17:28:51 +00:00
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
|
|
|
$result = $stack->pushRef(
|
2019-12-11 15:05:19 +00:00
|
|
|
$this->createMock( Parser::class ),
|
2019-12-19 09:16:14 +00:00
|
|
|
$mockStripState,
|
|
|
|
...$refs[$i]
|
|
|
|
);
|
2019-11-22 17:28:51 +00:00
|
|
|
|
2019-11-29 22:08:51 +00:00
|
|
|
$this->assertTrue( array_key_exists( $i, $expectedOutputs ),
|
|
|
|
'Bad test, not enough expected outputs in fixture.' );
|
2019-11-22 17:28:51 +00:00
|
|
|
$this->assertSame( $expectedOutputs[$i], $result );
|
|
|
|
}
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertSame( $finalRefs, $stack->refs );
|
|
|
|
$this->assertSame( $finalCallStack, $stack->refCallStack );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providePushRef() {
|
|
|
|
return [
|
|
|
|
'Anonymous ref in default group' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], '', null, null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-29 22:08:51 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, '', null, null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous ref in named group' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], 'foo', null, null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-29 22:08:51 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Ref with text' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], 'foo', null, null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
2019-11-26 16:06:01 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named ref with text' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], 'foo', 'name', null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'name',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'name' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'name',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'name', null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow after base' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', 'b', null, 'a', 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-a text-b',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow with no base' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], 'foo', null, null, 'a', 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'follow' => 'a',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow pointing to later ref' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, null, 'c', 'rtl' ],
|
|
|
|
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
null,
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => 'c',
|
|
|
|
'text' => 'text-c',
|
|
|
|
'number' => 2,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-22 17:28:51 +00:00
|
|
|
'follow' => 'c',
|
|
|
|
],
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
'c' => [
|
|
|
|
'count' => 0,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 3,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'c',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-c',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 2,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
|
|
|
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, text in first tag' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ null, [], 'foo', 'a', null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text', [] ],
|
|
|
|
[ 'increment', 1, 'foo', 'a', null, null, [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, text in second tag' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ null, [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text', [], 'foo', 'a', null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => null,
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, null, [] ],
|
|
|
|
[ 'assign', 1, 'foo', 'a', null, 'text', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Repeated ref, mismatched text' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-1', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-2', [], 'foo', 'a', null, null, 'rtl' ]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-1',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-1 cite_error_references_duplicate_key',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
2019-11-22 17:28:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 1,
|
2019-11-26 16:06:01 +00:00
|
|
|
'dir' => 'rtl',
|
2019-11-22 17:28:51 +00:00
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-26 16:06:01 +00:00
|
|
|
'text' => 'text-1 cite_error_references_duplicate_key',
|
2019-11-22 17:28:51 +00:00
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-1', [] ],
|
|
|
|
[ 'increment', 1, 'foo', 'a', null, 'text-2', [] ],
|
2019-11-22 17:28:51 +00:00
|
|
|
]
|
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
'Named extends with no parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', 'b', null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
2019-11-29 11:50:07 +00:00
|
|
|
'b' => [
|
|
|
|
'number' => 1,
|
|
|
|
'__placeholder__' => true,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', 'b', 'text-a', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named extends before parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', 'b', null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', 'b', null, null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', 'b', 'text-a', [] ],
|
|
|
|
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Named extends after parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', 'b', 'a', null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
|
|
|
[ 'new', 2, 'foo', 'b', 'a', 'text-b', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends with no parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', null, 'b', null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
2019-11-29 11:50:07 +00:00
|
|
|
'b' => [
|
|
|
|
'number' => 1,
|
|
|
|
'__placeholder__' => true,
|
|
|
|
]
|
|
|
|
],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, 'b', 'text-a', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends before parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', null, 'b', null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', 'b', null, null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => 'b',
|
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-29 23:26:58 +00:00
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
2019-11-29 11:50:07 +00:00
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'b',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 11:50:07 +00:00
|
|
|
'number' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, 'b', 'text-a', [] ],
|
|
|
|
[ 'new', 2, 'foo', 'b', null, 'text-b', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Anonymous extends after parent' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, 'a', null, 'rtl' ],
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
2019-11-29 23:26:58 +00:00
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
]
|
2019-11-18 14:49:51 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => 'a',
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
2019-11-29 22:37:13 +00:00
|
|
|
'name' => null,
|
2019-11-18 14:49:51 +00:00
|
|
|
'text' => 'text-b',
|
2019-11-29 23:10:11 +00:00
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
|
|
|
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
2019-11-18 14:49:51 +00:00
|
|
|
]
|
|
|
|
],
|
2019-12-09 09:19:55 +00:00
|
|
|
'Normal after extends' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, 'a', null, 'rtl' ],
|
|
|
|
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ],
|
2019-12-09 09:19:55 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => 'c',
|
|
|
|
'text' => 'text-c',
|
|
|
|
'number' => 2,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'number' => 1,
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
],
|
|
|
|
'c' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => 'c',
|
|
|
|
'text' => 'text-c',
|
|
|
|
'number' => 2,
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
|
|
|
[ 'new', 2, 'foo', null, 'a', 'text-b', [] ],
|
|
|
|
[ 'new', 3, 'foo', 'c', null, 'text-c', [] ],
|
2019-12-09 09:19:55 +00:00
|
|
|
]
|
|
|
|
],
|
2019-12-02 09:05:13 +00:00
|
|
|
'Two broken follows' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, null, 'd', 'rtl' ],
|
|
|
|
[ 'text-c', [], 'foo', null, null, 'd', 'rtl' ],
|
2019-12-02 09:05:13 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'follow' => 'd',
|
|
|
|
],
|
|
|
|
1 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-c',
|
|
|
|
'follow' => 'd',
|
|
|
|
],
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
|
|
|
[ 'new', 3, 'foo', null, null, 'text-c', [] ],
|
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
2019-12-02 09:05:13 +00:00
|
|
|
]
|
|
|
|
],
|
2019-11-22 17:28:51 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:14:49 +00:00
|
|
|
/**
|
|
|
|
* @covers ::rollbackRefs
|
|
|
|
* @covers ::rollbackRef
|
|
|
|
* @dataProvider provideRollbackRefs
|
|
|
|
*/
|
|
|
|
public function testRollbackRefs(
|
|
|
|
array $initialCallStack,
|
|
|
|
array $initialRefs,
|
|
|
|
int $count,
|
2019-12-19 10:27:00 +00:00
|
|
|
?array $expectedRedo,
|
|
|
|
?array $expectedRefs,
|
|
|
|
?string $expectedException
|
2019-12-02 09:14:49 +00:00
|
|
|
) {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refCallStack = $initialCallStack;
|
|
|
|
$stack->refs = $initialRefs;
|
|
|
|
|
2019-12-19 10:27:00 +00:00
|
|
|
if ( $expectedException ) {
|
|
|
|
$this->expectException( LogicException::class );
|
|
|
|
$this->expectExceptionMessage( $expectedException );
|
|
|
|
}
|
2019-12-02 09:14:49 +00:00
|
|
|
$redo = $stack->rollbackRefs( $count );
|
|
|
|
$this->assertSame( $expectedRedo, $redo );
|
|
|
|
$this->assertSame( $expectedRefs, $stack->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideRollbackRefs() {
|
|
|
|
return [
|
2019-12-19 10:27:00 +00:00
|
|
|
'Empty stack' => [ [], [], 0, [], [], null ],
|
|
|
|
'Attempt to overflow stack bounds' => [ [], [], 1, [], [], null ],
|
|
|
|
'Skip invalid refs' => [ [ false ], [], 1, [], [], null ],
|
2019-12-02 09:14:49 +00:00
|
|
|
'Missing group' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[],
|
|
|
|
1,
|
2019-12-19 10:27:00 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'Cannot roll back ref with unknown group "foo".',
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Find anonymous ref by key' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'key' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
1,
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text', [] ]
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-19 10:27:00 +00:00
|
|
|
[],
|
|
|
|
null
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Missing anonymous ref' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'key' => 2,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
1,
|
2019-12-19 10:27:00 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'Cannot roll back unknown ref by key 1.',
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Assign text' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'assign', 1, 'foo', null, null, 'text-2', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
'text' => 'text-1',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
1,
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'text-2', [] ]
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
'text' => null,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-12-19 10:27:00 +00:00
|
|
|
null
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Increment' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
1,
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ null, [] ]
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-12-19 10:27:00 +00:00
|
|
|
null
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Safely ignore placeholder' => [
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'placeholder' => true,
|
|
|
|
'number' => 10,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
1,
|
|
|
|
[
|
2019-12-19 09:16:14 +00:00
|
|
|
[ null, [] ]
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'placeholder' => true,
|
|
|
|
'number' => 10,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2019-12-19 10:27:00 +00:00
|
|
|
null
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::rollbackRef
|
|
|
|
*/
|
|
|
|
public function testRollbackRefs_extends() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
$mockStripState = $this->createMock( StripState::class );
|
|
|
|
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
|
|
|
/** @var StripState $mockStripState */
|
2019-12-11 15:05:19 +00:00
|
|
|
$stack->pushRef(
|
|
|
|
$this->createMock( Parser::class ),
|
2019-12-19 09:16:14 +00:00
|
|
|
$mockStripState,
|
|
|
|
'text', [],
|
|
|
|
'foo', null, 'a', null, 'rtl'
|
|
|
|
);
|
2019-12-02 09:14:49 +00:00
|
|
|
$this->assertSame( 1, $stack->extendsCount['foo']['a'] );
|
|
|
|
|
2019-12-19 09:16:14 +00:00
|
|
|
$stack->rollbackRefs( 1 );
|
2019-12-02 09:14:49 +00:00
|
|
|
|
|
|
|
$this->assertSame( 0, $stack->extendsCount['foo']['a'] );
|
|
|
|
}
|
2019-11-27 10:08:00 +00:00
|
|
|
|
|
|
|
/**
|
2019-12-09 14:07:37 +00:00
|
|
|
* @covers ::popGroup
|
2019-11-27 10:08:00 +00:00
|
|
|
*/
|
|
|
|
public function testRemovals() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refs = [ 'group1' => [], 'group2' => [] ];
|
|
|
|
|
2019-12-09 14:07:37 +00:00
|
|
|
$this->assertSame( [], $stack->popGroup( 'group1' ) );
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertSame( [ 'group2' => [] ], $stack->refs );
|
|
|
|
}
|
|
|
|
|
2019-11-22 17:28:51 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getGroups
|
|
|
|
*/
|
|
|
|
public function testGetGroups() {
|
|
|
|
$stack = $this->newStack();
|
2019-11-27 10:08:00 +00:00
|
|
|
$stack->refs = [ 'havenot' => [], 'have' => [ [ 'ref etc' ] ] ];
|
2019-11-22 17:28:51 +00:00
|
|
|
|
|
|
|
$this->assertSame( [ 'have' ], $stack->getGroups() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::hasGroup
|
|
|
|
*/
|
|
|
|
public function testHasGroup() {
|
|
|
|
$stack = $this->newStack();
|
2019-11-27 10:08:00 +00:00
|
|
|
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
2019-11-22 17:28:51 +00:00
|
|
|
|
|
|
|
$this->assertFalse( $stack->hasGroup( 'absent' ) );
|
|
|
|
$this->assertTrue( $stack->hasGroup( 'present' ) );
|
2019-11-27 10:08:00 +00:00
|
|
|
$this->assertFalse( $stack->hasGroup( 'empty' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getGroupRefs
|
|
|
|
*/
|
|
|
|
public function testGetGroupRefs() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
|
|
|
|
|
|
|
$this->assertSame( [], $stack->getGroupRefs( 'absent' ) );
|
|
|
|
$this->assertSame( [ [ 'ref etc' ] ], $stack->getGroupRefs( 'present' ) );
|
|
|
|
$this->assertSame( [], $stack->getGroupRefs( 'empty' ) );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-16 16:11:42 +00:00
|
|
|
* @covers ::appendText
|
2019-11-22 17:28:51 +00:00
|
|
|
*/
|
2019-12-16 16:11:42 +00:00
|
|
|
public function testAppendText_failure() {
|
2019-11-22 17:28:51 +00:00
|
|
|
$stack = $this->newStack();
|
|
|
|
|
2019-12-16 16:11:42 +00:00
|
|
|
$this->expectException( LogicException::class );
|
|
|
|
$stack->appendText( 'group', 'name', 'the-text' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::appendText
|
|
|
|
*/
|
|
|
|
public function testAppendText() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refs = [ 'group' => [ 'name' => [] ] ];
|
|
|
|
|
|
|
|
$stack->appendText( 'group', 'name', 'set' );
|
|
|
|
$this->assertSame( [ 'text' => 'set' ], $stack->refs['group']['name'] );
|
2019-11-22 17:28:51 +00:00
|
|
|
|
2019-12-16 16:11:42 +00:00
|
|
|
$stack->appendText( 'group', 'name', ' and append' );
|
|
|
|
$this->assertSame( [ 'text' => 'set and append' ], $stack->refs['group']['name'] );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 10:08:00 +00:00
|
|
|
/**
|
|
|
|
* @return ReferenceStack
|
|
|
|
*/
|
2019-11-22 17:28:51 +00:00
|
|
|
private function newStack() {
|
2019-12-09 16:08:57 +00:00
|
|
|
$errorReporter = $this->createMock( ErrorReporter::class );
|
2019-12-11 15:05:19 +00:00
|
|
|
$errorReporter->method( 'plain' )->willReturnArgument( 1 );
|
|
|
|
/** @var ErrorReporter $errorReporter */
|
|
|
|
return TestingAccessWrapper::newFromObject( new ReferenceStack( $errorReporter ) );
|
2019-11-22 17:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|