Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support single address fields in WrapperField.
- Loading branch information
Showing
2 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Drupal\campaignion\CRM\Export; | ||
|
||
use Drupal\campaignion\CRM\ExporterBase; | ||
|
||
/** | ||
* Test the WrapperField exporter. | ||
*/ | ||
class WrapperFieldTest extends \DrupalUnitTestCase { | ||
|
||
/** | ||
* Prepare a contact and exporter object for testing. | ||
* | ||
* We use the contact type provided by the campaignion_test module here. | ||
*/ | ||
public function setUp() { | ||
$this->contact = entity_create('redhen_contact', ['type' => 'contact']); | ||
$w = $this->contact->wrap(); | ||
$w->field_address->set([[ | ||
'country' => 'GB', | ||
]]); | ||
$w->field_gender->set('o'); | ||
$this->exporter = new ExporterBase([]); | ||
$this->exporter->setContact($this->contact); | ||
} | ||
|
||
/** | ||
* Test getting values from a multi-value field. | ||
*/ | ||
public function testMultiValueField() { | ||
$w = new WrapperField('field_address'); | ||
$w->setExporter($this->exporter); | ||
$this->assertEqual(['country' => 'GB'], $w->value()); | ||
$this->assertEqual(['country' => 'GB'], $w->value(0)); | ||
$this->assertEqual([['country' => 'GB']], $w->value(NULL)); | ||
$this->assertNull($w->value(1)); | ||
} | ||
|
||
/** | ||
* Test getting values from a single value field. | ||
*/ | ||
public function testSingleValueField() { | ||
$w = new WrapperField('field_gender'); | ||
$w->setExporter($this->exporter); | ||
$this->assertEqual('o', $w->value()); | ||
$this->assertEqual('o', $w->value(0)); | ||
$this->assertEqual(['o'], $w->value(NULL)); | ||
$this->assertEqual('o', $w->value(1)); | ||
} | ||
|
||
} |