Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3c5b768
Improved error message for CMS page delete
sreichel Oct 5, 2025
3595f78
Added basic cypress test
sreichel Oct 5, 2025
9c37f13
Improved config sort order
sreichel Oct 5, 2025
291970d
rename
sreichel Oct 5, 2025
0d4401e
update tests
sreichel Oct 5, 2025
adf183e
doc
sreichel Oct 5, 2025
4a82b2d
[skip-ci] typo
sreichel Oct 5, 2025
b4bd7b0
Merge branch 'main' into fix/cms-error-message
sreichel Oct 5, 2025
ce58c3a
locale fix
sreichel Oct 5, 2025
ec3a7ad
fix disable page
sreichel Oct 5, 2025
2f9f632
cypress screenshots
sreichel Oct 5, 2025
0de4657
Merge remote-tracking branch 'origin/fix/cms-error-message' into fix/…
sreichel Oct 5, 2025
d825873
bug fix
sreichel Oct 5, 2025
e630a0c
Update app/code/core/Mage/Cms/Model/Resource/Page.php
sreichel Oct 5, 2025
c3ea0aa
Update cypress/support/openmage/config/paths.js
sreichel Oct 5, 2025
1165a81
Update tests
sreichel Oct 5, 2025
3ed8490
template fix
sreichel Oct 5, 2025
5ac59d3
Update app/code/core/Mage/Cms/Model/Resource/Page.php
sreichel Oct 5, 2025
ed627be
Update app/code/core/Mage/Cms/Model/Resource/Page.php
sreichel Oct 5, 2025
831e142
Update app/code/core/Mage/Cms/Helper/Page.php
sreichel Oct 5, 2025
da5681f
Update store and website names in data provider
sreichel Oct 5, 2025
3f0e211
Refactor getScopeInfoFromConfigScope method
sreichel Oct 5, 2025
49e1498
Merge branch 'main' into fix/cms-error-message
kiatng Oct 9, 2025
36647ce
Merge branch 'main' into fix/cms-error-message
sreichel Oct 13, 2025
72d919f
Merge remote-tracking branch 'origin/fix/cms-error-message' into fix/…
sreichel Oct 13, 2025
84c7906
Merge branch 'main' into fix/cms-error-message
sreichel Oct 13, 2025
8bcd591
removed od files
sreichel Oct 13, 2025
517a05d
updated css
sreichel Oct 13, 2025
b3555df
Merge branch 'main' into fix/cms-error-message
sreichel Oct 14, 2025
ad025c1
translation
sreichel Oct 14, 2025
f924b0f
rector
sreichel Oct 14, 2025
77893b9
Merge branch 'main' into fix/cms-error-message
sreichel Oct 15, 2025
1f4335d
Merge branch 'main' into fix/cms-error-message
kiatng Oct 19, 2025
4d420bb
Merge branch 'main' into fix/cms-error-message
sreichel Oct 22, 2025
0bd62a0
Apply suggestions from code review
sreichel Oct 22, 2025
a416ade
wording
sreichel Oct 22, 2025
e60e90b
Merge remote-tracking branch 'origin/fix/cms-error-message' into fix/…
sreichel Oct 22, 2025
4a8de02
tests
sreichel Oct 22, 2025
e8f9828
wording
sreichel Oct 26, 2025
9f72428
typo
sreichel Oct 26, 2025
c9c9c94
test
sreichel Oct 26, 2025
badbfc3
Merge branch 'main' into fix/cms-error-message
sreichel Oct 27, 2025
478f66d
Merge branch 'main' into fix/cms-error-message
sreichel Oct 30, 2025
b39d400
Merge branch 'main' into fix/cms-error-message
sreichel Oct 31, 2025
88f43e5
message for ENV config
sreichel Oct 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions app/code/core/Mage/Cms/Helper/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,70 @@ public static function getUsedInStoreConfigPaths(?array $paths = []): array

return $searchPaths;
}

/**
* @param self::XML_PATH_* $path
*/
public static function getConfigLabelFromConfigPath(string $path): string
{
return match ($path) {
self::XML_PATH_NO_ROUTE_PAGE => Mage::helper('cms')->__('No Route Page'),
self::XML_PATH_NO_COOKIES_PAGE => Mage::helper('cms')->__('No Cookies Page'),
self::XML_PATH_HOME_PAGE => Mage::helper('cms')->__('Home Page'),
default => $path,
};
}

