Skip to content

Commit

Permalink
PHPUnit: added some tests (#4204)
Browse files Browse the repository at this point in the history
* Rector: CQ - UnusedForeachValueToArrayKeysRector (#1)

* Rector: CQ - UnusedForeachValueToArrayKeysRector

See Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector

* fixes + phpstan

See fix at rector: rectorphp/rector-src#6164

* Updated test

* Added test

* Added test

* Renamed and updated test

* Updated test

* Updated test

* Updated test

* Updated test

* Revert "Rector: CQ - UnusedForeachValueToArrayKeysRector (#1)"

This reverts commit 3d7eaf6.

* Updated test (phpstan L9)

* Updated test (fixed namespace)

* Updated test (phpstan L9)

* Added unit test to code style check and phpstan

* Some cleanup

* Some cleanup

* Some cleanup

* Updated workflow

* ddev shortcut [ski ci]

* Moved phphunit config file

* Merged phpunit & sonar workflow

* PhpUnit fix

 - PHP Deprecated:  str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/runner/work/magento-lts/magento-lts/lib/Varien/Object.php on line 594

* Fix linefeed (?)

* Fix config

* Fixed invalid php version

* Use minimum version

* Use minimum version for SonarScan

* Fix command [ski ci]

* Enable xdebug

* Added test, ref #4123

* Revert "Some cleanup"

This reverts commit 6d45ed6.

* Revert "PhpUnit fix"

This reverts commit f4935f1.

* Updated test

* Updated docblocks

* Revert "Fix linefeed (?)"

This reverts commit dee0422.

* Added tests

* Added tests

* Added tests [skip ci]

* Reverted changes to Mage_Core_Model_Website

* Updated config

* Updated .gitignore

* Updated workflow

* Updated workflow typo

* Updated workflow continue on error

* Updated workflow if condition

* Updated workflow [skip ci]

* Moved tests to root (as common)

* Fixed paths

* Fixed paths

* Fixed paths

* CS fix

* Added test

* Added test

* Added groups/suites

* Updated test

* CS fix

* Updated .gitignore

* Updated phpunit.xml.dist

* Added test

* Added tests

* Added tests

* Added tests

* Added tests

* CS fix

* CS fix

* Added tests

* Added tests

* Added tests

* Added tests

* CS/PhpStan fixes

* Update

- some tests commented - need files changes

* Nicer output?

* Don't wait for phpcs

* Revert output

* Updated workflows

* Added test

* Added phpunit command to composer.json

* Updated DDEV commands

* Fixed phpunit commands at composer.json

* WIP

* phpcs and phpstan fixes

* Updated tests

* Moved test to correct directory

* Added tests

---------

Co-authored-by: Ng Kiat Siong <[email protected]>
  • Loading branch information
sreichel and kiatng committed Sep 18, 2024
1 parent 93856f0 commit 0b68f1b
Show file tree
Hide file tree
Showing 44 changed files with 1,150 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ public function getDeleteButtonHtml()
*/
public function initForm()
{
/** @var Mage_Customer_Model_Customer $customer */
$customer = Mage::registry('current_customer');

$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('address_fieldset', [
'legend' => Mage::helper('customer')->__("Edit Customer's Address")]);

$customer = $this->getRegistryCurrentCustomer();
$addressModel = Mage::getModel('customer/address');
$addressModel->setCountryId(Mage::helper('core')->getDefaultCountry($customer->getStore()));
/** @var Mage_Customer_Model_Form $addressForm */
Expand Down Expand Up @@ -296,4 +294,9 @@ public function addValuesToNameSuffixElement($values)
}
return $this;
}

protected function getRegistryCurrentCustomer(): ?Mage_Customer_Model_Customer
{
return Mage::registry('current_customer');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function initForm()
{
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('_newsletter');
$customer = Mage::registry('current_customer');
$customer = $this->getRegistryCurrentCustomer();
$subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
Mage::register('subscriber', $subscriber);

Expand Down Expand Up @@ -95,4 +95,9 @@ protected function _prepareLayout()
);
return parent::_prepareLayout();
}

protected function getRegistryCurrentCustomer(): ?Mage_Customer_Model_Customer
{
return Mage::registry('current_customer');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function initForm()
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('_view');

$model = Mage::registry('current_convert_profile');
$model = $this->getRegistryCurrentConvertProfile();

$fieldset = $form->addFieldset('base_fieldset', [
'legend' => Mage::helper('adminhtml')->__('View Actions XML'),
Expand All @@ -50,4 +50,9 @@ public function initForm()

return $this;
}

protected function getRegistryCurrentConvertProfile(): ?Mage_Dataflow_Model_Profile
{
return Mage::registry('current_convert_profile');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function initForm()
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('_edit');

$model = Mage::registry('current_convert_profile');
$model = $this->getRegistryCurrentConvertProfile();

$fieldset = $form->addFieldset('base_fieldset', [
'legend' => Mage::helper('adminhtml')->__('General Information'),
Expand Down Expand Up @@ -57,4 +57,9 @@ public function initForm()

return $this;
}

protected function getRegistryCurrentConvertProfile(): ?Mage_Dataflow_Model_Profile
{
return Mage::registry('current_convert_profile');
}
}
1 change: 1 addition & 0 deletions app/code/core/Mage/Cms/Controller/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function match(Zend_Controller_Request_Http $request)
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
// phpcs:ignore: Ecg.Security.LanguageConstruct.ExitUsage
exit;
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Cms/Helper/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pag
{
$page = Mage::getSingleton('cms/page');
if (!is_null($pageId) && $pageId !== $page->getId()) {
$delimeterPosition = strrpos($pageId, '|');
if ($delimeterPosition) {
$pageId = substr($pageId, 0, $delimeterPosition);
$delimiterPosition = strrpos($pageId, '|');
if ($delimiterPosition) {
$pageId = substr($pageId, 0, $delimiterPosition);
}

$page->setStoreId(Mage::app()->getStore()->getId());
Expand Down
7 changes: 7 additions & 0 deletions app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function getStorageRoot()
if (!$this->_storageRoot) {
$path = Mage::getConfig()->getOptions()->getMediaDir()
. DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY;
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
$this->_storageRoot = realpath($path);
if (!$this->_storageRoot) {
$this->_storageRoot = $path;
Expand Down Expand Up @@ -107,6 +108,7 @@ public function getTreeNodeName()
*/
public function convertPathToId($path)
{
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
$storageRoot = realpath($this->getStorageRoot());
$path = str_replace($storageRoot, '', $path);
return $this->idEncode($path);
Expand All @@ -121,6 +123,7 @@ public function convertPathToId($path)
public function convertIdToPath($id)
{
$path = $this->idDecode($id);
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
$storageRoot = realpath($this->getStorageRoot());
if (!strstr($path, $storageRoot)) {
$path = $storageRoot . DS . $path;
Expand Down Expand Up @@ -209,7 +212,9 @@ public function getCurrentPath()
$currentPath = $this->getStorageRoot();
$node = $this->_getRequest()->getParam($this->getTreeNodeName());
if ($node) {
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
$path = realpath($this->convertIdToPath($node));
// phpcs:ignore: Ecg.Security.DiscouragedFunction.Discouraged
if ($path && is_dir($path) && stripos($path, $currentPath) !== false) {
$currentPath = $path;
}
Expand All @@ -235,6 +240,7 @@ public function getCurrentPath()
public function getCurrentUrl()
{
if (!$this->_currentUrl) {
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
$mediaPath = realpath(Mage::getConfig()->getOptions()->getMediaDir());
$path = str_replace($mediaPath, '', $this->getCurrentPath());
$path = trim($path, DS);
Expand Down Expand Up @@ -274,6 +280,7 @@ public function idEncode($string)
public function idDecode($string)
{
$string = strtr($string, ':_-', '+/=');
// phpcs:ignore: Ecg.Security.ForbiddenFunction.Found
return base64_decode($string);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Cms/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function _construct()
protected function _beforeSave()
{
$needle = 'block_id="' . $this->getBlockId() . '"';
if (strstr($this->getContent(), $needle) == false) {
if (!strstr($this->getContent(), $needle)) {
return parent::_beforeSave();
}
Mage::throwException(
Expand Down
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cms/Model/Mysql4/Block.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand All @@ -13,13 +14,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

/**
* CMS block model
*
* @category Mage
* @package Mage_Cms
* @deprecated
* @see Mage_Cms_Model_Resource_Block
*/
// phpcs:ignore: Ecg.Classes.Mysql4.Found
class Mage_Cms_Model_Mysql4_Block extends Mage_Cms_Model_Resource_Block
{
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cms/Model/Mysql4/Block/Collection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand All @@ -13,13 +14,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

/**
* CMS block model
*
* @category Mage
* @package Mage_Cms
* @deprecated
* @see Mage_Cms_Model_Resource_Block_Collection
*/
// phpcs:ignore: Ecg.Classes.Mysql4.Found
class Mage_Cms_Model_Mysql4_Block_Collection extends Mage_Cms_Model_Resource_Block_Collection
{
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cms/Model/Mysql4/Page.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand All @@ -13,13 +14,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

/**
* Cms page mysql resource
*
* @category Mage
* @package Mage_Cms
* @deprecated
* @see Mage_Cms_Model_Resource_Page
*/
// phpcs:ignore: Ecg.Classes.Mysql4.Found
class Mage_Cms_Model_Mysql4_Page extends Mage_Cms_Model_Resource_Page
{
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cms/Model/Mysql4/Page/Collection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand All @@ -13,13 +14,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

/**
* CMS page collection
*
* @category Mage
* @package Mage_Cms
* @deprecated
* @see Mage_Cms_Model_Resource_Page_Collection
*/
// phpcs:ignore: Ecg.Classes.Mysql4.Found
class Mage_Cms_Model_Mysql4_Page_Collection extends Mage_Cms_Model_Resource_Page_Collection
{
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cms/Model/Mysql4/Page/Service.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand All @@ -13,13 +14,17 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

/**
* Cms page service resource model
*
* @category Mage
* @package Mage_Cms
* @deprecated
* @see Mage_Cms_Model_Resource_Page_Service
*/
// phpcs:ignore: Ecg.Classes.Mysql4.Found
class Mage_Cms_Model_Mysql4_Page_Service extends Mage_Cms_Model_Resource_Page_Service
{
}
37 changes: 35 additions & 2 deletions app/code/core/Mage/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class Mage_Cms_Model_Page extends Mage_Core_Model_Abstract
/**
* Page's Statuses
*/
public const STATUS_ENABLED = 1;
public const STATUS_ENABLED = 1;
public const STATUS_DISABLED = 0;

public const CACHE_TAG = 'cms_page';
public const CACHE_TAG = 'cms_page';
protected $_cacheTag = 'cms_page';

/**
Expand Down Expand Up @@ -124,6 +124,39 @@ public function checkIdentifier($identifier, $storeId)
return $this->_getResource()->checkIdentifier($identifier, $storeId);
}

/**
* Retrieves cms page title from DB by passed identifier.
*
* @param string $identifier
* @return string
*/
public function getCmsPageTitleByIdentifier(string $identifier): string
{
return $this->_getResource()->getCmsPageTitleByIdentifier($identifier);
}

/**
* Retrieves cms page title from DB by passed id.
*
* @param string|int $id
* @return string
*/
public function getCmsPageTitleById($id): string
{
return $this->_getResource()->getCmsPageTitleById($id);
}

/**
* Retrieves cms page identifier from DB by passed id.
*
* @param string|int $id
* @return string
*/
public function getCmsPageIdentifierById($id): string
{
return $this->_getResource()->getCmsPageIdentifierById($id);
}

/**
* Prepare page's statuses.
* Available event cms_page_get_available_statuses to customize statuses.
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Cms/Model/Resource/Block/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ protected function _renderFiltersBefore()
['store_table' => $this->getTable('cms/block_store')],
'main_table.block_id = store_table.block_id',
[]
// phpcs:ignore: Ecg.Sql.SlowQuery.SlowSql
)->group('main_table.block_id');

/*
* Allow analytic functions usage because of one field grouping
*/
$this->_useAnalyticFunction = true;
}
return parent::_renderFiltersBefore();
parent::_renderFiltersBefore();
}
}
4 changes: 2 additions & 2 deletions app/code/core/Mage/Cms/Model/Resource/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function checkIdentifier($identifier, $storeId)
/**
* Retrieves cms page title from DB by passed identifier.
*
* @param string $identifier
* @param string|int $identifier
* @return string
*/
public function getCmsPageTitleByIdentifier($identifier)
Expand All @@ -304,7 +304,7 @@ public function getCmsPageTitleByIdentifier($identifier)
/**
* Retrieves cms page title from DB by passed id.
*
* @param string $id
* @param string|int $id
* @return string
*/
public function getCmsPageTitleById($id)
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Cms/Model/Resource/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ protected function _renderFiltersBefore()
['store_table' => $this->getTable('cms/page_store')],
'main_table.page_id = store_table.page_id',
[]
// phpcs:ignore: Ecg.Sql.SlowQuery.SlowSql
)->group('main_table.page_id');

/*
* Allow analytic functions usage because of one field grouping
*/
$this->_useAnalyticFunction = true;
}
return parent::_renderFiltersBefore();
parent::_renderFiltersBefore();
}

/**
Expand Down
Loading

0 comments on commit 0b68f1b

Please sign in to comment.