public function testThereIsNoPaginatorWhenOnlyOnePage() { // We set the itemsPerPage to an reasonably big number so as to avoid test broke from small changes // on the fixture YML file $total = $this->list->count(); $this->gridField->getConfig()->getComponentByType("SilverStripe\\Forms\\GridField\\GridFieldPaginator")->setItemsPerPage($total); $fieldHolder = $this->gridField->FieldHolder(); $content = new CSSContentParser($fieldHolder); // Check that there is no paginator render into the footer $this->assertEquals(0, count($content->getBySelector('.datagrid-pagination'))); // Check that there is still 'View 1 - 4 of 4' part on the left of the paginator $this->assertEquals(2, count($content->getBySelector('.pagination-records-number'))); }
/** * @covers SilverStripe\Forms\GridField\GridFieldDataColumns::getFieldFormatting * @covers SilverStripe\Forms\GridField\GridFieldDataColumns::setFieldFormatting */ public function testFieldFormatting() { $obj = new GridField('testfield', 'testfield'); $columns = $obj->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $this->assertEquals(array(), $columns->getFieldFormatting()); $columns->setFieldFormatting(array("myFieldName" => '<a href=\\"custom-admin/$ID\\">$ID</a>')); $this->assertEquals(array("myFieldName" => '<a href=\\"custom-admin/$ID\\">$ID</a>'), $columns->getFieldFormatting()); }
/** * Retrieves an instance of a GridFieldPaginator attached to the same control * @param GridField $gridField The parent gridfield * @return GridFieldPaginator The attached GridFieldPaginator, if found. * @throws LogicException */ protected function getPaginator($gridField) { /** @var GridFieldPaginator $paginator */ $paginator = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldPaginator'); if (!$paginator && $this->config()->get('require_paginator')) { throw new LogicException(get_class($this) . " relies on a GridFieldPaginator to be added " . "to the same GridField, but none are present."); } return $paginator; }
/** * @covers SilverStripe\Forms\GridField\GridFieldConfig::__construct * @covers SilverStripe\Forms\GridField\GridFieldConfig::addComponent */ public function testGridFieldSetCustomConfig() { $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldDataColumns()); $obj = new GridField('testfield', 'testfield', ArrayList::create(array()), $config); $expectedComponents = new ArrayList(array(0 => new GridFieldSortableHeader(), 1 => new GridFieldDataColumns(), 2 => new GridState_Component())); $this->assertEquals($expectedComponents, $obj->getConfig()->getComponents(), 'Testing default Config'); }
/** * Test getManipulatedData on subclassed dataobjects */ public function testInheritedGetManiplatedData() { $list = GridFieldSortableHeaderTest_TeamGroup::get(); $config = new GridFieldConfig_RecordEditor(); $gridField = new GridField('testfield', 'testfield', $list, $config); $state = $gridField->State->GridFieldSortableHeader; $compontent = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldSortableHeader'); // Test that inherited dataobjects will work correctly $state->SortColumn = 'Cheerleader.Hat.Colour'; $state->SortDirection = 'asc'; $relationListA = $compontent->getManipulatedData($gridField, $list); $relationListAsql = Convert::nl2os($relationListA->sql(), ' '); // Assert that all tables are joined properly $this->assertContains('FROM "GridFieldSortableHeaderTest_Team"', $relationListAsql); $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_TeamGroup" ' . 'ON "GridFieldSortableHeaderTest_TeamGroup"."ID" = "GridFieldSortableHeaderTest_Team"."ID"', $relationListAsql); $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Cheerleader" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Team"."CheerleaderID"', $relationListAsql); $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_CheerleaderHat" ' . 'ON "GridFieldSortableHeaderTest_CheerleaderHat"."ID" = "GridFieldSortableHeaderTest_Cheerleader"."HatID"', $relationListAsql); // Test sorting is correct $this->assertEquals(array('Cologne', 'Auckland', 'Wellington', 'Melbourne'), $relationListA->column('City')); $state->SortDirection = 'desc'; $relationListAdesc = $compontent->getManipulatedData($gridField, $list); $this->assertEquals(array('Melbourne', 'Wellington', 'Auckland', 'Cologne'), $relationListAdesc->column('City')); // Test subclasses of tables $state->SortColumn = 'CheerleadersMom.Hat.Colour'; $state->SortDirection = 'asc'; $relationListB = $compontent->getManipulatedData($gridField, $list); $relationListBsql = $relationListB->sql(); // Assert that subclasses are included in the query $this->assertContains('FROM "GridFieldSortableHeaderTest_Team"', $relationListBsql); $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_TeamGroup" ' . 'ON "GridFieldSortableHeaderTest_TeamGroup"."ID" = "GridFieldSortableHeaderTest_Team"."ID"', $relationListBsql); // Joined tables are joined basetable first $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Cheerleader" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Team"."CheerleadersMomID"', $relationListBsql); // Then the basetable of the joined record is joined to the specific subtable $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Mom" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Mom"."ID"', $relationListBsql); $this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_CheerleaderHat" ' . 'ON "GridFieldSortableHeaderTest_CheerleaderHat"."ID" = "GridFieldSortableHeaderTest_Cheerleader"."HatID"', $relationListBsql); // Test sorting is correct $this->assertEquals(array('Cologne', 'Auckland', 'Wellington', 'Melbourne'), $relationListB->column('City')); $state->SortDirection = 'desc'; $relationListBdesc = $compontent->getManipulatedData($gridField, $list); $this->assertEquals(array('Melbourne', 'Wellington', 'Auckland', 'Cologne'), $relationListBdesc->column('City')); }
/** * Return the columns to export * * @param GridField $gridField * * @return array */ protected function getExportColumnsForGridField(GridField $gridField) { if ($this->exportColumns) { return $this->exportColumns; } /** @var GridFieldDataColumns $dataCols */ $dataCols = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); if ($dataCols) { return $dataCols->getDisplayFields($gridField); } return DataObject::singleton($gridField->getModelClass())->summaryFields(); }
public function Form() { // GridField lists categories for a specific person $person = GridFieldDetailFormTest_Person::get()->sort('FirstName')->First(); $detailFields = singleton('GridFieldDetailFormTest_Category')->getCMSFields(); $detailFields->addFieldsToTab('Root.Main', array(new CheckboxField('ManyMany[IsPublished]'), new TextField('ManyMany[PublishedBy]'))); $categoriesField = new GridField('testfield', 'testfield', $person->Categories()); $categoriesField->getConfig()->addComponent($gridFieldForm = new GridFieldDetailForm($this, 'SilverStripe\\Forms\\Form')); $gridFieldForm->setFields($detailFields); $categoriesField->getConfig()->addComponent(new GridFieldToolbarHeader()); $categoriesField->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right')); $categoriesField->getConfig()->addComponent(new GridFieldEditButton()); $favGroupsField = new GridField('testgroupsfield', 'testgroupsfield', $person->FavouriteGroups()); /** @skipUpgrade */ $favGroupsField->getConfig()->addComponent(new GridFieldDetailForm($this, 'Form')); $favGroupsField->getConfig()->addComponent(new GridFieldToolbarHeader()); $favGroupsField->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right')); $favGroupsField->getConfig()->addComponent(new GridFieldEditButton()); $fields = new FieldList($categoriesField, $favGroupsField); /** @skipUpgrade */ return new Form($this, 'Form', $fields, new FieldList()); }