/**
* @param Mage_Adminhtml_Block_System_Config_Form::SCOPE_* $scope
* @throws Mage_Core_Exception
*/
public static function getScopeInfoFromConfigScope(string $scope, string $scopeId): string
{
return match ($scope) {
Mage_Adminhtml_Block_System_Config_Form::SCOPE_DEFAULT => Mage::helper('cms')->__('Default Config'),
Mage_Adminhtml_Block_System_Config_Form::SCOPE_WEBSITES => sprintf(
'%s "%s"',
Mage::helper('cms')->__('Website'),
Mage::app()->getWebsite($scopeId)->getName(),
),
Mage_Adminhtml_Block_System_Config_Form::SCOPE_STORES => sprintf(
'%s "%s"',
Mage::helper('cms')->__('Store View'),
Mage::app()->getStore($scopeId)->getName(),
),
};
}

/**
* @throws Mage_Core_Exception
*/
public static function getValidateConfigErrorMessage(Mage_Core_Model_Resource_Db_Collection_Abstract $isUsedInConfig): string
{
$messages = [];

$data = $isUsedInConfig->getData();
foreach ($data as $key => $item) {
$path = $item['path'];
unset($item['config_id'], $item['path'], $item['updated_at'], $item['value']);
$data[$path][] = $item;
unset($data[$key], $key, $path);
}

foreach ($data as $path => $items) {
$scopes = [];
foreach ($items as $item) {
$scopes[] = self::getScopeInfoFromConfigScope($item['scope'], $item['scope_id']);
}

$messages[] = sprintf(
'"%s" (%s)',
self::getConfigLabelFromConfigPath($path),
implode(', ', $scopes),
);
}
unset($data, $path, $items, $item, $scopes);

return implode(', ', $messages);
}
}
12 changes: 7 additions & 5 deletions app/code/core/Mage/Cms/Model/Resource/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function _beforeDelete(Mage_Core_Model_Abstract $object)
$object->setId(null);
Mage::throwException(
Mage::helper('cms')->__(
'Cannot delete page, it is used in "%s".',
implode(', ', $isUsedInConfig->getColumnValues('path')),
'Cannot delete page, it is used in configuration %s.',
Mage_Cms_Helper_Page::getValidateConfigErrorMessage($isUsedInConfig),
),
);
}
Expand Down Expand Up @@ -79,8 +79,8 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object)
$object->setIsActive(true);
Mage::getSingleton('adminhtml/session')->addWarning(
Mage::helper('cms')->__(
'Cannot disable page, it is used in configuration "%s".',
implode(', ', $isUsedInConfig->getColumnValues('path')),
'Cannot disable page, it is used in configuration %s.',
Mage_Cms_Helper_Page::getValidateConfigErrorMessage($isUsedInConfig),
),
);
}
Expand Down Expand Up @@ -281,7 +281,9 @@ protected function isValidPageIdentifier(Mage_Core_Model_Abstract $object)

