Skip to content

Commit

Permalink
Merge branch 'main' into sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Nov 23, 2024
2 parents 06486c2 + 11db607 commit 85f9d88
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ phpunit.xml
/site

# DDEV
.ddev/config.yaml
.ddev/.sampleData
.ddev/config.yaml
.ddev/config.*.yaml
.ddev/xhgui
.ddev/xhprof
.ddev/docker-compose.xhgui.yaml
.ddev/docker-compose.xhgui_norouter.yaml
app/etc/includes/ddev.xhgui.php
4 changes: 4 additions & 0 deletions .phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<php>
<env name="NO_XHGUI" value="1"/>
</php>

<testsuites>
<testsuite name="Base">
<directory>tests/unit/Base</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
*/
class Mage_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Default
{
public function getUserValue(): string
{
return (string) $this->getDataByKey('user_value');
}

/**
* Validate user input for option
*
* @throws Mage_Core_Exception
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return Mage_Catalog_Model_Product_Option_Type_Default
* @return $this
*/
public function validateUserValue($values)
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"macopedia/phpstan-magento1": "^1.0.5",
"magento-ecg/coding-standard": "^4.5",
"openmage/dev-meta-package": "^1.0",
"perftools/php-profiler": "^1.1",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^1.12.1",
Expand Down
66 changes: 64 additions & 2 deletions composer.lock

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

6 changes: 4 additions & 2 deletions lib/Varien/Convert/Parser/Xml/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ public function parse()
$dom->loadXML($this->getData());

$worksheets = $dom->getElementsByTagName('Worksheet');

/** @var DOMElement $worksheet */
foreach ($worksheets as $worksheet) {
$wsName = $worksheet->getAttribute('ss:Name');
$rows = $worksheet->getElementsByTagName('Row');
$firstRow = true;
$fieldNames = [];
$wsData = [];
/** @var DOMElement $row */
foreach ($rows as $row) {
$index = 1;
$cells = $row->getElementsByTagName('Cell');
$rowData = [];
/** @var DOMElement $cell */
foreach ($cells as $cell) {
$value = $cell->getElementsByTagName('Data')->item(0)->nodeValue;
$ind = $cell->getAttribute('ss:Index');
Expand Down Expand Up @@ -195,7 +197,7 @@ public function getRowXml(array $row)
$xmlData = [];
$xmlData[] = '<Row>';
foreach ($row as $value) {
$this->_xmlElement->row = htmlspecialchars($value);
$this->_xmlElement->row = htmlspecialchars((string) $value);
$value = str_replace($xmlHeader, '', $this->_xmlElement->asXML());
$value = preg_replace($xmlRegexp, '\\1', $value);
$dataType = 'String';
Expand Down
81 changes: 81 additions & 0 deletions tests/unit/Mage/Catalog/Model/Product/Option/Type/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\Model\Product\Option\Type;

use Generator;
use Mage;
use Mage_Catalog_Model_Product_Option;
use Mage_Catalog_Model_Product_Option_Type_Text as Subject;
use PHPUnit\Framework\TestCase;

class TextTest extends TestCase
{
public Subject $subject;

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

/**
* @group Mage_Catalog
* @group Mage_Catalog_Model
* @group runInSeparateProcess
* @runInSeparateProcess
*/
public function testValidateUserValue(): void
{
$this->subject->setOption(new Mage_Catalog_Model_Product_Option());
$this->assertInstanceOf(Subject::class, $this->subject->validateUserValue([]));
}


/**
* @dataProvider providePrepareForCart
* @group Mage_Catalog
* @group Mage_Catalog_Model
*/
public function testPrepareForCart($expectedResult, bool $setIsValid = true, $setUserValue = null): void
{
$this->subject->setIsValid($setIsValid)->setUserValue($setUserValue);
$this->assertSame($expectedResult, $this->subject->prepareForCart());
}

public function providePrepareForCart(): Generator
{
yield 'valid' => [
'test',
true,
'test',
];
yield 'invalid' => [
null,
];
}

/**
* @covers Mage_Catalog_Model_Product_Option_Type_Text::getFormattedOptionValue()
* @group Mage_Catalog
* @group Mage_Catalog_Model
*/
public function testGetDefaultAttributeSetId(): void
{
$this->assertIsString($this->subject->getFormattedOptionValue(''));
}
}

0 comments on commit 85f9d88

Please sign in to comment.