Skip to content

Commit 1de9167

Browse files
committed
updated tests
1 parent 616d488 commit 1de9167

File tree

116 files changed

+1084
-951
lines changed

Some content is hidden

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

116 files changed

+1084
-951
lines changed

.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.

app/code/core/Mage/Core/Model/Email/Queue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* @method string getMessageBody()
3636
* @method $this setMessageBody(string $value)
3737
* @method $this setMessageBodyHash(string $value)
38-
* @method string getMessageParameters()
39-
* @method $this setMessageParameters(string $value)
38+
* @method array getMessageParameters()
39+
* @method $this setMessageParameters(array $value)
4040
* @method $this setProcessedAt(string $value)
4141
*/
4242
class Mage_Core_Model_Email_Queue extends Mage_Core_Model_Abstract

tests/unit/Base/ClassLoadingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ClassLoadingTest extends TestCase
2828
*/
2929
public function testClassExists(bool $expectedResult, string $class): void
3030
{
31-
$this->assertSame($expectedResult, class_exists($class));
31+
static::assertSame($expectedResult, class_exists($class));
3232
}
3333

3434
public function provideClassExistsData(): Generator

tests/unit/Base/DefaultConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DefaultConfigTest extends TestCase
3131
*/
3232
public function testGetStoreConfig(string $expectedResult, string $path, $store = null): void
3333
{
34-
$this->assertSame($expectedResult, Mage::getStoreConfig($path, $store));
34+
static::assertSame($expectedResult, Mage::getStoreConfig($path, $store));
3535
}
3636

3737

tests/unit/Base/XmlFileLoadingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testFileLoading(string $filepath): void
3636
SimpleXMLElement::class,
3737
LIBXML_PEDANTIC, //not needed by OpenMage, but good to test more strictly
3838
);
39-
$this->assertNotEmpty($simplexml->asXML());
39+
static::assertNotEmpty($simplexml->asXML());
4040
}
4141

4242
/**
@@ -48,7 +48,7 @@ public function testXmlReaderIsValid(string $filepath): void
4848
/** @var XMLReader $xml */
4949
$xml = XMLReader::open($filepath);
5050
$xml->setParserProperty(XMLReader::VALIDATE, true);
51-
$this->assertTrue($xml->isValid());
51+
static::assertTrue($xml->isValid());
5252
}
5353

5454
public function provideXmlFiles(): Generator

tests/unit/Error/ProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testGetHostUrl(string $expectedResult, array $serverVars): void
4646
foreach ($serverVars as $serverVar => $value) {
4747
$_SERVER[$serverVar] = $value;
4848
}
49-
$this->assertSame($expectedResult, $this->subject->getHostUrl());
49+
static::assertSame($expectedResult, $this->subject->getHostUrl());
5050
}
5151

5252
public function provideGetHostUrl(): Generator

tests/unit/Mage/Admin/Helper/BlockTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
class BlockTest extends TestCase
2525
{
26-
public Subject $subject;
26+
private static Subject $subject;
2727

28-
public function setUp(): void
28+
public static function setUpBeforeClass(): void
2929
{
3030
Mage::app();
31-
$this->subject = Mage::helper('admin/block');
31+
self::$subject = Mage::helper('admin/block');
3232
}
3333

3434
/**
@@ -38,7 +38,7 @@ public function setUp(): void
3838
*/
3939
public function testIsTypeAllowed(): void
4040
{
41-
$this->assertFalse($this->subject->isTypeAllowed('some-type'));
41+
static::assertFalse(self::$subject->isTypeAllowed('some-type'));
4242
}
4343

4444
/**
@@ -48,6 +48,6 @@ public function testIsTypeAllowed(): void
4848
*/
4949
public function testGetDisallowedBlockNames(): void
5050
{
51-
$this->assertSame(['install/end'], $this->subject->getDisallowedBlockNames());
51+
static::assertSame(['install/end'], self::$subject->getDisallowedBlockNames());
5252
}
5353
}

tests/unit/Mage/Admin/Helper/DataTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
class DataTest extends TestCase
2525
{
26-
public Subject $subject;
26+
private static Subject $subject;
2727

28-
public function setUp(): void
28+
public static function setUpBeforeClass(): void
2929
{
3030
Mage::app();
31-
$this->subject = Mage::helper('admin/data');
31+
self::$subject = Mage::helper('admin/data');
3232
}
3333

3434
/**
@@ -38,7 +38,7 @@ public function setUp(): void
3838
*/
3939
public function testGenerateResetPasswordLinkToken(): void
4040
{
41-
$this->assertIsString($this->subject->generateResetPasswordLinkToken());
41+
static::assertIsString(self::$subject->generateResetPasswordLinkToken());
4242
}
4343

4444
/**
@@ -48,6 +48,6 @@ public function testGenerateResetPasswordLinkToken(): void
4848
*/
4949
public function testGetResetPasswordLinkExpirationPeriod(): void
5050
{
51-
$this->assertIsInt($this->subject->getResetPasswordLinkExpirationPeriod());
51+
static::assertIsInt(self::$subject->getResetPasswordLinkExpirationPeriod());
5252
}
5353
}

