Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,22 @@ public function getWebsiteCodes()
*/
protected function _getParentCategory($rowData)
{
$categoryParts = $this->_explodeEscaped('/',$rowData[self::COL_CATEGORY]);
$categoryParts = $this->_explodeEscaped('/', $rowData[self::COL_CATEGORY]);
array_pop($categoryParts);
$parent = $this->_implodeEscaped('/',$categoryParts);
$parent = $this->_implodeEscaped('/', $categoryParts);

if ($parent)
{
if (isset($this->_categoriesWithRoots[$rowData[self::COL_ROOT]][$parent]))
{
if ($parent) {
if (isset($this->_categoriesWithRoots[$rowData[self::COL_ROOT]][$parent])) {
return $this->_categoriesWithRoots[$rowData[self::COL_ROOT]][$parent];
} elseif (isset($this->_newCategory[$rowData[self::COL_ROOT]][$parent])) {
return $this->_newCategory[$rowData[self::COL_ROOT]][$parent];
} else {
return false;
}
} else {
} elseif (isset($this->_categoriesWithRoots[$rowData[self::COL_ROOT]])) {
return reset($this->_categoriesWithRoots[$rowData[self::COL_ROOT]]);
} else {
return false;
}
}

Expand Down Expand Up @@ -876,9 +876,14 @@ public function validateRow(array $rowData, $rowNum)
$root = $rowData[self::COL_ROOT];
$category = $rowData[self::COL_CATEGORY];

//check if the root exists
if (! isset($this->_categoriesWithRoots[$root])) {
$this->addRowError(self::ERROR_INVALID_ROOT, $rowNum);
return false;
}

//check if parent category exists
if ($this->_getParentCategory($rowData) === false)
{
if ($this->_getParentCategory($rowData) === false) {

$this->addRowError(self::ERROR_PARENT_NOT_FOUND, $rowNum);
return false;
Expand All @@ -898,14 +903,6 @@ public function validateRow(array $rowData, $rowNum)
}
}

//check if the root exists
if (! isset($this->_categoriesWithRoots[$root]))
{
$this->addRowError(self::ERROR_INVALID_ROOT, $rowNum);
return false;
}


// check simple attributes
foreach ($this->_attributes as $attrCode => $attrParams) {
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

class AvS_FastSimpleImport_Test_Model_Category_Import extends EcomDev_PHPUnit_Test_Case
{
/**
* @var AvS_FastSimpleImport_Model_Import_Entity_Category
*/
protected $_model;

public function setUp()
{
$this->_model = $this->getModelMock(
'fastsimpleimport/import_entity_category',
null,
false,
array(),
null,
false
);

parent::setUp();
}

/**
* @test
* @covers AvS_FastSimpleImport_Model_Import_Entity_Category::validateRow
* @uses AvS_FastSimpleImport_Model_Import_Entity_Category::_explodeEscaped
* @uses AvS_FastSimpleImport_Model_Import_Entity_Category::getRowScope
* @uses AvS_FastSimpleImport_Model_Import_Entity_Category::_getCategoryName
* @uses AvS_FastSimpleImport_Model_Import_Entity_Category::_filterRowData
*/
public function validateRowWrongRoot()
{
$row = array(
// Add a Salt to make sure it does not match any possible leftover from a failed fixture
'_root' => 'Not Default ' . substr(uniqid(), -6),
'_category' => 'Some category',
);

// Setup my own error message to prevent test for failing if it is changed later
$this->_model->addMessageTemplate(
AvS_FastSimpleImport_Model_Import_Entity_Category::ERROR_INVALID_ROOT,
'Invalid Root'
);

// Assert Validation failed
$result = $this->_model->validateRow($row, 1);
$this->assertFalse($result);

// Assert error message is correct
$errors = $this->_model->getErrorMessages();
$this->assertArrayHasKey('Invalid Root', $errors);
}
}