Skip to content

Commit 553259b

Browse files
ENGCOM-6361: No marginal white space validation added #25808
2 parents 9fd136a + 458d2eb commit 553259b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Block/SaveTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,58 @@ public function testSaveAndClose()
373373
$this->assertSame($this->resultRedirect, $this->saveController->execute());
374374
}
375375

376+
public function testSaveActionWithMarginalSpace()
377+
{
378+
$postData = [
379+
'title' => 'unique_title_123',
380+
'identifier' => ' unique_title_123',
381+
'stores' => ['0'],
382+
'is_active' => true,
383+
'content' => '',
384+
'back' => 'continue'
385+
];
386+
387+
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn($postData);
388+
$this->requestMock->expects($this->atLeastOnce())
389+
->method('getParam')
390+
->willReturnMap(
391+
[
392+
['block_id', null, 1],
393+
['back', null, true],
394+
]
395+
);
396+
397+
$this->blockFactory->expects($this->atLeastOnce())
398+
->method('create')
399+
->willReturn($this->blockMock);
400+
401+
$this->blockRepository->expects($this->once())
402+
->method('getById')
403+
->with($this->blockId)
404+
->willReturn($this->blockMock);
405+
406+
$this->blockMock->expects($this->once())->method('setData');
407+
$this->blockRepository->expects($this->once())->method('save')
408+
->with($this->blockMock)
409+
->willThrowException(new \Exception('No marginal white space please.'));
410+
411+
$this->messageManagerMock->expects($this->never())
412+
->method('addSuccessMessage');
413+
$this->messageManagerMock->expects($this->once())
414+
->method('addExceptionMessage');
415+
416+
$this->dataPersistorMock->expects($this->any())
417+
->method('set')
418+
->with('cms_block', array_merge($postData, ['block_id' => null]));
419+
420+
$this->resultRedirect->expects($this->atLeastOnce())
421+
->method('setPath')
422+
->with('*/*/edit', ['block_id' => $this->blockId])
423+
->willReturnSelf();
424+
425+
$this->assertSame($this->resultRedirect, $this->saveController->execute());
426+
}
427+
376428
public function testSaveActionThrowsException()
377429
{
378430
$postData = [

app/code/Magento/Cms/view/adminhtml/ui_component/cms_block_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<settings>
106106
<validation>
107107
<rule name="required-entry" xsi:type="boolean">true</rule>
108+
<rule name="no-marginal-whitespace" xsi:type="boolean">true</rule>
108109
</validation>
109110
<dataType>text</dataType>
110111
<label translate="true">Identifier</label>

0 commit comments

Comments
 (0)