Skip to content

Commit

Permalink
PhpUnit: added tests (#4321)
Browse files Browse the repository at this point in the history
* added tests

* fixes

* typo
  • Loading branch information
sreichel authored Nov 10, 2024
1 parent 68cfcd9 commit 258e6b0
Show file tree
Hide file tree
Showing 20 changed files with 734 additions and 26 deletions.
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/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
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());
}
}
108 changes: 108 additions & 0 deletions tests/unit/Mage/Catalog/Helper/DataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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 Generator;
use Mage;
use Mage_Catalog_Helper_Data;
use Mage_Catalog_Model_Template_Filter;
use PHPUnit\Framework\TestCase;

class DataTest extends TestCase
{
public Mage_Catalog_Helper_Data $subject;

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

/**
* @dataProvider provideSplitSku
* @group Mage_Catalog
* @group Mage_Catalog_Helper
*/
public function testSplitSku($expectedResult, string $sku, int $length = 30): void
{
$this->assertSame($expectedResult, $this->subject->splitSku($sku, $length));
}

public function provideSplitSku(): Generator
{
yield 'test #1' => [
[
'100',
],
'100',
];
yield 'test #2 w/ length' => [
[
'10',
'0'
],
'100',
2
];
}

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

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

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

/**
* @group Mage_Catalog
* @group Mage_Catalog_Helper
*/
public function testGetPageTemplateProcessor(): void
{
$this->assertInstanceOf(Mage_Catalog_Model_Template_Filter::class, $this->subject->getPageTemplateProcessor());
}

/**
* @group Mage_Catalog
* @group Mage_Catalog_Helper
*/
public function testGetOldFieldMap(): void
{
$this->assertSame([], $this->subject->getOldFieldMap());
}
}
64 changes: 64 additions & 0 deletions tests/unit/Mage/Catalog/Helper/MapTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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_Map;
use PHPUnit\Framework\TestCase;

class MapTest extends TestCase
{
public Mage_Catalog_Helper_Map $subject;

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

/**
* @group Mage_Catalog
* @group Mage_Catalog_Helper
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testGetCategoryUrl(): void
{
$this->assertStringEndsWith('/catalog/seo_sitemap/category/', $this->subject->getCategoryUrl());
}

/**
* @group Mage_Catalog
* @group Mage_Catalog_Helper
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testGetProductUrl(): void
{
$this->assertStringEndsWith('/catalog/seo_sitemap/product/', $this->subject->getProductUrl());
}

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

0 comments on commit 258e6b0

Please sign in to comment.