Skip to content

Commit

Permalink
Fixed unit test incompatibility with PHPUnit 9.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
UndefinedOffset committed Jul 28, 2023
1 parent 2493f61 commit 22bfe19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.buildpath
/.project
/.settings
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SilverStripe GridField Deleted Items
=================
[![CI](https://github.com/webbuilders-group/silverstripe-gridfield-deleted-items/actions/workflows/ci.yml/badge.svg)](https://github.com/webbuilders-group/silverstripe-versioned-helpers/actions/workflows/ci.yml)
[![CI](https://github.com/webbuilders-group/silverstripe-gridfield-deleted-items/actions/workflows/ci.yml/badge.svg)](https://github.com/webbuilders-group/silverstripe-gridfield-deleted-items/actions/workflows/ci.yml)

Provides a series of components that allows you to view versioned objects that have been deleted from the draft site.

Expand Down
33 changes: 15 additions & 18 deletions tests/Forms/GridField/GridFieldDeletedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,37 @@

use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedColumns;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedDeleteAction;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedEditButton;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedManipulator;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedRestoreButton;
use WebbuildersGroup\GridFieldDeletedItems\Forms\GridFieldDeletedToggle;
use WebbuildersGroup\GridFieldDeletedItems\Tests\GridFieldDeletedTest\DummyController;
use WebbuildersGroup\GridFieldDeletedItems\Tests\GridFieldDeletedTest\TestObject;

class GridFieldDeletedTest extends FunctionalTest
{
protected static $fixture_file = 'GridFieldDeletedTest.yml';
protected static $extra_dataobjects = [GridFieldDeletedTest\TestObject::class];
protected static $extra_dataobjects = [TestObject::class];

protected $list;
protected $gridField;
protected $form;

public function setUp()
protected function setUp(): void
{
parent::setUp();

$this->list = GridFieldDeletedTest\TestObject::get();
$this->list = TestObject::get();
$config = GridFieldConfig_RecordEditor::create(10)
->removeComponentsByType(GridFieldDataColumns::class)
->removeComponentsByType(GridFieldEditButton::class)
Expand All @@ -47,7 +44,7 @@ public function setUp()
->addComponent(new GridFieldDeletedToggle('buttons-before-left'));

$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
$this->form = new Form(new GridFieldDeletedTest\DummyController(), 'mockform', new FieldList([$this->gridField]), new FieldList());
$this->form = new Form(new DummyController(), 'mockform', new FieldList([$this->gridField]), new FieldList());
}

/**
Expand All @@ -56,7 +53,7 @@ public function setUp()
public function testToggleShowDeleted()
{
$deletedIDs = [];
$list = GridFieldDeletedTest\TestObject::get();
$list = TestObject::get();
foreach ($list as $item) {
if ($item->ID % 2 == 0) {
$deletedIDs[] = $item->ID;
Expand Down Expand Up @@ -103,13 +100,13 @@ public function testToggleShowDeleted()
public function testRestoreDeleted()
{
// Load the item to delete and capture it's id then delete it
$deletedItem = $this->objFromFixture(GridFieldDeletedTest\TestObject::class, 'testobj2');
$deletedItem = $this->objFromFixture(TestObject::class, 'testobj2');
$deletedItemID = $deletedItem->ID;
$deletedItem->delete();


// Make sure the item was deleted
$this->assertNull(Versioned::get_one_by_stage(GridFieldDeletedTest\TestObject::class, 'Stage', '"ID"=' . $deletedItemID), 'Item was not deleted prior to restoring');
$this->assertNull(Versioned::get_one_by_stage(TestObject::class, 'Stage', '"ID"=' . $deletedItemID), 'Item was not deleted prior to restoring');


// Attempt to restore the item
Expand All @@ -123,8 +120,8 @@ public function testRestoreDeleted()


// Check to see if the item exists again
$item = Versioned::get_one_by_stage(GridFieldDeletedTest\TestObject::class, 'Stage', '"Title"=\'Test Object 2\'');
$this->assertInstanceOf(GridFieldDeletedTest\TestObject::class, $item, 'Could not find the item after restoring');
$item = Versioned::get_one_by_stage(TestObject::class, 'Stage', '"Title"=\'Test Object 2\'');
$this->assertInstanceOf(TestObject::class, $item, 'Could not find the item after restoring');
$this->assertTrue($item->exists(), 'Could not find the item after restoring');
}

Expand All @@ -134,7 +131,7 @@ public function testRestoreDeleted()
public function testDeletedNoEdit()
{
// Load the item to delete and capture it's id then delete it
$deletedItem = $this->objFromFixture(GridFieldDeletedTest\TestObject::class, 'testobj2');
$deletedItem = $this->objFromFixture(TestObject::class, 'testobj2');
$deletedItem->delete();


Expand All @@ -147,7 +144,7 @@ public function testDeletedNoEdit()


// Verify we have an array and the class attribute exists
$this->assertInternalType('array', $attributes);
$this->assertIsArray($attributes);
$this->assertArrayHasKey('class', $attributes);


Expand All @@ -157,11 +154,11 @@ public function testDeletedNoEdit()


// Get the attributes for a non-deleted item
$attributes = $this->gridField->getConfig()->getComponentByType(GridFieldDeletedColumns::class)->getColumnAttributes($this->gridField, $this->objFromFixture(GridFieldDeletedTest\TestObject::class, 'testobj1'), 'Title');
$attributes = $this->gridField->getConfig()->getComponentByType(GridFieldDeletedColumns::class)->getColumnAttributes($this->gridField, $this->objFromFixture(TestObject::class, 'testobj1'), 'Title');


// Verify we have an array and the class attribute exists
$this->assertInternalType('array', $attributes);
$this->assertIsArray($attributes);
$this->assertArrayHasKey('class', $attributes);


Expand Down
1 change: 0 additions & 1 deletion tests/Forms/GridField/GridFieldDeletedTest/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use WebbuildersGroup\GridFieldDeletedItems\Tests\GridFieldDeletedTest_TestObject;

class TestObject extends DataObject implements TestOnly
{
Expand Down

0 comments on commit 22bfe19

Please sign in to comment.