diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php index 05622a6c228..3a9b5bdc578 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php @@ -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 */ @@ -296,4 +294,9 @@ public function addValuesToNameSuffixElement($values) } return $this; } + + protected function getRegistryCurrentCustomer(): ?Mage_Customer_Model_Customer + { + return Mage::registry('current_customer'); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php index 75bf8385835..94c815fdf58 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php @@ -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); @@ -95,4 +95,9 @@ protected function _prepareLayout() ); return parent::_prepareLayout(); } + + protected function getRegistryCurrentCustomer(): ?Mage_Customer_Model_Customer + { + return Mage::registry('current_customer'); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php index a8ff8fe1648..0fc992d2738 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php @@ -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'), @@ -50,4 +50,9 @@ public function initForm() return $this; } + + protected function getRegistryCurrentConvertProfile(): ?Mage_Dataflow_Model_Profile + { + return Mage::registry('current_convert_profile'); + } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php index de42e352cfe..e8b952b1e1d 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php @@ -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'), @@ -57,4 +57,9 @@ public function initForm() return $this; } + + protected function getRegistryCurrentConvertProfile(): ?Mage_Dataflow_Model_Profile + { + return Mage::registry('current_convert_profile'); + } } diff --git a/app/code/core/Mage/Cms/Controller/Router.php b/app/code/core/Mage/Cms/Controller/Router.php index f8cf0f5477d..368afa71e33 100644 --- a/app/code/core/Mage/Cms/Controller/Router.php +++ b/app/code/core/Mage/Cms/Controller/Router.php @@ -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; } diff --git a/app/code/core/Mage/Cms/Helper/Page.php b/app/code/core/Mage/Cms/Helper/Page.php index 977af4d4f66..1513a755051 100644 --- a/app/code/core/Mage/Cms/Helper/Page.php +++ b/app/code/core/Mage/Cms/Helper/Page.php @@ -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()); diff --git a/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php b/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php index 21d80cf1a56..08e514a593c 100644 --- a/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php @@ -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; @@ -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); @@ -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; @@ -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; } @@ -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); @@ -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); } diff --git a/app/code/core/Mage/Cms/Model/Block.php b/app/code/core/Mage/Cms/Model/Block.php index 7ef415ff414..0b9c8275dc7 100644 --- a/app/code/core/Mage/Cms/Model/Block.php +++ b/app/code/core/Mage/Cms/Model/Block.php @@ -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( diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Block.php b/app/code/core/Mage/Cms/Model/Mysql4/Block.php index 0ae678f8cad..e4fcf4094e6 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Block.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Block.php @@ -1,4 +1,5 @@ _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. diff --git a/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php b/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php index 2cab27d2fff..2e0852a8385 100644 --- a/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php +++ b/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php @@ -92,6 +92,7 @@ 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'); /* @@ -99,6 +100,6 @@ protected function _renderFiltersBefore() */ $this->_useAnalyticFunction = true; } - return parent::_renderFiltersBefore(); + parent::_renderFiltersBefore(); } } diff --git a/app/code/core/Mage/Cms/Model/Resource/Page.php b/app/code/core/Mage/Cms/Model/Resource/Page.php index 94dea6c40af..8b9733a7f6f 100644 --- a/app/code/core/Mage/Cms/Model/Resource/Page.php +++ b/app/code/core/Mage/Cms/Model/Resource/Page.php @@ -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) @@ -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) diff --git a/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php b/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php index d8a85cd11f1..aa54f1ef80a 100644 --- a/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php +++ b/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php @@ -162,6 +162,7 @@ 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'); /* @@ -169,7 +170,7 @@ protected function _renderFiltersBefore() */ $this->_useAnalyticFunction = true; } - return parent::_renderFiltersBefore(); + parent::_renderFiltersBefore(); } /** diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php index 5ccf659cfc5..3974734a8fd 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php @@ -51,7 +51,9 @@ public function getDirsCollection($path) $subDirectories = Mage::getModel('core/file_storage_directory_database')->getSubdirectories($path); foreach ($subDirectories as $directory) { $fullPath = rtrim($path, DS) . DS . $directory['name']; + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found if (!file_exists($fullPath)) { + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found mkdir($fullPath, 0777, true); } } @@ -136,6 +138,7 @@ public function getFilesCollection($path, $type = null) $thumbUrl = Mage::getSingleton('adminhtml/url')->getUrl('*/*/thumbnail', ['file' => $item->getId()]); } + // phpcs:ignore: Generic.PHP.NoSilencedErrors.Discouraged $size = @getimagesize($item->getFilename()); if (is_array($size)) { @@ -180,12 +183,14 @@ public function createDirectory($name, $path) if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) { Mage::throwException(Mage::helper('cms')->__('Invalid folder name. Please, use alphanumeric characters, underscores and dashes.')); } + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found, Ecg.Security.DiscouragedFunction.Discouraged if (!is_dir($path) || !is_writable($path)) { $path = $this->getHelper()->getStorageRoot(); } $newPath = $path . DS . $name; + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found if (file_exists($newPath)) { Mage::throwException(Mage::helper('cms')->__('A directory with the same name already exists. Please try another folder name.')); } @@ -226,6 +231,7 @@ public function deleteDirectory($path) $io->getFilteredPath($path) )); } + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found if (str_contains($pathCmp, chr(0)) || preg_match('#(^|[\\\\/])\.\.($|[\\\\/])#', $pathCmp) ) { @@ -298,6 +304,7 @@ public function uploadFile($targetPath, $type = null) $this->resizeFile($targetPath . DS . $uploader->getUploadedFileName(), true); } $result['cookie'] = [ + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found 'name' => session_name(), 'value' => $this->getSession()->getSessionId(), 'lifetime' => $this->getSession()->getCookieLifetime(), @@ -322,6 +329,7 @@ public function getThumbnailPath($filePath, $checkFile = false) if (str_starts_with($filePath, $mediaRootDir)) { $thumbPath = $this->getThumbnailRoot() . DS . substr($filePath, strlen($mediaRootDir)); + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found if (!$checkFile || is_readable($thumbPath)) { return $thumbPath; } @@ -342,6 +350,7 @@ public function getThumbnailUrl($filePath, $checkFile = false) $mediaRootDir = Mage::getConfig()->getOptions()->getMediaDir() . DS; if (str_starts_with($filePath, $mediaRootDir)) { $thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . substr($filePath, strlen($mediaRootDir)); + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found if (!$checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) { $randomIndex = '?rand=' . time(); $thumbUrl = $this->getHelper()->getBaseUrl() . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY @@ -361,6 +370,7 @@ public function getThumbnailUrl($filePath, $checkFile = false) */ public function resizeFile($source, $keepRation = true) { + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found, Ecg.Security.DiscouragedFunction.Discouraged if (!is_file($source) || !is_readable($source)) { return false; } @@ -386,8 +396,10 @@ public function resizeFile($source, $keepRation = true) $image->resize($width, $height); $dest = $targetDir . DS + // phpcs:ignore: Ecg.Security.DiscouragedFunction.Discouraged . Mage_Core_Model_File_Uploader::getCorrectFileName(pathinfo($source, PATHINFO_BASENAME)); $image->save($dest); + // phpcs:ignore: Ecg.Security.DiscouragedFunction.Discouraged if (is_file($dest)) { return $dest; } @@ -398,7 +410,7 @@ public function resizeFile($source, $keepRation = true) * Resize images on the fly in controller action * * @param string $filename File basename - * @return bool|string Thumbnail path or false for errors + * @return false|string Thumbnail path or false for errors */ public function resizeOnTheFly($filename) { @@ -421,6 +433,7 @@ public function getThumbsPath($filePath = false) $thumbnailDir = $this->getThumbnailRoot(); if ($filePath && str_starts_with($filePath, $mediaRootDir)) { + // phpcs:ignore: Ecg.Security.ForbiddenFunction.Found $thumbnailDir .= DS . dirname(substr($filePath, strlen($mediaRootDir))); } @@ -529,6 +542,7 @@ public function isImage($filename) if (!$this->hasData('_image_extensions')) { $this->setData('_image_extensions', $this->getAllowedExtensions('image')); } + // phpcs:ignore: Ecg.Security.DiscouragedFunction.Discouraged $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); return in_array($ext, $this->_getData('_image_extensions')); } diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index eb3a67d6c10..80e4e82f0a3 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -1700,9 +1700,6 @@ public function deleteConfig($path, $scope = 'default', $scopeId = 0) /** * Get config value from DB * - * @param string $path - * @param string $scope - * @param int $scopeId * @return string|false */ public function getConfig(string $path, string $scope = 'default', int $scopeId = 0) diff --git a/app/code/core/Mage/Core/Model/Resource/Config.php b/app/code/core/Mage/Core/Model/Resource/Config.php index 45f34b51837..c6b14f133dc 100644 --- a/app/code/core/Mage/Core/Model/Resource/Config.php +++ b/app/code/core/Mage/Core/Model/Resource/Config.php @@ -210,9 +210,6 @@ public function deleteConfig($path, $scope, $scopeId) /** * Get config value * - * @param string $path - * @param string $scope - * @param int $scopeId * @return string|false */ public function getConfig(string $path, string $scope, int $scopeId) diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index 509c70ac5ec..12b43827ee4 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -177,7 +177,7 @@ public function getUrl() } /** - * @return mixed + * @return string */ public function getFirstVisitAt() { @@ -188,7 +188,7 @@ public function getFirstVisitAt() } /** - * @return mixed + * @return string */ public function getLastVisitAt() { @@ -334,7 +334,7 @@ public function bindQuoteDestroy($observer) } /** - * Methods for research (depends from customer online admin section) + * Methods for research (depends on customer online admin section) * @param Varien_Object $data * @return $this */ diff --git a/composer.json b/composer.json index 3fc9d0344f9..b6e834d82e3 100644 --- a/composer.json +++ b/composer.json @@ -129,8 +129,19 @@ "sort-packages": true }, "scripts": { - "phpunit:test": "vendor/bin/phpunit --no-coverage \"$@\" --testdox", + "php-cs-fixer:test": "vendor/bin/php-cs-fixer fix --dry-run --diff", + "php-cs-fixer:fix": "vendor/bin/php-cs-fixer fix", + "phpstan": "vendor/bin/phpstan analyze", + "phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --no-coverage --testdox", "phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --testdox", "phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox" + }, + "scripts-descriptions": { + "php-cs-fixer:test": "Run php-cs-fixer", + "php-cs-fixer:fix": "Run php-cs-fixer and fix issues", + "phpstan": "Run phpstan", + "phpunit:test": "Run PHPUnit", + "phpunit:coverage": "Run PHPUnit with code coverage", + "phpunit:coverage-local": "Run PHPUnit with local HTML code coverage" } } diff --git a/lib/Varien/Data/Collection/Db.php b/lib/Varien/Data/Collection/Db.php index eea8f5e7a00..288a0ce87cd 100644 --- a/lib/Varien/Data/Collection/Db.php +++ b/lib/Varien/Data/Collection/Db.php @@ -398,6 +398,8 @@ protected function _renderFilters() /** * Hook for operations before rendering filters + * + * @return void */ protected function _renderFiltersBefore() { diff --git a/tests/unit/Mage/AdminNotification/Model/FeedTest.php b/tests/unit/Mage/AdminNotification/Model/FeedTest.php new file mode 100644 index 00000000000..c5ef6917895 --- /dev/null +++ b/tests/unit/Mage/AdminNotification/Model/FeedTest.php @@ -0,0 +1,54 @@ +subject = Mage::getModel('adminnotification/feed'); + } + + /** + * @group Mage_AdminNotification + * @group Mage_AdminNotification_Model + */ + public function testGetFeedUrl(): void + { + $this->assertIsString($this->subject->getFeedUrl()); + } + + /** + * @group Mage_AdminNotification + * @group Mage_AdminNotification_Model + */ + public function testCheckUpdate(): void + { + $this->assertInstanceOf(Mage_AdminNotification_Model_Feed::class, $this->subject->checkUpdate()); + } +} diff --git a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AccountTest.php b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AccountTest.php index da8f2baaf3d..285320d1597 100644 --- a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AccountTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AccountTest.php @@ -35,7 +35,6 @@ public function setUp(): void } /** - * @return void * @throws Mage_Core_Exception * * @group Mage_Adminhtml diff --git a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php index 1d36c1f2f1c..c378f22e685 100644 --- a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/AddressesTest.php @@ -34,21 +34,24 @@ public function setUp(): void } /** - * @return void - * * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block */ -// public function testInitForm(): void -// { -// $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class) -// ->setMethods(['getRegistryCurrentCustomer']) -// ->getMock(); -// -// $mock->expects($this->any()) -// ->method('getRegistryCurrentCustomer') -// // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation -// ->willReturn(new Mage_Customer_Model_Customer()); -// -// $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class, $mock->initForm()); -// } + public function testInitForm(): void + { + $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class) + ->setMethods(['getRegistryCurrentCustomer', 'isReadonly']) + ->getMock(); + + $mock->expects($this->any()) + ->method('getRegistryCurrentCustomer') + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + ->willReturn(new Mage_Customer_Model_Customer()); + + $mock->expects($this->any()) + ->method('isReadonly') + ->willReturn(true); + + $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Addresses::class, $mock->initForm()); + } } diff --git a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php index cb005ff8482..817bcf863d2 100644 --- a/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php +++ b/tests/unit/Mage/Adminhtml/Block/Customer/Edit/Tab/NewsletterTest.php @@ -37,18 +37,19 @@ public function setUp(): void * @return void * * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block */ -// public function testInitForm(): void -// { -// $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class) -// ->setMethods(['getRegistryCurrentCustomer']) -// ->getMock(); -// -// $mock->expects($this->any()) -// ->method('getRegistryCurrentCustomer') -// // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation -// ->willReturn(new Mage_Customer_Model_Customer()); -// -// $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class, $mock->initForm()); -// } + public function testInitForm(): void + { + $mock = $this->getMockBuilder(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class) + ->setMethods(['getRegistryCurrentCustomer']) + ->getMock(); + + $mock->expects($this->any()) + ->method('getRegistryCurrentCustomer') + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + ->willReturn(new Mage_Customer_Model_Customer()); + + $this->assertInstanceOf(Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter::class, $mock->initForm()); + } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php b/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php index 2a96cd2a21d..433b9c1d4fe 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/ViewTest.php @@ -19,6 +19,7 @@ use Mage; use Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View; +use Mage_Dataflow_Model_Profile; use PHPUnit\Framework\TestCase; class ViewTest extends TestCase @@ -33,12 +34,20 @@ public function setUp(): void } /** - * @return void - * * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block */ -// public function testInitForm(): void -// { -// $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View::class, $this->subject->initForm()); -// } + public function testInitForm(): void + { + $mock = $this->getMockBuilder(Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View::class) + ->setMethods(['getRegistryCurrentConvertProfile']) + ->getMock(); + + $mock->expects($this->any()) + ->method('getRegistryCurrentConvertProfile') + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + ->willReturn(new Mage_Dataflow_Model_Profile()); + + $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_View::class, $mock->initForm()); + } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php b/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php index 8a004b3c5ae..ae38cdfa4f7 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/EditTest.php @@ -19,6 +19,7 @@ use Mage; use Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit; +use Mage_Dataflow_Model_Profile; use PHPUnit\Framework\TestCase; class EditTest extends TestCase @@ -33,12 +34,20 @@ public function setUp(): void } /** - * @return void - * * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block */ -// public function testInitForm(): void -// { -// $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit::class, $this->subject->initForm()); -// } + public function testInitForm(): void + { + $mock = $this->getMockBuilder(Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit::class) + ->setMethods(['getRegistryCurrentConvertProfile']) + ->getMock(); + + $mock->expects($this->any()) + ->method('getRegistryCurrentConvertProfile') + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + ->willReturn(new Mage_Dataflow_Model_Profile()); + + $this->assertInstanceOf(Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Edit::class, $mock->initForm()); + } } diff --git a/tests/unit/Mage/Cms/Block/BlockTest.php b/tests/unit/Mage/Cms/Block/BlockTest.php new file mode 100644 index 00000000000..28b80285b7c --- /dev/null +++ b/tests/unit/Mage/Cms/Block/BlockTest.php @@ -0,0 +1,54 @@ +getMockBuilder(Mage_Cms_Block_Block::class) + ->setMethods(['getBlockId']) + ->getMock(); + + $mock->expects($this->any())->method('getBlockId')->willReturn($blockId); + $this->assertIsArray($mock->getCacheKeyInfo()); + } + + /** + * @return array[] + */ + public function provideGetCacheKeyInfoData(): array + { + return [ + 'valid block ID' => [ + '2' + ], + 'invalid block ID' => [ + '0' + ] + ]; + } +} diff --git a/tests/unit/Mage/Cms/Block/PageTest.php b/tests/unit/Mage/Cms/Block/PageTest.php new file mode 100644 index 00000000000..7e6bf982ea7 --- /dev/null +++ b/tests/unit/Mage/Cms/Block/PageTest.php @@ -0,0 +1,55 @@ +getMockBuilder(Mage_Cms_Block_Page::class) + ->setMethods(['getPageId']) + ->getMock(); + + $mock->expects($this->any())->method('getPageId')->willReturn($pageId); + $this->assertInstanceOf(Mage_Cms_Model_Page::class, $mock->getPage()); + } + + /** + * @return array[] + */ + public function provideGetPageData(): array + { + return [ + 'valid page ID' => [ + '2' + ], + 'invalid page ID' => [ + '0' + ] + ]; + } +} diff --git a/tests/unit/Mage/Cms/Block/Widget/BlockTest.php b/tests/unit/Mage/Cms/Block/Widget/BlockTest.php new file mode 100644 index 00000000000..481a048740c --- /dev/null +++ b/tests/unit/Mage/Cms/Block/Widget/BlockTest.php @@ -0,0 +1,76 @@ +subject = new Mage_Cms_Block_Widget_Block(); + } + + /** + * @dataProvider provideGetCacheKeyInfoData + * @group Mage_Cms + * @group Mage_Cms_Block + */ + public function testGetCacheKeyInfo(string $blockId): void + { + $mock = $this->getMockBuilder(Mage_Cms_Block_Widget_Block::class) + ->setMethods(['getBlockId']) + ->getMock(); + + $mock->expects($this->any())->method('getBlockId')->willReturn($blockId); + $this->assertIsArray($mock->getCacheKeyInfo()); + } + + /** + * @return array[] + */ + public function provideGetCacheKeyInfoData(): array + { + return [ + 'valid block ID' => [ + '2' + ], + 'invalid block ID' => [ + '0' + ] + ]; + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Block + */ + public function testIsRequestFromAdminArea(): void + { + $this->assertIsBool($this->subject->isRequestFromAdminArea()); + } +} diff --git a/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php new file mode 100644 index 00000000000..65205901b21 --- /dev/null +++ b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php @@ -0,0 +1,64 @@ +subject = new Mage_Cms_Block_Widget_Page_Link(); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Block + */ + public function testGetHref(): void + { + $this->assertIsString($this->subject->getHref()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Block + */ + public function testGetTitle(): void + { + $this->assertIsString($this->subject->getTitle()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Block + */ +// public function testGetAnchorText(): void +// { +// $this->assertIsString($this->subject->getAnchorText()); +// } +} diff --git a/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php b/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php new file mode 100644 index 00000000000..8139c185075 --- /dev/null +++ b/tests/unit/Mage/Cms/Helper/Wysiwyg/ImagesTest.php @@ -0,0 +1,113 @@ +subject = Mage::helper('cms/wysiwyg_images'); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testGetCurrentPath(): void + { + $this->assertIsString($this->subject->getCurrentPath()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testGetCurrentUrl(): void + { + $this->assertIsString($this->subject->getCurrentUrl()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testGetStorage(): void + { + $this->assertInstanceOf(Mage_Cms_Model_Wysiwyg_Images_Storage::class, $this->subject->getStorage()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testIdEncode(): void + { + $this->assertIsString($this->subject->idEncode(self::TEST_STRING)); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testIdDecode(): void + { + $this->assertIsString($this->subject->idDecode(self::TEST_STRING)); + } + + /** + * @dataProvider provideGetShortFilenameData + * @group Mage_Cms + * @group Mage_Cms_Helper + */ + public function testGetShortFilename(string $expectedResult, string $filename, int $maxLength): void + { + $this->assertEquals($expectedResult, $this->subject->getShortFilename($filename, $maxLength)); + } + + /** + * @return array[] + */ + public function provideGetShortFilenameData(): array + { + return [ + 'full length' => [ + '0123456789', + self::TEST_STRING, + 20, + ], + 'truncated' => [ + '01234...', + self::TEST_STRING, + 5, + ] + ]; + } +} diff --git a/tests/unit/Mage/Cms/Model/PageTest.php b/tests/unit/Mage/Cms/Model/PageTest.php new file mode 100644 index 00000000000..3b318a2f15c --- /dev/null +++ b/tests/unit/Mage/Cms/Model/PageTest.php @@ -0,0 +1,91 @@ +subject = Mage::getModel('cms/page'); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testLoad(): void + { + $this->assertInstanceOf(Mage_Cms_Model_Page::class, $this->subject->load(null)); + $this->assertInstanceOf(Mage_Cms_Model_Page::class, $this->subject->load(2)); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testCheckIdentifier(): void + { + $this->assertIsString($this->subject->checkIdentifier('home', 1)); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetCmsPageTitleByIdentifier(): void + { + $this->assertNotFalse($this->subject->getCmsPageTitleByIdentifier('home')); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetCmsPageTitleById(): void + { + $this->assertNotFalse($this->subject->getCmsPageTitleById(2)); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetCmsPageIdentifierById(): void + { + $this->assertNotFalse($this->subject->getCmsPageIdentifierById(2)); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetAvailableStatuses(): void + { + $this->assertIsArray($this->subject->getAvailableStatuses()); + } +} diff --git a/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php b/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php new file mode 100644 index 00000000000..45dc4949635 --- /dev/null +++ b/tests/unit/Mage/Cms/Model/Wysiwyg/ConfigTest.php @@ -0,0 +1,85 @@ +subject = Mage::getModel('cms/wysiwyg_config'); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + * @runInSeparateProcess + */ + public function testGetConfig(): void + { + $this->assertInstanceOf(Varien_Object::class, $this->subject->getConfig()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetSkinImagePlaceholderUrl(): void + { + $this->assertIsString($this->subject->getSkinImagePlaceholderUrl()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetSkinImagePlaceholderPath(): void + { + $this->assertIsString($this->subject->getSkinImagePlaceholderPath()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testIsEnabled(): void + { + $this->assertIsBool($this->subject->isEnabled()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testIsHidden(): void + { + $this->assertIsBool($this->subject->isHidden()); + } +} diff --git a/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php b/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php new file mode 100644 index 00000000000..d0d85f845ec --- /dev/null +++ b/tests/unit/Mage/Cms/Model/Wysiwyg/Images/StorageTest.php @@ -0,0 +1,96 @@ +subject = Mage::getModel('cms/wysiwyg_images_storage'); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetThumbsPath(): void + { + $this->assertIsString($this->subject->getThumbsPath()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + * @runInSeparateProcess + */ + public function testResizeOnTheFly(): void + { + $this->assertFalse($this->subject->resizeOnTheFly('not-existing.jpeg')); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetHelper(): void + { + $this->assertInstanceOf(Mage_Cms_Helper_Wysiwyg_Images::class, $this->subject->getHelper()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + * @runInSeparateProcess + */ + public function testGetSession(): void + { + $this->assertInstanceOf(Mage_Adminhtml_Model_Session::class, $this->subject->getSession()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testGetThumbnailRoot(): void + { + $this->assertIsString($this->subject->getThumbnailRoot()); + } + + /** + * @group Mage_Cms + * @group Mage_Cms_Model + */ + public function testIsImage(): void + { + $this->assertIsBool($this->subject->isImage('test.jpeg')); + } +} diff --git a/dev/tests/unit/Mage/Core/Model/ConfigTest.php b/tests/unit/Mage/Core/Model/ConfigTest.php similarity index 93% rename from dev/tests/unit/Mage/Core/Model/ConfigTest.php rename to tests/unit/Mage/Core/Model/ConfigTest.php index 146ca0a2d9b..7e90bd5d27a 100644 --- a/dev/tests/unit/Mage/Core/Model/ConfigTest.php +++ b/tests/unit/Mage/Core/Model/ConfigTest.php @@ -10,9 +10,6 @@ class ConfigTest extends TestCase { - /** - * @var Mage_Core_Model_Config - */ public Mage_Core_Model_Config $subject; public function setUp(): void @@ -21,6 +18,10 @@ public function setUp(): void $this->subject = Mage::getModel('core/config'); } + /** + * @group Mage_Core + * @group Mage_Core_Model + */ public function testSaveDeleteGetConfig(): void { $path = 'test/config'; diff --git a/tests/unit/Mage/Core/Model/UrlTest.php b/tests/unit/Mage/Core/Model/UrlTest.php new file mode 100644 index 00000000000..c6c644783ec --- /dev/null +++ b/tests/unit/Mage/Core/Model/UrlTest.php @@ -0,0 +1,42 @@ +subject = Mage::getModel('core/url'); + } + + /** + * @group Mage_Core + * @group Mage_Core_Model + */ + public function testGetSecure(): void + { + $this->assertIsBool($this->subject->getSecure()); + } +} diff --git a/tests/unit/Mage/Core/Model/VariableTest.php b/tests/unit/Mage/Core/Model/VariableTest.php new file mode 100644 index 00000000000..d27e4608d9e --- /dev/null +++ b/tests/unit/Mage/Core/Model/VariableTest.php @@ -0,0 +1,42 @@ +subject = Mage::getModel('core/variable'); + } + + /** + * @group Mage_Core + * @group Mage_Core_Model + */ + public function testGetVariablesOptionArray(): void + { + $this->assertIsArray($this->subject->getVariablesOptionArray()); + } +} diff --git a/tests/unit/Mage/Customer/Model/CustomerTest.php b/tests/unit/Mage/Customer/Model/CustomerTest.php new file mode 100644 index 00000000000..4accfe15f34 --- /dev/null +++ b/tests/unit/Mage/Customer/Model/CustomerTest.php @@ -0,0 +1,47 @@ +subject = Mage::getModel('customer/customer'); + } + + /** + * @group Mage_Customer + * @group Mage_Customer_Model + */ + public function testValidateAddress(): void + { + $data = []; + $this->assertIsBool($this->subject->validateAddress($data)); + } +} diff --git a/tests/unit/Mage/Log/Model/AggregationTest.php b/tests/unit/Mage/Log/Model/AggregationTest.php new file mode 100644 index 00000000000..ee6192d3cce --- /dev/null +++ b/tests/unit/Mage/Log/Model/AggregationTest.php @@ -0,0 +1,46 @@ +subject = Mage::getModel('log/aggregation'); + } + + /** + * @group Mage_Log + * @group Mage_Log_Model + * @doesNotPerformAssertions + */ + public function testRun(): void + { + $this->subject->run(); + } +} diff --git a/tests/unit/Mage/Log/Model/CustomerTest.php b/tests/unit/Mage/Log/Model/CustomerTest.php new file mode 100644 index 00000000000..8261eeb49cb --- /dev/null +++ b/tests/unit/Mage/Log/Model/CustomerTest.php @@ -0,0 +1,45 @@ +subject = Mage::getModel('log/customer'); + } + + /** + * @group Mage_Log + * @group Mage_Log_Model + */ + public function testGetLoginAtTimestamp(): void + { + $this->assertNull($this->subject->getLoginAtTimestamp()); + } +} diff --git a/tests/unit/Mage/Log/Model/VisitorTest.php b/tests/unit/Mage/Log/Model/VisitorTest.php index 0d2c1713997..605a3f31eae 100644 --- a/tests/unit/Mage/Log/Model/VisitorTest.php +++ b/tests/unit/Mage/Log/Model/VisitorTest.php @@ -40,4 +40,44 @@ public function testInitServerData(): void { $this->assertInstanceOf(Mage_Log_Model_Visitor::class, $this->subject->initServerData()); } + + /** + * @group Mage_Log + * @group Mage_Log_Model + * @runInSeparateProcess + */ + public function testGetOnlineMinutesInterval(): void + { + $this->assertIsInt($this->subject->getOnlineMinutesInterval()); + } + + /** + * @group Mage_Log + * @group Mage_Log_Model + * @runInSeparateProcess + */ + public function testGetUrl(): void + { + $this->assertIsString($this->subject->getUrl()); + } + + /** + * @group Mage_Log + * @group Mage_Log_Model + * @runInSeparateProcess + */ + public function testGetFirstVisitAt(): void + { + $this->assertIsString($this->subject->getFirstVisitAt()); + } + + /** + * @group Mage_Log + * @group Mage_Log_Model + * @runInSeparateProcess + */ + public function testGetLastVisitAt(): void + { + $this->assertIsString($this->subject->getLastVisitAt()); + } }