2015-11-12 02:59:08 +01:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests\GridField;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldPrintButton;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldPaginator;
|
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Forms\Tests\GridField\GridFieldPrintButtonTest\TestObject;
|
2015-11-12 02:59:08 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class GridFieldPrintButtonTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2017-03-24 12:17:26 +01:00
|
|
|
TestObject::class,
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// 42 items
|
|
|
|
for ($i = 1; $i <= 42; $i++) {
|
|
|
|
$obj = new TestObject();
|
|
|
|
$obj->Name = "Object {$i}";
|
|
|
|
$obj->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLimit()
|
|
|
|
{
|
|
|
|
$list = TestObject::get();
|
|
|
|
|
|
|
|
$button = new GridFieldPrintButton();
|
2020-04-20 19:58:09 +02:00
|
|
|
$button->setPrintColumns(['Name' => 'My Name']);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
// Get paginated gridfield config
|
|
|
|
$config = GridFieldConfig::create()
|
|
|
|
->addComponent(new GridFieldPaginator(10))
|
|
|
|
->addComponent($button);
|
|
|
|
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
2017-06-22 12:50:45 +02:00
|
|
|
/** @skipUpgrade */
|
|
|
|
new Form(Controller::curr(), 'Form', new FieldList($gridField), new FieldList());
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
// Printed data should ignore pagination limit
|
|
|
|
$printData = $button->generatePrintData($gridField);
|
|
|
|
$rows = $printData->ItemRows;
|
|
|
|
$this->assertEquals(42, $rows->count());
|
|
|
|
}
|
2015-11-12 02:59:08 +01:00
|
|
|
}
|