tests/unit/Mage/Admin/Helper/VariableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
class VariableTest extends TestCase
2525
{
26-
public Subject $subject;
26+
public static Subject $subject;
2727

28-
public function setUp(): void
28+
public static function setUpBeforeClass(): void
2929
{
3030
Mage::app();
31-
$this->subject = Mage::helper('admin/variable');
31+
self::$subject = Mage::helper('admin/variable');
3232
}
3333

3434
/**
@@ -38,6 +38,6 @@ public function setUp(): void
3838
*/
3939
public function testIsPathAllowed(): void
4040
{
41-
$this->assertIsBool($this->subject->isPathAllowed(''));
41+
static::assertIsBool(self::$subject->isPathAllowed(''));
4242
}
4343
}

tests/unit/Mage/Admin/Model/BlockTest.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717

1818
namespace OpenMage\Tests\Unit\Mage\Admin\Model;
1919

20+
use Exception;
2021
use Generator;
2122
use Mage;
2223
use Mage_Admin_Model_Block as Subject;
2324
use PHPUnit\Framework\TestCase;
2425

2526
class BlockTest extends TestCase
2627
{
27-
public Subject $subject;
28+
private static Subject $subject;
2829

29-
public function setUp(): void
30+
public static function setUpBeforeClass(): void
3031
{
3132
Mage::app();
32-
$this->subject = Mage::getModel('admin/block');
33+
self::$subject = Mage::getModel('admin/block');
3334
}
3435

3536
/**
@@ -38,7 +39,7 @@ public function setUp(): void
3839
*
3940
* @group Mage_Admin
4041
* @group Mage_Admin_Model
41-
* @group Mage_Admin_Model_Test
42+
* @throws Exception
4243
*/
4344
public function testValidate($expectedResult, array $methods): void
4445
{
@@ -51,7 +52,7 @@ public function testValidate($expectedResult, array $methods): void
5152

5253
$mock->method('getBlockName')->willReturn($methods['getBlockName']);
5354
$mock->method('getIsAllowed')->willReturn($methods['getIsAllowed']);
54-
$this->assertEquals($expectedResult, $mock->validate());
55+
static::assertEquals($expectedResult, $mock->validate());
5556
}
5657

5758
public function provideValidateAdminBlockData(): Generator
@@ -86,7 +87,7 @@ public function provideValidateAdminBlockData(): Generator
8687
[$errorIncorrectBlockName],
8788
[
8889
'getBlockName' => '~',
89-
'getIsAllowed' => '0',
90+
'getIsAllowed' => '1',
9091
],
9192
];
9293
yield 'errors: invalid blockname' => [
@@ -96,6 +97,34 @@ public function provideValidateAdminBlockData(): Generator
9697
'getIsAllowed' => '0',
9798
],
9899
];
100+
yield 'errors: null blockname' => [
101+
['Block Name is required field.'],
102+
[
103+
'getBlockName' => null,
104+
'getIsAllowed' => '1',
105+
],
106+
];
107+
yield 'errors: special chars in blockname' => [
108+
[$errorIncorrectBlockName],
109+
[
110+
'getBlockName' => '!@#$%^&*()',
111+
'getIsAllowed' => '1',
112+
],
113+
];
114+
yield 'errors: numeric blockname' => [
115+
[$errorIncorrectBlockName],
116+
[
117+
'getBlockName' => '12345',
118+
'getIsAllowed' => '1',
119+
],
120+
];
121+
yield 'valid: mixed case blockname' => [
122+
true,
123+
[
124+
'getBlockName' => 'Test/Block',
125+
'getIsAllowed' => '1',
126+
],
127+
];
99128
}
100129

101130
/**
@@ -104,6 +133,6 @@ public function provideValidateAdminBlockData(): Generator
104133
*/
105134
public function testIsTypeAllowed(): void
106135
{
107-
$this->assertIsBool($this->subject->isTypeAllowed('invalid-type'));
136+
static::assertIsBool(self::$subject->isTypeAllowed('invalid-type'));
108137
}
109138
}

0 commit comments

Comments
 (0)