silverstripe-userforms/tests/Extension/UserFormFieldEditorExtensionTest.php
Dylan Wagstaff a42729679b
FIX account for owner class while removing orphans (#1018)
* FIX account for owner class while removing orphans
* Explicitly set $page and $block ID's in test fixture

Co-authored-by: Steve Boyd <emteknetnz@gmail.com>
2021-01-17 15:29:33 +13:00

78 lines
2.6 KiB
PHP

<?php
namespace SilverStripe\UserForms\Tests\Extension;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Versioned\Versioned;
class UserFormFieldEditorExtensionTest extends SapphireTest
{
protected static $fixture_file = 'UserFormFieldEditorExtensionTest.yml';
protected static $extra_dataobjects = [
UserFormBlockStub::class,
];
protected function setUp()
{
parent::setUp();
$page = $this->objFromFixture(UserDefinedForm::class, 'page');
$block = $this->objFromFixture(UserFormBlockStub::class, 'block');
$page->publishRecursive();
$block->publishRecursive();
}
public function testOrphanRemovalDoesNotAffectOtherClassesWithTheSameID()
{
$page = $this->objFromFixture(UserDefinedForm::class, 'page');
$block = $this->objFromFixture(UserFormBlockStub::class, 'block');
// assert setup
$this->assertSame($page->ID, $block->ID);
$this->assertCount(1, $page->Fields());
$this->assertCount(3, $block->Fields());
// ensure setup has affected live mode too
$origReadingMode = Versioned::get_reading_mode();
Versioned::set_reading_mode(Versioned::LIVE);
$initialLivePage = UserDefinedForm::get()->First();
$initialLiveBlock = UserFormBlockStub::get()->First();
$this->assertSame($initialLivePage->ID, $initialLiveBlock->ID);
$this->assertCount(1, $initialLivePage->Fields());
$this->assertCount(3, $initialLiveBlock->Fields());
Versioned::set_reading_mode($origReadingMode);
// execute change
$newField = new EditableEmailField();
$newField->update([
'Name' => 'basic_email_name',
'Title' => 'Page Email Field'
]);
$page->Fields()->add($newField);
$page->publishRecursive();
// assert effect of change
$checkPage = UserDefinedForm::get()->First();
$checkBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkPage->Fields());
$this->assertCount(3, $checkBlock->Fields());
// ensure this is true for live mode too
$origReadingMode = Versioned::get_reading_mode();
Versioned::set_reading_mode(Versioned::LIVE);
$checkLivePage = UserDefinedForm::get()->First();
$checkLiveBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkLivePage->Fields());
$this->assertCount(3, $checkLiveBlock->Fields());
Versioned::set_reading_mode($origReadingMode);
}
}