Skip to content

Commit ab1d4f5

Browse files
authored
PHPUnit: added/updated tests (#4758)
* tests * rector * updated test groups * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * updated tests * update * update * update * update * update * typo * updated tests * updated tests * updated tests * updated tests * sonar 1 * sonar 2 * phpcs/phpstan * sonar 4 * sonar 5 * sonar 6 * phpcs * copyright, ref #4767 * added Makefile * merge fix * reverted all changes to core files * Revert "reverted all changes to core files" This reverts commit 63e5f77.
1 parent 11a4abf commit ab1d4f5

File tree

183 files changed

+4982
-3361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+4982
-3361
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/README.md export-ignore
2525

26+
/Makefile export-ignore
27+
2628
# Enforce checkout with linux lf consistent over all platforms
2729
*.html text eol=lf
2830
*.css text eol=lf

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
phpunit-result-cache-
100100
101101
- name: Run phpUnit
102-
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml
102+
run: php vendor/bin/phpunit --configuration .phpunit.dist.xml --testsuite Base,Error,Mage,Varien
103103

104104
- name: Save result cache
105105
uses: actions/cache/save@v4

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
1616
'nullable_type_declaration_for_default_null_value' => true,
1717
// Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::
18-
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
18+
'php_unit_test_case_static_method_calls' => ['call_type' => 'static'],
1919
// Convert double quotes to single quotes for simple strings.
2020
'single_quote' => true,
2121
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.

.phpunit.dist.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,81 @@
3131
<testsuite name="Mage">
3232
<directory>tests/unit/Mage</directory>
3333
</testsuite>
34+
<testsuite name="Mage_Admin">
35+
<directory>tests/unit/Mage/Admin</directory>
36+
</testsuite>
37+
<testsuite name="Mage_Adminhtml">
38+
<directory>tests/unit/Mage/Adminhtml</directory>
39+
</testsuite>
40+
<testsuite name="Mage_AdminNotification">
41+
<directory>tests/unit/Mage/AdminNotification</directory>
42+
</testsuite>
43+
<testsuite name="Mage_Api">
44+
<directory>tests/unit/Mage/Api</directory>
45+
</testsuite>
46+
<testsuite name="Mage_Catalog">
47+
<directory>tests/unit/Mage/Catalog</directory>
48+
</testsuite>
49+
<testsuite name="Mage_Cms">
50+
<directory>tests/unit/Mage/Cms</directory>
51+
</testsuite>
52+
<testsuite name="Mage_Contacts">
53+
<directory>tests/unit/Mage/Contacts</directory>
54+
</testsuite>
55+
<testsuite name="Mage_Core">
56+
<directory>tests/unit/Mage/Core</directory>
57+
</testsuite>
58+
<testsuite name="Mage_Customer">
59+
<directory>tests/unit/Mage/Customer</directory>
60+
</testsuite>
61+
<testsuite name="Mage_Directory">
62+
<directory>tests/unit/Mage/Directory</directory>
63+
</testsuite>
64+
<testsuite name="Mage_Downloadable">
65+
<directory>tests/unit/Mage/Downloadable</directory>
66+
</testsuite>
67+
<testsuite name="Mage_Eav">
68+
<directory>tests/unit/Mage/Eav</directory>
69+
</testsuite>
70+
<testsuite name="Mage_GiftMessage">
71+
<directory>tests/unit/Mage/GiftMessage</directory>
72+
</testsuite>
73+
<testsuite name="Mage_Index">
74+
<directory>tests/unit/Mage/Index</directory>
75+
</testsuite>
76+
<testsuite name="Mage_Log">
77+
<directory>tests/unit/Mage/Log</directory>
78+
</testsuite>
79+
<testsuite name="Mage_Newsletter">
80+
<directory>tests/unit/Mage/Newsletter</directory>
81+
</testsuite>
82+
<testsuite name="Mage_Page">
83+
<directory>tests/unit/Mage/Page</directory>
84+
</testsuite>
85+
<testsuite name="Mage_Reports">
86+
<directory>tests/unit/Mage/Reports</directory>
87+
</testsuite>
88+
<testsuite name="Mage_Review">
89+
<directory>tests/unit/Mage/Review</directory>
90+
</testsuite>
91+
<testsuite name="Mage_Rule">
92+
<directory>tests/unit/Mage/Rule</directory>
93+
</testsuite>
94+
<testsuite name="Mage_Sales">
95+
<directory>tests/unit/Mage/Sales</directory>
96+
</testsuite>
97+
<testsuite name="Mage_Sitemap">
98+
<directory>tests/unit/Mage/Sitemap</directory>
99+
</testsuite>
100+
<testsuite name="Mage_Tax">
101+
<directory>tests/unit/Mage/Tax</directory>
102+
</testsuite>
103+
<testsuite name="Mage_Uploader">
104+
<directory>tests/unit/Mage/Uploader</directory>
105+
</testsuite>
106+
<testsuite name="Mage_Wishlist">
107+
<directory>tests/unit/Mage/Wishlist</directory>
108+
</testsuite>
34109
<testsuite name="Varien">
35110
<directory>tests/unit/Varien</directory>
36111
</testsuite>

.rector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Rector\Php82\Rector as Php82;
1818
use Rector\Php83\Rector as Php83;
1919
use Rector\Php84\Rector as Php84;
20+
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
2021
use Rector\TypeDeclaration\Rector as TypeDeclaration;
2122

2223
try {
@@ -49,6 +50,8 @@
4950
Php80\Class_\ClassPropertyAssignToConstructorPromotionRector::class, # todo: wait for php80
5051
Php80\Class_\StringableForToStringRector::class, # todo: wait for php80
5152
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
53+
# use static methods
54+
PreferPHPUnitThisCallRector::class,
5255
__DIR__ . '/shell/translations.php',
5356
__DIR__ . '/shell/update-copyright.php',
5457
__DIR__ . '/tests/unit/Mage/Reports/Model/Resource/Report/CollectionTest.php',

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mkdocs-serve:
2+
@if command -v mkdocs >/dev/null ; then \
3+
mkdocs serve; \
4+
else \
5+
echo "mkdocs is not installed, see https://docs.openmage.org/developers/mkdocs/" && exit 2; \
6+
fi; \
7+
8+
phpunit-serve:
9+
@if test -f build/coverage/index.html ; then \
10+
xdg-open build/coverage/index.html; \
11+
else \
12+
echo "phpunit coverage not found, run \"composer run phpunit:coverage-local\"" && exit 2; \
13+
fi; \

app/code/core/Mage/Adminhtml/Block/Cache/Grid.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ public function decorateStatus($value, $row, $column, $isExport)
107107
{
108108
$class = '';
109109
if (isset($this->_invalidatedTypes[$row->getId()])) {
110-
$cell = '<span class="grid-severity-minor"><span>' . $this->__('Invalidated') . '</span></span>';
110+
$class = self::CSS_SEVERITY_MINOR;
111+
$value = $this->__('Invalidated');
112+
} elseif ($row->getStatus()) {
113+
$class = self::CSS_SEVERITY_NOTICE;
111114
} else {
112-
if ($row->getStatus()) {
113-
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
114-
} else {
115-
$cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>';
116-
}
115+
$class = self::CSS_SEVERITY_CRITICAL;
117116
}
118-
return $cell;
117+
return sprintf(self::PATTERN_SEVERITY, $class, $value);
119118
}
120119

121120
/**

app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
1616
*/
1717

18+
use Mage_Adminhtml_Block_Widget_Grid_Massaction_Abstract as MassAction;
19+
1820
/**
1921
* Adminhtml permissions orphanedResource grid
2022
*
@@ -75,7 +77,7 @@ protected function _prepareMassaction()
7577
$this->setMassactionIdField('resource_id');
7678
$this->getMassactionBlock()->setFormFieldName('resource_id');
7779

78-
$this->getMassactionBlock()->addItem('delete', [
80+
$this->getMassactionBlock()->addItem(MassAction::DELETE, [
7981
'label' => Mage::helper('adminhtml')->__('Delete'),
8082
'url' => $this->getUrl('*/*/massDelete'),
8183
'confirm' => Mage::helper('adminhtml')->__('Are you sure you want to do this?'),

app/code/core/Mage/Adminhtml/Block/Widget/Grid.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
*/
2626
class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget
2727
{
28+
public const PATTERN_SEVERITY = '<span class="%s"><span>%s</span></span>';
29+
public const CSS_SEVERITY_CRITICAL = 'grid-severity-critical';
30+
public const CSS_SEVERITY_MAJOR = 'grid-severity-major';
31+
public const CSS_SEVERITY_MINOR = 'grid-severity-minor';
32+
public const CSS_SEVERITY_NOTICE = 'grid-severity-notice';
33+
2834
/**
2935
* Columns array
3036
*

app/code/core/Mage/Cms/Block/Widget/Page/Link.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function getHref()
6868
* as parameter or retrieve page title from DB using passed identifier or page id.
6969
*
7070
* @return string
71+
* @throws Mage_Core_Model_Store_Exception
7172
*/
7273
public function getTitle()
7374
{
@@ -77,10 +78,9 @@ public function getTitle()
7778
// compare to null used here bc user can specify blank title
7879
$this->_title = $this->getData('title');
7980
} elseif ($this->getData('page_id')) {
80-
$this->_title = Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($this->getData('page_id'));
81+
$this->_title = $this->getCmsPageTitleById($this->getData('page_id'));
8182
} elseif ($this->getData('href')) {
82-
$this->_title = Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
83-
->getCmsPageTitleByIdentifier($this->getData('href'));
83+
$this->_title = $this->getCmsPageTitleByIdentifier($this->getData('href'));
8484
}
8585
}
8686

@@ -93,6 +93,7 @@ public function getTitle()
9393
* if title will be blank string, page identifier will be used.
9494
*
9595
* @return string
96+
* @throws Mage_Core_Model_Store_Exception
9697
*/
9798
public function getAnchorText()
9899
{
@@ -101,14 +102,27 @@ public function getAnchorText()
101102
} elseif ($this->getTitle()) {
102103
$this->_anchorText = $this->getTitle();
103104
} elseif ($this->getData('href')) {
104-
$this->_anchorText = Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
105-
->getCmsPageTitleByIdentifier($this->getData('href'));
105+
$this->_anchorText = $this->getCmsPageTitleByIdentifier($this->getData('href'));
106106
} elseif ($this->getData('page_id')) {
107-
$this->_anchorText = Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($this->getData('page_id'));
107+
$this->_anchorText = $this->getCmsPageTitleById($this->getData('page_id'));
108108
} else {
109109
$this->_anchorText = $this->getData('href');
110110
}
111111

112112
return $this->_anchorText;
113113
}
114+
115+
protected function getCmsPageTitleById(int|string $pageId): string
116+
{
117+
return Mage::getResourceSingleton('cms/page')->getCmsPageTitleById($pageId);
118+
}
119+
120+
/**
121+
* @throws Mage_Core_Model_Store_Exception
122+
*/
123+
protected function getCmsPageTitleByIdentifier(int|string $identifier): string
124+
{
125+
return Mage::getResourceSingleton('cms/page')->setStore(Mage::app()->getStore())
126+
->getCmsPageTitleByIdentifier($identifier);
127+
}
114128
}

0 commit comments

Comments
 (0)