Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion core/collector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ protected function AddRow($aRow)
{
$aData = array();
foreach ($this->aCSVHeaders as $sHeader) {
if (is_null($aRow[$sHeader]) && $this->AttributeIsNullified($sHeader)) {
if (strlen($aRow[$sHeader])==0 && $this->AttributeIsNullified($sHeader)) {
$aData[] = NULL_VALUE;
} else {
$aData[] = $aRow[$sHeader];
Expand Down
18 changes: 11 additions & 7 deletions test/CollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,19 @@ public function testAttributeIsNullified($sCollectorXmlSubSection, $bExpectedIsN

$this->assertEquals($bExpectedIsNullified, $oCollector->AttributeIsNullified('phone'));

$oCollector->Collect(1);
$oCollector->Collect();
$sExpectedCsv = <<<CSV
primary_key;first_name;name;org_id;phone;mobile_phone;employee_number;email;function
1;isaac;asimov;Demo;;123456;9998877665544;issac.asimov@function.io;writer
1;isaac;asimov_null;Demo;;123456;9998877665544;issac.asimov@function.io;writer
2;isaac;asimov_empty;Demo;;123456;9998877665544;issac.asimov@function.io;writer
3;isaac;asimov_notempty;Demo;"not empty";123456;9998877665544;issac.asimov@function.io;writer

CSV;
$sExpectedNullifiedCsv = <<<CSV
primary_key;first_name;name;org_id;phone;mobile_phone;employee_number;email;function
1;isaac;asimov;Demo;<NULL>;123456;9998877665544;issac.asimov@function.io;writer
1;isaac;asimov_null;Demo;<NULL>;123456;9998877665544;issac.asimov@function.io;writer
2;isaac;asimov_empty;Demo;<NULL>;123456;9998877665544;issac.asimov@function.io;writer
3;isaac;asimov_notempty;Demo;"not empty";123456;9998877665544;issac.asimov@function.io;writer

CSV;

Expand Down Expand Up @@ -158,12 +162,12 @@ public function testUpdateSDSAttributes($aExpectedAttrDef, $aSynchroAttrDef, boo
$oCollector = new iTopPersonCollector();
$oMockClient = $this->CreateMock('RestClient');
$oMockClient->expects($this->exactly($bWillUpdate ? 1 : 0))->method("Update")->willReturn(['code' => 0]);

$bRet = $this->InvokeNonPublicMethod(get_class($oCollector), 'UpdateSDSAttributes', $oCollector, [$aExpectedAttrDef, $aSynchroAttrDef, '', $oMockClient]);

$this->assertTrue($bRet);
}

public function providerUpdateSDSAttributes()
{
return [
Expand Down Expand Up @@ -271,7 +275,7 @@ public function InvokeNonPublicMethod($sObjectClass, $sMethodName, $oObject, $aA
$class = new \ReflectionClass($sObjectClass);
$method = $class->getMethod($sMethodName);
$method->setAccessible(true);

return $method->invokeArgs($oObject, $aArgs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,62 @@

class iTopPersonCollector extends Collector
{
private $bFetched;
private $i;
private $aCurrentData;

protected function Fetch()
{
if (! $this->bFetched) {
$this->bFetched = true;
return [
'primary_key' => 1,
'first_name' => "isaac",
'name' => "asimov",
'org_id' => "Demo",
'phone' => null,
'mobile_phone' => "123456",
'employee_number' => "9998877665544",
'email' => "issac.asimov@function.io",
'function' => "writer",
'Status' => "Active",
if (is_null($this->aCurrentData)){
$this->i = 0;
$this->aCurrentData = [
[
'primary_key' => 1,
'first_name' => "isaac",
'name' => "asimov_null",
'org_id' => "Demo",
'phone' => null,
'mobile_phone' => "123456",
'employee_number' => "9998877665544",
'email' => "issac.asimov@function.io",
'function' => "writer",
'Status' => "Active",
],
[
'primary_key' => 2,
'first_name' => "isaac",
'name' => "asimov_empty",
'org_id' => "Demo",
'phone' => "",
'mobile_phone' => "123456",
'employee_number' => "9998877665544",
'email' => "issac.asimov@function.io",
'function' => "writer",
'Status' => "Active",
],
[
'primary_key' => 3,
'first_name' => "isaac",
'name' => "asimov_notempty",
'org_id' => "Demo",
'phone' => "not empty",
'mobile_phone' => "123456",
'employee_number' => "9998877665544",
'email' => "issac.asimov@function.io",
'function' => "writer",
'Status' => "Active",
],
];
}

return null;
$res = null;
if ($this->i < count($this->aCurrentData)){
$res=$this->aCurrentData[$this->i];
$this->i++;
}

return $res;
}

/**
* {@inheritDoc}
* @see Collector::AttributeIsOptional()
Expand Down
4 changes: 2 additions & 2 deletions test/single_json/nullified_json_1/expected_generated.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
primary_key;name;status;first_name;email;phone;org_id;function
1;"My last name";active;"My first name";my.email@foo.org;"+00 000 000 000";1;<NULL>
2;Picasso;active;Pablo;pablo@demo.com;;3;
3;Dali;active;Salvador;dali@demo.com;;3;
2;Picasso;active;Pablo;pablo@demo.com;;3;<NULL>
3;Dali;active;Salvador;dali@demo.com;;3;<NULL>