public function getUsedInStoreConfigCollection(Mage_Cms_Model_Page $page, ?array $paths = []): Mage_Core_Model_Resource_Db_Collection_Abstract
{
$storeIds = (array) $page->getStoreId();
$storeId = (array) $page->getStoreId(); # null on save
$stores = (array) $page->getStores(); # null on delete
$storeIds = array_merge($storeId, $stores);
$storeIds[] = Mage_Core_Model_App::ADMIN_STORE_ID;
$config = Mage::getResourceModel('core/config_data_collection')
->addFieldToFilter('value', $page->getIdentifier())
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Cms/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<label>CMS Home Page</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_cms_page</source_model>
<sort_order>1</sort_order>
<sort_order>21</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -26,7 +26,7 @@
<label>CMS No Route Page</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_cms_page</source_model>
<sort_order>2</sort_order>
<sort_order>22</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -35,7 +35,7 @@
<label>CMS No Cookies Page</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_cms_page</source_model>
<sort_order>3</sort_order>
<sort_order>23</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -44,7 +44,7 @@
<label>Show Breadcrumbs for CMS Pages</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>5</sort_order>
<sort_order>25</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down
4 changes: 2 additions & 2 deletions app/locale/en_US/Mage_Cms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"CMS Static Block","CMS Static Block"
"CMS Static Block Default Template","CMS Static Block Default Template"
"Cannot create new directory.","Cannot create new directory."
"Cannot delete page, it is used in ""%s"".","Cannot delete page, it is used in ""%s""."
"Cannot delete page, it is used in configuration %s.","Cannot delete page, it is used in configuration %s."
"Cannot delete directory %s.","Cannot delete directory %s."
"Cannot delete root directory %s.","Cannot delete root directory %s."
"Cannot disable page, it is used in configuration ""%s"".","Cannot disable page, it is used in configuration ""%s""."
"Cannot disable page, it is used in configuration %s.","Cannot disable page, it is used in configuration %s."
"Cannot upload file.","Cannot upload file."
"Collapse All","Collapse All"
"Content","Content"
Expand Down
28 changes: 28 additions & 0 deletions cypress/e2e/openmage/backend/cms/page.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const route = cy.testRoutes.backend.cms.page;
const validation = cy.openmage.validation;

describe(`Checks admin system "${route.h3}"`, () => {
beforeEach('Log in the user', () => {
Expand All @@ -9,4 +10,31 @@ describe(`Checks admin system "${route.h3}"`, () => {
it(`tests classes and title`, () => {
cy.adminTestRoute(route);
});

it('tests to disable a CMS page that is used in config', () => {
cy.log('Select a CMS page');
cy.get(route._gridTable)
.contains('td', 'no-route')
.click();

cy.log('Disable the CMS page');
cy.get('#page_is_active')
.select('Disabled');

validation.saveAction(route._buttonSaveAndContinue);
cy.get(validation._warningMessage).should('include.text', 'Cannot disable page, it is used in configuration');
cy.get(validation._successMessage).should('include.text', 'The page has been saved.');
cy.get('#messages').screenshot('error-disable-active-page', { overwrite: true});
});

it('tests to delete a CMS page that is used in config', () => {
cy.log('Select a CMS page');
cy.get(route._gridTable)
.contains('td', 'no-route')
.click();

validation.saveAction(route._buttonDelete);
cy.get(validation._errorMessage).should('include.text', 'Cannot delete page');
cy.get('#messages').screenshot('error-delete-active-page', { overwrite: true});
});
});
2 changes: 1 addition & 1 deletion cypress/support/openmage.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cy.openmage = {
},
saveAction: (selector) => {
cy.log('Clicking on Save button');
cy.get(selector).click({force: true, multiple: true});
cy.get(selector).first().click({force: true, multiple: false});
},
validateFields: (fields, validation) =>{
cy.log('Checking for error messages');
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/openmage/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ cy.testRoutes = {
url: 'cms_page/index',
h3: 'Manage Pages',
_h3: adminPage._h3,
_gridTable: '#cmsPageGrid_table',
_buttonDelete: '.form-buttons button[title="Delete Page"]',
_buttonReset: '.form-buttons button[title="Reset"]',
_buttonSave: '.form-buttons button[title="Save Page"]',
_buttonSaveAndContinue: '.form-buttons button[title="Save and Continue Edit"]',
},
widget: {
_id_parent: adminNav.cms,
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/Mage/Cms/Helper/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,32 @@ final class PageTest extends OpenMageTest
use CmsTrait;

/**
* @covers Mage_Cms_Helper_Page::getUsedInStoreConfigPaths()
* @dataProvider provideGetUsedInStoreConfigPaths
* @group Helper
*/
public function testGetUsedInStoreConfigPaths(array $expectedResult, ?array $path): void
{
self::assertSame($expectedResult, Subject::getUsedInStoreConfigPaths($path));
}

/**
* @covers Mage_Cms_Helper_Page::getConfigLabelFromConfigPath()
* @dataProvider provideGetConfigLabelFromConfigPath
* @group Helper
*/
public function testGetConfigLabelFromConfigPath(string $expectedResult, string $paths): void
{
self::assertSame($expectedResult, Subject::getConfigLabelFromConfigPath($paths));
}

/**
* @covers Mage_Cms_Helper_Page::getScopeInfoFromConfigScope()
* @dataProvider provideGetScopeInfoFromConfigScope
* @group Helper
*/
public function testGetScopeInfoFromConfigScope(string $expectedResult, string $scope, string $scopeId): void
{
self::assertStringStartsWith($expectedResult, Subject::getScopeInfoFromConfigScope($scope, $scopeId));
}
}
40 changes: 40 additions & 0 deletions tests/unit/Traits/DataProvider/Mage/Cms/CmsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace OpenMage\Tests\Unit\Traits\DataProvider\Mage\Cms;

use Generator;
use Mage_Adminhtml_Block_System_Config_Form;
use Mage_Cms_Helper_Page;

trait CmsTrait
Expand Down Expand Up @@ -45,6 +46,45 @@ public function provideGetUsedInStoreConfigPaths(): Generator
];
}

public function provideGetConfigLabelFromConfigPath(): Generator
{
yield 'home page' => [
'Home Page',
Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE,
];

yield 'no cookie page' => [
'No Cookies Page',
Mage_Cms_Helper_Page::XML_PATH_NO_COOKIES_PAGE,
];

yield 'no route page' => [
'No Route Page',
Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE,
];
}

public function provideGetScopeInfoFromConfigScope(): Generator
{
yield 'default' => [
'Default Config',
Mage_Adminhtml_Block_System_Config_Form::SCOPE_DEFAULT,
'1',
];

yield 'websites' => [
'Website',
Mage_Adminhtml_Block_System_Config_Form::SCOPE_WEBSITES,
'1',
];

yield 'stores' => [
'Store View',
Mage_Adminhtml_Block_System_Config_Form::SCOPE_STORES,
'1',
];
}

public function provideGetShortFilename(): Generator
{
yield 'full length' => [
Expand Down
Loading