Skip to content

Commit

Permalink
Add test for source tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
torotil committed Dec 21, 2017
1 parent b228071 commit fbbe5b0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 38 deletions.
38 changes: 38 additions & 0 deletions campaignion_source_tags/tests/SourceTagTest.php
@@ -0,0 +1,38 @@
<?php

namespace Drupal\campaignion_source_tags;

use Drupal\campaignion\CRM\ImporterBase;
use Drupal\campaignion\CRM\Import\Field\Name;
use Drupal\campaignion\CRM\Import\Source\ArraySource;
use Drupal\campaignion_supporter_tags\Tagger;

/**
* Test for setting source tags.
*/
class SourceTagTest extends \DrupalWebTestCase {

/**
* Test setting the source tag during an import.
*/
public function testSetSourceTagDuringImport() {
$mappings = [
new Name('first_name', 'first_name'),
new Name('last_name', 'last_name'),
];
$importer = new ImporterBase($mappings);
$tagger = Tagger::byNameAndParentUuid('supporter_tags', '0fd2977e-9927-4de7-b4c2-e0bde71fc605');
$source = new ArraySource([
'first_name' => 'F',
'last_name' => 'L',
'email' => 'testsetsourcetagduringimport@example.com',
]);
$contact = $importer->findOrCreateContact($source);
$tagger->tag($contact->supporter_tags, ['test-source'], TRUE);
$importer->import($source, $contact);
$contact->save();
$this->assertNotEmpty($contact->source_tag[LANGUAGE_NONE][0]);
entity_delete('redhen_contact', $contact->contact_id);
}

}
37 changes: 0 additions & 37 deletions campaignion_test/campaignion_test.features.field_base.inc
Expand Up @@ -314,42 +314,5 @@ function campaignion_test_field_default_field_bases() {
'type' => 'redhen_email',
);

// Exported field_base: 'supporter_tags'
$field_bases['supporter_tags'] = array(
'active' => 1,
'cardinality' => -1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'supporter_tags',
'foreign keys' => array(
'tid' => array(
'columns' => array(
'tid' => 'tid',
),
'table' => 'taxonomy_term_data',
),
),
'global_block_settings' => 1,
'indexes' => array(
'tid' => array(
0 => 'tid',
),
),
'locked' => 0,
'module' => 'taxonomy',
'settings' => array(
'allowed_values' => array(
0 => array(
'vocabulary' => 'supporter_tags',
'parent' => 0,
),
),
'options_list_callback' => 'i18n_taxonomy_allowed_values',
'profile2_private' => FALSE,
),
'translatable' => 0,
'type' => 'taxonomy_term_reference',
);

return $field_bases;
}
48 changes: 48 additions & 0 deletions campaignion_test/campaignion_test.features.field_instance.inc
Expand Up @@ -514,6 +514,54 @@ function campaignion_test_field_default_field_instances() {
),
);

// Exported field_instance: 'redhen_contact-contact-source_tag'.
$field_instances['redhen_contact-contact-source_tag'] = array(
'bundle' => 'contact',
'custom_add_another' => '',
'custom_remove' => '',
'default_value' => array(
0 => array(
'tid' => NULL,
),
),
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'i18n_taxonomy',
'settings' => array(),
'type' => 'i18n_taxonomy_term_reference_link',
'weight' => 17,
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'entity_type' => 'redhen_contact',
'field_name' => 'source_tag',
'label' => 'Source tag',
'required' => 0,
'settings' => array(
'custom_add_another' => '',
'custom_remove' => '',
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'taxonomy',
'settings' => array(
'autocomplete_path' => 'taxonomy/autocomplete',
'size' => 60,
),
'type' => 'taxonomy_autocomplete',
'weight' => 13,
),
);

// Exported field_instance: 'redhen_contact-contact-supporter_tags'
$field_instances['redhen_contact-contact-supporter_tags'] = array(
'bundle' => 'contact',
Expand Down
3 changes: 2 additions & 1 deletion campaignion_test/campaignion_test.info
Expand Up @@ -9,6 +9,7 @@ dependencies[] = campaignion_activity
dependencies[] = campaignion_newsletters
dependencies[] = campaignion_newsletters_mailchimp
dependencies[] = campaignion_supporter_tags
dependencies[] = campaignion_source_tags
dependencies[] = campaignion_email_to_target
dependencies[] = campaignion_email_to_target_counter
dependencies[] = campaignion_webform_tokens
Expand Down Expand Up @@ -39,7 +40,6 @@ features[field_base][] = field_salutation
features[field_base][] = field_social_network_links
features[field_base][] = field_title
features[field_base][] = redhen_contact_email
features[field_base][] = supporter_tags
features[field_instance][] = redhen_contact-contact-field_address
features[field_instance][] = redhen_contact-contact-field_date_of_birth
features[field_instance][] = redhen_contact-contact-field_direct_mail_newsletter
Expand All @@ -52,6 +52,7 @@ features[field_instance][] = redhen_contact-contact-field_salutation
features[field_instance][] = redhen_contact-contact-field_social_network_links
features[field_instance][] = redhen_contact-contact-field_title
features[field_instance][] = redhen_contact-contact-redhen_contact_email
features[field_instance][] = redhen_contact-contact-source_tags
features[field_instance][] = redhen_contact-contact-supporter_tags
features[redhen_contact_type][] = contact
features[taxonomy][] = supporter_tags
Expand Down

0 comments on commit fbbe5b0

Please sign in to comment.