diff --git a/core/collector.class.inc.php b/core/collector.class.inc.php index 3b4d624..8d4acab 100644 --- a/core/collector.class.inc.php +++ b/core/collector.class.inc.php @@ -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]; diff --git a/test/CollectorTest.php b/test/CollectorTest.php index 67004b5..49a72c2 100644 --- a/test/CollectorTest.php +++ b/test/CollectorTest.php @@ -109,15 +109,19 @@ public function testAttributeIsNullified($sCollectorXmlSubSection, $bExpectedIsN $this->assertEquals($bExpectedIsNullified, $oCollector->AttributeIsNullified('phone')); - $oCollector->Collect(1); + $oCollector->Collect(); $sExpectedCsv = <<;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; @@ -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 [ @@ -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); } } diff --git a/test/collector/attribute_isnullified/iTopPersonCollector.class.inc.php b/test/collector/attribute_isnullified/iTopPersonCollector.class.inc.php index eb87c65..481ed39 100644 --- a/test/collector/attribute_isnullified/iTopPersonCollector.class.inc.php +++ b/test/collector/attribute_isnullified/iTopPersonCollector.class.inc.php @@ -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() diff --git a/test/single_json/nullified_json_1/expected_generated.csv b/test/single_json/nullified_json_1/expected_generated.csv index 3bab6b3..468643d 100644 --- a/test/single_json/nullified_json_1/expected_generated.csv +++ b/test/single_json/nullified_json_1/expected_generated.csv @@ -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; -2;Picasso;active;Pablo;pablo@demo.com;;3; -3;Dali;active;Salvador;dali@demo.com;;3; +2;Picasso;active;Pablo;pablo@demo.com;;3; +3;Dali;active;Salvador;dali@demo.com;;3;