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
|
|
|
|
2021-01-29 04:06:56 +00:00
|
|
|
$this->assertArrayHasKey( $i, $expectedOutputs,
|
2019-11-29 22:08:51 +00:00
|
|
|
'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
|
|
|
]
|
|
|
|
],
|
2020-02-05 10:39:49 +00:00
|
|
|
'Follow after base' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', 'b', null, 'a', 'rtl' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a text-b',
|
|
|
|
'number' => 1,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow with no base' => [
|
|
|
|
[
|
|
|
|
[ 'text', [], 'foo', null, null, 'a', 'rtl' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text',
|
|
|
|
'follow' => 'a',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Follow pointing to later ref' => [
|
|
|
|
[
|
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, null, 'c', 'rtl' ],
|
|
|
|
[ 'text-c', [], 'foo', 'c', null, null, 'rtl' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
null,
|
|
|
|
[
|
|
|
|
'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,
|
|
|
|
],
|
2020-02-05 16:52:21 +00:00
|
|
|
0 => [
|
|
|
|
'count' => -1,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 2,
|
|
|
|
'name' => null,
|
|
|
|
'text' => 'text-b',
|
|
|
|
'follow' => 'c',
|
|
|
|
],
|
2020-02-05 10:39:49 +00:00
|
|
|
'c' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 3,
|
|
|
|
'name' => 'c',
|
|
|
|
'text' => 'text-c',
|
|
|
|
'number' => 2,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
2020-02-05 16:52:21 +00:00
|
|
|
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
2020-02-05 10:39:49 +00:00
|
|
|
[ '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', [] ],
|
2020-01-08 15:50:25 +00:00
|
|
|
[ 'new-from-placeholder', 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', [] ],
|
2020-01-08 15:50:25 +00:00
|
|
|
[ 'new-from-placeholder', 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
|
|
|
]
|
|
|
|
],
|
2020-02-05 15:28:45 +00:00
|
|
|
'Two incomplete follows' => [
|
2020-02-05 10:39:49 +00:00
|
|
|
[
|
|
|
|
[ 'text-a', [], 'foo', 'a', null, null, 'rtl' ],
|
|
|
|
[ 'text-b', [], 'foo', null, null, 'd', 'rtl' ],
|
|
|
|
[ 'text-c', [], 'foo', null, null, 'd', 'rtl' ],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo' => [
|
2020-02-05 16:52:21 +00:00
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text-a',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
2020-02-05 10:39:49 +00:00
|
|
|
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',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
2020-02-05 16:52:21 +00:00
|
|
|
[ 'new', 1, 'foo', 'a', null, 'text-a', [] ],
|
2020-02-05 10:39:49 +00:00
|
|
|
[ 'new', 2, 'foo', null, null, 'text-b', [] ],
|
|
|
|
[ 'new', 3, 'foo', null, null, 'text-c', [] ],
|
|
|
|
]
|
|
|
|
],
|
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,
|
2019-12-24 13:31:27 +00:00
|
|
|
int $rollbackCount,
|
|
|
|
$expectedResult,
|
|
|
|
array $expectedRefs = []
|
2019-12-02 09:14:49 +00:00
|
|
|
) {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
$stack->refCallStack = $initialCallStack;
|
|
|
|
$stack->refs = $initialRefs;
|
|
|
|
|
2019-12-24 13:31:27 +00:00
|
|
|
if ( is_string( $expectedResult ) ) {
|
2019-12-19 10:27:00 +00:00
|
|
|
$this->expectException( LogicException::class );
|
2019-12-24 13:31:27 +00:00
|
|
|
$this->expectExceptionMessage( $expectedResult );
|
2019-12-19 10:27:00 +00:00
|
|
|
}
|
2019-12-24 13:31:27 +00:00
|
|
|
$redoStack = $stack->rollbackRefs( $rollbackCount );
|
|
|
|
$this->assertSame( $expectedResult, $redoStack );
|
2019-12-02 09:14:49 +00:00
|
|
|
$this->assertSame( $expectedRefs, $stack->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideRollbackRefs() {
|
|
|
|
return [
|
2019-12-24 13:31:27 +00:00
|
|
|
'Empty stack' => [
|
|
|
|
'initialCallStack' => [],
|
|
|
|
'initialRefs' => [],
|
|
|
|
'rollbackCount' => 0,
|
|
|
|
'expectedResult' => [],
|
|
|
|
'expectedRefs' => [],
|
|
|
|
],
|
|
|
|
'Attempt to overflow stack bounds' => [
|
|
|
|
'initialCallStack' => [],
|
|
|
|
'initialRefs' => [],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [],
|
|
|
|
'expectedRefs' => [],
|
|
|
|
],
|
|
|
|
'Skip invalid refs' => [
|
|
|
|
'initialCallStack' => [ false ],
|
|
|
|
'initialRefs' => [],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [],
|
|
|
|
'expectedRefs' => [],
|
|
|
|
],
|
2019-12-02 09:14:49 +00:00
|
|
|
'Missing group' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => 'Cannot roll back ref with unknown group "foo".',
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Find anonymous ref by key' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'key' => 1,
|
|
|
|
],
|
|
|
|
] ],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [
|
|
|
|
[ 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'expectedRefs' => [],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Missing anonymous ref' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'new', 1, 'foo', null, null, 'text', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'key' => 2,
|
|
|
|
],
|
|
|
|
] ],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => 'Cannot roll back unknown ref by key 1.',
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Assign text' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'assign', 1, 'foo', null, null, 'text-2', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
'text' => 'text-1',
|
|
|
|
],
|
|
|
|
] ],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [
|
|
|
|
[ 'text-2', [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'expectedRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
'text' => null,
|
|
|
|
],
|
|
|
|
] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Increment' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
],
|
|
|
|
] ],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [
|
|
|
|
[ null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'expectedRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
],
|
|
|
|
] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
|
|
|
'Safely ignore placeholder' => [
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialCallStack' => [
|
2019-12-19 09:16:14 +00:00
|
|
|
[ 'increment', 1, 'foo', null, null, null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'initialRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'placeholder' => true,
|
|
|
|
'number' => 10,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 1,
|
|
|
|
],
|
|
|
|
] ],
|
|
|
|
'rollbackCount' => 1,
|
|
|
|
'expectedResult' => [
|
|
|
|
[ null, [] ],
|
2019-12-02 09:14:49 +00:00
|
|
|
],
|
2019-12-24 13:31:27 +00:00
|
|
|
'expectedRefs' => [ 'foo' => [
|
|
|
|
[
|
|
|
|
'placeholder' => true,
|
|
|
|
'number' => 10,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'count' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
],
|
|
|
|
] ],
|
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
|
|
|
|
*/
|
|
|
|
public function testAppendText() {
|
|
|
|
$stack = $this->newStack();
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
}
|