20 $this->_structure = new \Magento\Framework\Data\Structure();
30 $this->assertSame([], $this->_structure->exportElements());
31 $this->_structure->importElements($elements);
32 $this->assertSame($elements, $this->_structure->exportElements());
33 $structure = new \Magento\Framework\Data\Structure($elements);
34 $this->assertSame($elements, $structure->exportElements());
44 [[
'element' => [
'arbitrary_key' =>
'value']]],
58 'group' => [
'two' =>
'two',
'three' =>
'three'],
76 $this->_structure->importElements($elements);
85 'numeric id' => [[
'element']],
86 'completely missing nested set' => [
89 'messed up nested set' => [
96 'nested set invalid data type' => [
99 'duplicate aliases' => [
108 'missing reference back to parent' => [
113 'broken reference back to parent' => [
123 'group invalid data type' => [
126 'asymmetric group' => [
133 'group references to non-existing element' => [
147 $this->_structure->importElements($elements);
156 'non-existing parent' => [
175 $data = [uniqid() => uniqid()];
176 $elementId = uniqid(
'id');
177 $this->assertFalse($this->_structure->hasElement($elementId));
178 $this->assertFalse($this->_structure->getElement($elementId));
180 $this->_structure->createElement($elementId,
$data);
181 $this->assertTrue($this->_structure->hasElement($elementId));
182 $this->assertSame(
$data, $this->_structure->getElement($elementId));
191 $elementId = uniqid(
'id');
192 $this->_structure->createElement($elementId, []);
193 $this->_structure->createElement($elementId, []);
204 $this->assertTrue($this->_structure->unsetElement(
'six',
false));
205 $this->assertFalse($this->_structure->unsetElement(
'six',
false));
206 $this->assertSame([5], $this->_structure->getElement(
'five'));
209 $this->assertTrue($this->_structure->unsetElement(
'three'));
210 $this->assertTrue($this->_structure->unsetElement(
'four'));
211 $this->assertSame([
'one' => [],
'five' => [5]], $this->_structure->exportElements());
220 $this->assertFalse($this->_structure->getAttribute(
'two',
'non-existing'));
221 $this->assertEquals(
'bar', $this->_structure->getAttribute(
'two',
'foo'));
223 $this->_structure->setAttribute(
'two',
'non-existing',
$value)->setAttribute(
'two',
'foo',
$value);
224 $this->assertEquals(
$value, $this->_structure->getAttribute(
'two',
'non-existing'));
225 $this->assertEquals(
$value, $this->_structure->getAttribute(
'two',
'foo'));
234 $this->_structure->setAttribute(
'non-existing',
'foo',
'bar');
245 $this->_structure->importElements([
'element' => []]);
246 $this->_structure->setAttribute(
'element',
$attribute,
'value');
267 $this->_structure->getAttribute(
'non-existing',
'foo');
278 $element = $this->_structure->getElement(
'four');
280 $this->assertFalse($this->_structure->getElement(
'four.5'));
281 $this->assertSame($this->_structure, $this->_structure->renameElement(
'four',
'four.5'));
282 $this->assertSame(
$element, $this->_structure->getElement(
'four.5'));
293 $this->_structure->renameElement(
'three',
'three.5');
295 $this->assertSame([
'three.5' =>
'th',
'two' =>
'tw'], $this->_structure->getChildren(
'four.5'));
296 $this->_structure->renameElement(
'two',
'two.5');
298 $this->assertSame([
'three.5' =>
'th',
'two.5' =>
'tw'], $this->_structure->getChildren(
'four.5'));
309 $this->_structure->setAsChild(
'two',
'one');
310 $this->assertEquals(
'one', $this->_structure->getParentId(
'two'));
311 $this->assertEquals([
'two' =>
'two'], $this->_structure->getChildren(
'one'));
312 $this->assertEquals([
'three' =>
'th'], $this->_structure->getChildren(
'four'));
315 $this->_structure->setAsChild(
'six',
'three',
's');
316 $this->assertEquals(
'three', $this->_structure->getParentId(
'six'));
317 $this->assertEquals([
'six' =>
's'], $this->_structure->getChildren(
'three'));
329 $this->_structure->setAsChild(
'x',
'parent',
'', $offset);
330 $children = $this->_structure->getChildren(
'parent');
331 $actualOffset = array_search(
'x', array_keys(
$children));
335 "The 'x' is expected to be at '{$expectedOffset}' offset, rather than '{$actualOffset}', in array: " .
373 $this->_structure->createElement(
'one', []);
374 $this->_structure->createElement(
'two', []);
375 $this->_structure->createElement(
'three', []);
376 $this->_structure->setAsChild(
'three',
'two');
377 $this->_structure->setAsChild(
'two',
'one');
378 $this->_structure->setAsChild($elementId, $parentId);
386 return [[
'one',
'three'], [
'one',
'one']];
397 $this->_structure->unsetChild(
'five');
398 $this->assertFalse($this->_structure->getParentId(
'five'));
402 $this->_structure->unsetChild(
'four',
'tw');
403 $this->assertFalse($this->_structure->getChildId(
'four',
'tw'));
404 $this->assertFalse($this->_structure->getParentId(
'two'));
417 $this->_structure->setAsChild(
'x',
'parent',
'', $initialOffset);
418 $this->assertSame($expectedOffset, $this->_structure->reorderChild(
'parent',
'x', $newOffset));
466 $this->_structure->createElement(
'one', []);
467 $this->_structure->createElement(
'two', []);
468 $this->_structure->reorderChild(
'one',
'two', 0);
482 $this->_structure->setAsChild(
'x',
'parent',
'', $initialOffset);
483 $this->assertSame($expectedOffset, $this->_structure->reorderToSibling(
'parent',
'x', $sibling, $delta));
523 $this->_structure->createElement(
'one', []);
524 $this->_structure->createElement(
'two', []);
525 $this->_structure->createElement(
'three', []);
526 $this->_structure->setAsChild(
'two',
'one');
527 $this->_structure->reorderToSibling(
'one',
'three',
'two', 1);
536 $this->assertFalse($this->_structure->getChildId(
'nonexisting-parent',
'does not matter'));
537 $this->assertEquals(
'five', $this->_structure->getChildId(
'six',
'f'));
545 $this->_structure->createElement(
'one', []);
546 $this->_structure->createElement(
'two', []);
547 $this->_structure->createElement(
'three', []);
548 $this->_structure->setAsChild(
'two',
'one');
549 $this->_structure->setAsChild(
'three',
'one',
'th');
552 $this->assertSame([
'two' =>
'two',
'three' =>
'th'], $this->_structure->getChildren(
'one'));
553 $this->assertSame([], $this->_structure->getChildren(
'three'));
554 $this->assertSame([], $this->_structure->getChildren(
'nonexisting'));
557 $this->assertEquals(
'one', $this->_structure->getParentId(
'two'));
558 $this->assertFalse($this->_structure->getParentId(
'nonexistent'));
561 $this->assertEquals(
'two', $this->_structure->getChildAlias(
'one',
'two'));
562 $this->assertEquals(
'th', $this->_structure->getChildAlias(
'one',
'three'));
563 $this->assertFalse($this->_structure->getChildAlias(
'nonexistent',
'child'));
564 $this->assertFalse($this->_structure->getChildAlias(
'one',
'nonexistent'));
575 $this->assertFalse($this->_structure->addToParentGroup(
'non-existing',
'group1'));
576 $this->assertSame([], $this->_structure->getGroupChildNames(
'non-existing',
'group1'));
579 $this->_structure->createElement(
'one', []);
580 $this->_structure->createElement(
'two', []);
581 $this->assertFalse($this->_structure->addToParentGroup(
'two',
'group1'));
582 $this->assertSame([], $this->_structure->getGroupChildNames(
'one',
'group1'));
585 $this->_structure->setAsChild(
'two',
'one');
586 $this->assertTrue($this->_structure->addToParentGroup(
'two',
'group1'));
587 $this->assertTrue($this->_structure->addToParentGroup(
'two',
'group2'));
590 $this->_structure->createElement(
'three', []);
591 $this->_structure->createElement(
'four', []);
592 $this->_structure->setAsChild(
'three',
'one',
'th');
593 $this->_structure->setAsChild(
'four',
'one');
594 $this->_structure->addToParentGroup(
'three',
'group1');
595 $this->_structure->addToParentGroup(
'four',
'group2');
596 $this->assertSame([
'two',
'three'], $this->_structure->getGroupChildNames(
'one',
'group1'));
597 $this->assertSame([
'two',
'four'], $this->_structure->getGroupChildNames(
'one',
'group2'));
600 $this->_structure->unsetChild(
'one',
'two');
601 $this->assertSame([
'three'], $this->_structure->getGroupChildNames(
'one',
'group1'));
602 $this->assertSame([
'four'], $this->_structure->getGroupChildNames(
'one',
'group2'));
605 $this->_structure->setAsChild(
'two',
'one');
606 $this->assertSame([
'two',
'three'], $this->_structure->getGroupChildNames(
'one',
'group1'));
607 $this->assertSame([
'two',
'four'], $this->_structure->getGroupChildNames(
'one',
'group2'));
616 $this->_structure->importElements(
635 $this->_structure->importElements(
testReorderChildException()
reorderSiblingDataProvider()
testSetAsChildOffset($offset, $expectedOffset)
testGetAttributeNoElementException()
testReorderChild($initialOffset, $newOffset, $expectedOffset)
importExceptionDataProvider()
testImportExceptionElementNotFound($elements)
testCreateElementException()
testConstructImportExportElements($elements)
importExceptionElementNotFoundDataProvider()
testReorderToSiblingException()
testSetAttributeNoElementException()
reorderChildDataProvider()
setAsChildExceptionDataProvider()
testSetAsChildException($elementId, $parentId)
testReorderToSibling($initialOffset, $sibling, $delta, $expectedOffset)
testGetChildrenParentIdChildAlias()
testCreateGetHasElement()
setAttributeArgumentExceptionDataProvider()
importExportElementsDataProvider()
setAsChildOffsetDataProvider()
_populateSampleStructure()
testImportException($elements)
_populateSampleSortStructure()
testSetAttributeArgumentException($attribute)