mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Make sure LazyLoader still woks after a readonly transofrmation (#8460)
This commit is contained in:
parent
0b5a654d73
commit
2e2ca5a4a7
@ -155,6 +155,7 @@ class CompositeField extends FormField
|
|||||||
public function setChildren($children)
|
public function setChildren($children)
|
||||||
{
|
{
|
||||||
$this->children = $children;
|
$this->children = $children;
|
||||||
|
$children->setContainerField($this);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,18 +110,19 @@ class GridField extends FormField
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $readonlyComponents = array(
|
protected $readonlyComponents = [
|
||||||
GridField_ActionMenu::class,
|
GridField_ActionMenu::class,
|
||||||
GridState_Component::class,
|
|
||||||
GridFieldConfig_RecordViewer::class,
|
GridFieldConfig_RecordViewer::class,
|
||||||
GridFieldDetailForm::class,
|
|
||||||
GridFieldDataColumns::class,
|
GridFieldDataColumns::class,
|
||||||
|
GridFieldDetailForm::class,
|
||||||
|
GridFieldLazyLoader::class,
|
||||||
GridFieldPageCount::class,
|
GridFieldPageCount::class,
|
||||||
GridFieldPaginator::class,
|
GridFieldPaginator::class,
|
||||||
GridFieldSortableHeader::class,
|
GridFieldSortableHeader::class,
|
||||||
GridFieldToolbarHeader::class,
|
GridFieldToolbarHeader::class,
|
||||||
GridFieldViewButton::class,
|
GridFieldViewButton::class,
|
||||||
);
|
GridState_Component::class,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pattern used for looking up
|
* Pattern used for looking up
|
||||||
|
@ -55,58 +55,117 @@ class GridFieldLazyLoaderTest extends SapphireTest
|
|||||||
|
|
||||||
public function testGetManipulatedDataWithoutHeader()
|
public function testGetManipulatedDataWithoutHeader()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getHeaderlessGridField();
|
$gridField = $this->getHeaderlessGridField();
|
||||||
$this->assertCount(
|
$this->assertCount(
|
||||||
0,
|
0,
|
||||||
$this->component->getManipulatedData($gridFied, $this->list)->toArray(),
|
$this->component->getManipulatedData($gridField, $this->list)->toArray(),
|
||||||
'GridFieldLazyLoader::getManipulatedData should return an empty list if the X-Pjax is unset'
|
'GridFieldLazyLoader::getManipulatedData should return an empty list if the X-Pjax is unset'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetManipulatedDataWithoutTabSet()
|
public function testGetManipulatedDataWithoutTabSet()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getOutOfTabSetGridField();
|
$gridField = $this->getOutOfTabSetGridField();
|
||||||
$this->assertSameSize(
|
$this->assertSameSize(
|
||||||
$this->list,
|
$this->list,
|
||||||
$this->component->getManipulatedData($gridFied, $this->list)->toArray(),
|
$this->component->getManipulatedData($gridField, $this->list)->toArray(),
|
||||||
'GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is not in a tab'
|
'GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is not in a tab'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetManipulatedDataNonLazy()
|
public function testGetManipulatedDataNonLazy()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getNonLazyGridField();
|
$gridField = $this->getNonLazyGridField();
|
||||||
$this->assertSameSize(
|
$this->assertSameSize(
|
||||||
$this->list,
|
$this->list,
|
||||||
$this->component->getManipulatedData($gridFied, $this->list),
|
$this->component->getManipulatedData($gridField, $this->list),
|
||||||
'GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is in a tab with the pajax header'
|
'GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is in a tab with the pajax header'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHTMLFragmentsWithoutHeader()
|
public function testGetHTMLFragmentsWithoutHeader()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getHeaderlessGridField();
|
$gridField = $this->getHeaderlessGridField();
|
||||||
$actual = $this->component->getHTMLFragments($gridFied);
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
$this->assertContains('grid-field-lazy-loadable', $gridFied->extraClass());
|
$this->assertContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
$this->assertNotContains('grid-field-lazy-loaded', $gridFied->extraClass());
|
$this->assertNotContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHTMLFragmentsWithoutTabSet()
|
public function testGetHTMLFragmentsWithoutTabSet()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getOutOfTabSetGridField();
|
$gridField = $this->getOutOfTabSetGridField();
|
||||||
$actual = $this->component->getHTMLFragments($gridFied);
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
$this->assertContains('grid-field-lazy-loaded', $gridFied->extraClass());
|
$this->assertContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
$this->assertNotContains('grid-field-lazy-loadable', $gridFied->extraClass());
|
$this->assertNotContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHTMLFragmentsNonLazy()
|
public function testGetHTMLFragmentsNonLazy()
|
||||||
{
|
{
|
||||||
$gridFied = $this->getNonLazyGridField();
|
$gridField = $this->getNonLazyGridField();
|
||||||
$actual = $this->component->getHTMLFragments($gridFied);
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
$this->assertContains('grid-field-lazy-loaded', $gridFied->extraClass());
|
$this->assertContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
$this->assertNotContains('grid-field-lazy-loadable', $gridFied->extraClass());
|
$this->assertNotContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testReadOnlyGetManipulatedDataWithoutHeader()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getHeaderlessGridField());
|
||||||
|
$this->assertCount(
|
||||||
|
0,
|
||||||
|
$this->component->getManipulatedData($gridField, $this->list)->toArray(),
|
||||||
|
'Redonly GridFieldLazyLoader::getManipulatedData should return an empty list if the X-Pjax is unset'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReadOnlyGetManipulatedDataWithoutTabSet()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getOutOfTabSetGridField());
|
||||||
|
$this->assertSameSize(
|
||||||
|
$this->list,
|
||||||
|
$this->component->getManipulatedData($gridField, $this->list)->toArray(),
|
||||||
|
'Redonly GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is not in a tab'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReadOnlyGetManipulatedDataNonLazy()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getNonLazyGridField());
|
||||||
|
$this->assertSameSize(
|
||||||
|
$this->list,
|
||||||
|
$this->component->getManipulatedData($gridField, $this->list),
|
||||||
|
'Redonly GridFieldLazyLoader::getManipulatedData should return a proper list if gridifield is in a tab with the pajax header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReadOnlyGetHTMLFragmentsWithoutHeader()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getHeaderlessGridField());
|
||||||
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
|
$this->assertContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
|
$this->assertNotContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReadOnlyGetHTMLFragmentsWithoutTabSet()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getOutOfTabSetGridField());
|
||||||
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
|
$this->assertContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
|
$this->assertNotContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReadOnlyGetHTMLFragmentsNonLazy()
|
||||||
|
{
|
||||||
|
$gridField = $this->makeGridFieldReadonly($this->getNonLazyGridField());
|
||||||
|
$actual = $this->component->getHTMLFragments($gridField);
|
||||||
|
$this->assertEmpty($actual, 'getHTMLFragments should always return an array');
|
||||||
|
$this->assertContains('grid-field-lazy-loaded', $gridField->extraClass());
|
||||||
|
$this->assertNotContains('grid-field-lazy-loadable', $gridField->extraClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,4 +209,23 @@ class GridFieldLazyLoaderTest extends SapphireTest
|
|||||||
Form::create(null, 'Form', $fieldList, FieldList::create());
|
Form::create(null, 'Form', $fieldList, FieldList::create());
|
||||||
return $this->gridField;
|
return $this->gridField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a readonly transformation on our GridField's Form and return the ReadOnly GridField.
|
||||||
|
*
|
||||||
|
* We need to make sure the LazyLoader component still works after our GridField has been made readonly.
|
||||||
|
*
|
||||||
|
* @param GridField $gridField
|
||||||
|
* @return GridField
|
||||||
|
*/
|
||||||
|
private function makeGridFieldReadonly(GridField $gridField)
|
||||||
|
{
|
||||||
|
$form = $gridField->getForm()->makeReadonly();
|
||||||
|
$fields = $form->Fields()->dataFields();
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if ($field->getName() == 'testfield') {
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user