list = new DataList(Team::class); $config = GridFieldConfig::create()->addComponent(new GridFieldEditButton()); $this->gridField = new GridField('testfield', 'testfield', $this->list, $config); $this->form = new Form(null, 'mockform', new FieldList([$this->gridField]), new FieldList()); } public function testShowEditLinks() { if (Security::getCurrentUser()) { Security::setCurrentUser(null); } $content = new CSSContentParser($this->gridField->FieldHolder()); // Check that there are content $this->assertEquals(4, count($content->getBySelector('.ss-gridfield-item'))); // Make sure that there are edit links, even though the user doesn't have "edit" permissions // (they can still view the records) $this->assertEquals( 3, count($content->getBySelector('.edit-link')), 'Edit links should show when not logged in.' ); } public function testShowEditLinksWithAdminPermission() { $this->logInWithPermission('ADMIN'); $content = new CSSContentParser($this->gridField->FieldHolder()); $editLinks = $content->getBySelector('.edit-link'); $this->assertEquals(3, count($editLinks), 'Edit links should show when logged in.'); } public function testDefaultClassesAreSet() { $button = new GridFieldEditButton; $expected = [ 'grid-field__icon-action--hidden-on-hover', 'font-icon-edit', 'btn--icon-large' ]; $result = $button->getExtraClass(); foreach ($expected as $className) { $this->assertStringContainsString($className, $result); } } public function testAddAndRemoveExtraClass() { $button = new GridFieldEditButton; $button->addExtraClass('foobar'); $this->assertStringContainsString('foobar', $button->getExtraClass()); $button->removeExtraClass('foobar'); $this->assertStringNotContainsString('foobar', $button->getExtraClass()); // Check that duplicates are removed $button->addExtraClass('foobar'); $button->addExtraClass('foobar'); $button->removeExtraClass('foobar'); $this->assertStringNotContainsString('foobar', $button->getExtraClass()); } }