Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 28, 2022
1 parent f3f2335 commit ad6d084
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions code/Extension/UserFormFieldEditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function updateCMSFields(FieldList $fields)
{
$fieldEditor = $this->getFieldEditorGrid();

$fields->insertAfter(new Tab('FormFields', _t(__CLASS__.'.FORMFIELDS', 'Form Fields')), 'Main');
$fields->insertAfter('Main', new Tab('FormFields', _t(__CLASS__.'.FORMFIELDS', 'Form Fields')));
$fields->addFieldToTab('Root.FormFields', $fieldEditor);

return $fields;
Expand Down Expand Up @@ -192,7 +192,7 @@ public function onAfterPublish()
foreach ($this->owner->Fields() as $field) {
// store any IDs of fields we publish so we don't unpublish them
$seenIDs[] = $field->ID;
$field->doPublish(Versioned::DRAFT, Versioned::LIVE);
$field->publishRecursive();
$field->destroy();
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public function isModifiedOnDraft()
public function onAfterRevertToLive()
{
foreach ($this->owner->Fields() as $field) {
$field->copyVersionToStage(Versioned::LIVE, Versioned::DRAFT, false);
$field->copyVersionToStage(Versioned::LIVE, Versioned::DRAFT);
$field->writeWithoutVersion();
}
}
Expand Down
4 changes: 2 additions & 2 deletions code/Model/EditableFormField/EditableFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public function getSubmittedFormField()
*/
public static function get_php_max_file_size()
{
$maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
$maxPost = File::ini2bytes(ini_get('post_max_size'));
$maxUpload = Convert::memstring2bytes(ini_get('upload_max_filesize'));
$maxPost = Convert::memstring2bytes(ini_get('post_max_size'));
return min($maxUpload, $maxPost);
}

Expand Down
9 changes: 3 additions & 6 deletions code/Model/EditableFormField/EditableMultipleOptionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,13 @@ public function getCMSFields()
* Duplicate a pages content. We need to make sure all the fields attached
* to that page go with it
*
* @param bool $doWrite @deprecated
* @param string $manyMany @deprecated
* {@inheritDoc}
*/
public function duplicate($doWrite = true, $manyMany = 'many_many')
{
// Versioned 1.0 has a bug where [] will result in _all_ relations being duplicated
if ($manyMany === 'many_many' && !$this->manyMany()) {
$manyMany = null;
}

$clonedNode = parent::duplicate(true, $manyMany);
$clonedNode = parent::duplicate(true);

foreach ($this->Options() as $field) {
/** @var EditableOption $newField */
Expand Down
4 changes: 2 additions & 2 deletions code/Model/Recipient/EmailRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ public function getCMSFields()

if ($templates) {
$fields->insertBefore(
'EmailBodyHtml',
DropdownField::create(
'EmailTemplate',
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILTEMPLATE', 'Email template'),
$templates
)->addExtraClass('toggle-html-only'),
'EmailBodyHtml'
)->addExtraClass('toggle-html-only')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<nav aria-label="Pages in this form">
<ul class="step-buttons">
<% loop $Steps %>
<li class="step-button-wrapper<% if $First %> current<% end_if %>" data-for="$Name">
<li class="step-button-wrapper<% if $IsFirst %> current<% end_if %>" data-for="$Name">
<%-- Remove js-align class to remove javascript positioning --%>
<button class="step-button-jump js-align" disabled="disabled" data-step="$Pos"><% if $Top.ButtonText %>$Top.ButtonText <% end_if %>$Pos</button>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testValidateAddsErrorWhenMinValueIsGreaterThanMaxValue()

$result = $field->validate();
$this->assertFalse($result->isValid(), 'Validation should fail when min is greater than max');
$this->assertStringContainsString('Minimum length should be less than the maximum length', $result->serialize());
$this->assertStringContainsString('Minimum length should be less than the maximum length', $result->__serialize());
}

public function testValidate()
Expand Down
3 changes: 3 additions & 0 deletions tests/php/Model/EditableFormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function testFormFieldPermissions()

public function testCustomRules()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture(UserDefinedForm::class, 'custom-rules-form');

Expand Down
7 changes: 4 additions & 3 deletions tests/php/Model/UserDefinedFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UserDefinedFormTest extends FunctionalTest
protected function setUp(): void
{
parent::setUp();
Email::config()->update('admin_email', 'no-reply@example.com');
Email::config()->set('admin_email', 'no-reply@example.com');
}

public function testRollbackToVersion()
Expand All @@ -51,6 +51,7 @@ public function testRollbackToVersion()

// @todo
$this->logInWithPermission('ADMIN');
/** @var UserDefinedForm|Versioned $form */
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');

$form->SubmitButtonText = 'Button Text';
Expand All @@ -66,7 +67,7 @@ public function testRollbackToVersion()
$updated = Versioned::get_one_by_stage(UserDefinedForm::class, 'Stage', "\"UserDefinedForm\".\"ID\" = $form->ID");
$this->assertEquals($updated->SubmitButtonText, 'Updated Button Text');

$form->doRollbackTo($origVersion);
$form->rollbackRecursive($origVersion);

$orignal = Versioned::get_one_by_stage(UserDefinedForm::class, 'Stage', "\"UserDefinedForm\".\"ID\" = $form->ID");
$this->assertEquals($orignal->SubmitButtonText, 'Button Text');
Expand Down Expand Up @@ -521,7 +522,7 @@ public function testIndex()
{
// Test that the $UserDefinedForm is stripped out
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$page->publish('Stage', 'Live');
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);

$result = $this->get($page->Link());
$body = Convert::nl2os($result->getBody(), ''); // strip out newlines
Expand Down

0 comments on commit ad6d084

Please sign in to comment.