Skip to content

Commit

Permalink
Merge branch 'main' into phpunit-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Nov 11, 2024
2 parents 6c159e8 + 258e6b0 commit 46f3234
Show file tree
Hide file tree
Showing 26 changed files with 848 additions and 37 deletions.
1 change: 0 additions & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ jobs:

- name: PHPCodeSniffer
run: php vendor/bin/phpcs -s --report=full --standard=${{ matrix.rules.path }}
continue-on-error: ${{ matrix.rules.path == '.phpcs.ecg.xml.dist' }}
1 change: 1 addition & 0 deletions .phpcs.ecg.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<exclude-pattern>*/core/Mage/Adminhtml/Model/System/Config/Backend/Category.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Api/Model/Acl/Role/Registry.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Api/Model/Resource/User.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Api2/Model/Observer.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Api2/controllers/Adminhtml/Api2/AttributeController.php*</exclude-pattern>
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Helper/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ public function getCategoryUrlPath($urlPath, $slash = false, $storeId = null)
*/
public function canUseCanonicalTag($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_USE_CATEGORY_CANONICAL_TAG, $store);
return Mage::getStoreConfigFlag(self::XML_PATH_USE_CATEGORY_CANONICAL_TAG, $store);
}
}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function getProductUrlSuffix($storeId = null)
*/
public function canUseCanonicalTag($store = null)
{
return Mage::getStoreConfig(self::XML_PATH_USE_PRODUCT_CANONICAL_TAG, $store);
return Mage::getStoreConfigFlag(self::XML_PATH_USE_PRODUCT_CANONICAL_TAG, $store);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/CatalogRule/Model/Resource/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website

$customerGroupIds = $rule->getCustomerGroupIds();

$fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime($rule->getFromDate()));
$toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime($rule->getToDate()));
$fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getFromDate()));
$toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getToDate()));
$toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0;

$timestamp = time();
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ public function setChild($alias, $block)

$block->setParentBlock($this);
$block->setBlockAlias($alias);
$this->unsetChild($alias);
$this->_children[$alias] = $block;
return $this;
}
Expand All @@ -482,7 +483,7 @@ public function unsetChild($alias)
unset($this->_children[$alias]);
$key = array_search($name, $this->_sortedChildren);
if ($key !== false) {
unset($this->_sortedChildren[$key]);
array_splice($this->_sortedChildren, $key, 1);
}
}

Expand Down Expand Up @@ -741,7 +742,6 @@ public function insert($block, $siblingName = '', $after = false, $alias = '')
*/
public function sortChildren($force = false)
{
$this->_sortedChildren = array_values($this->_sortedChildren); // reset indexes which might have gaps after unsetting blocks
foreach ($this->_sortInstructions as $name => $list) {
list($siblingName, $after, $exists) = $list;
if ($exists && !$force) {
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public function getStore($id = null)
return $id;
}
if (!isset($id)) {
$this->throwStoreException();
$this->throwStoreException('Invalid store id requested.');
}

if (empty($this->_stores[$id])) {
Expand All @@ -887,7 +887,7 @@ public function getStore($id = null)
}

if (!$store->getCode()) {
$this->throwStoreException();
$this->throwStoreException('Invalid store code requested.');
}
$this->_stores[$store->getStoreId()] = $store;
$this->_stores[$store->getCode()] = $store;
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions tests/unit/Base/DefaultConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Base;

use Generator;
use Mage;
use Mage_Adminhtml_Block_Dashboard;
use PHPUnit\Framework\TestCase;

class DefaultConfigTest extends TestCase
{
/**
* @dataProvider provideGetStoreConfig
* @group Base
* @group Default_Config
*/
public function testGetStoreConfig(string $expectedResult, string $path, $store = null): void
{
$this->assertSame($expectedResult, Mage::getStoreConfig($path, $store));
}


public function provideGetStoreConfig(): Generator
{
yield Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS => [
'1',
Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS
];
}
}
6 changes: 4 additions & 2 deletions tests/unit/Mage/Admin/Helper/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ public function setUp(): void
}

/**
* @covers Mage_Admin_Helper_Block::isTypeAllowed()
* @group Mage_Admin
* @group Mage_Admin_Helper
*/
public function testIsTypeAllowed(): void
{
$this->assertIsBool($this->subject->isTypeAllowed('some-type'));
$this->assertFalse($this->subject->isTypeAllowed('some-type'));
}

/**
* @covers Mage_Admin_Helper_Block::getDisallowedBlockNames()
* @group Mage_Admin
* @group Mage_Admin_Helper
*/
public function testGetDisallowedBlockNames(): void
{
$this->assertIsArray($this->subject->getDisallowedBlockNames());
$this->assertSame(['install/end'], $this->subject->getDisallowedBlockNames());
}
}
2 changes: 2 additions & 0 deletions tests/unit/Mage/Admin/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function setUp(): void
}

/**
* @covers Mage_Admin_Helper_Data::generateResetPasswordLinkToken()
* @group Mage_Admin
* @group Mage_Admin_Helper
*/
Expand All @@ -41,6 +42,7 @@ public function testGenerateResetPasswordLinkToken(): void
}

/**
* @covers Mage_Admin_Helper_Data::getResetPasswordLinkExpirationPeriod()
* @group Mage_Admin
* @group Mage_Admin_Helper
*/
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/Mage/Adminhtml/Block/CacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block;

use Mage;
use Mage_Adminhtml_Block_Cache;
use PHPUnit\Framework\TestCase;

class CacheTest extends TestCase
{
public Mage_Adminhtml_Block_Cache $subject;

public function setUp(): void
{
Mage::app();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->subject = new Mage_Adminhtml_Block_Cache();
}

/**
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testGetFlushStorageUrl(): void
{
$this->assertStringStartsWith('http', $this->subject->getFlushStorageUrl());
}

/**
* @group Mage_Adminhtml
* @group Mage_Adminhtml_Block
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testGetFlushSystemUrl(): void
{
$this->assertStringStartsWith('http', $this->subject->getFlushSystemUrl());
}
}
42 changes: 42 additions & 0 deletions tests/unit/Mage/Catalog/Helper/CategoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Catalog\Helper;

use Mage;
use Mage_Catalog_Helper_Category;
use PHPUnit\Framework\TestCase;

class CategoryTest extends TestCase
{
public Mage_Catalog_Helper_Category $subject;

public function setUp(): void
{
Mage::app();
$this->subject = Mage::helper('catalog/category');
}

/**
* @group Mage_Catalog
* @group Mage_Catalog_Helper
*/
public function testCanUseCanonicalTag(): void
{
$this->assertIsBool($this->subject->canUseCanonicalTag());
}
}
Loading

0 comments on commit 46f3234

Please sign in to comment.