feeds_mapper_link.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * @file
  4. * Test case for CCK link mapper mappers/date.inc.
  5. */
  6. /**
  7. * Class for testing Feeds <em>link</em> mapper.
  8. */
  9. class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Mapper: Link',
  13. 'description' => 'Test Feeds Mapper support for Link fields.',
  14. 'group' => 'Feeds',
  15. 'dependencies' => array('link'),
  16. );
  17. }
  18. public function setUp() {
  19. parent::setUp(array('link'));
  20. }
  21. /**
  22. * Basic test loading a single entry CSV file.
  23. */
  24. public function test() {
  25. $static_title = $this->randomName();
  26. // Create content type.
  27. $typename = $this->createContentType(array(), array(
  28. 'alpha' => array(
  29. 'type' => 'link_field',
  30. 'instance_settings' => array(
  31. 'instance[settings][title]' => 'required',
  32. ),
  33. ),
  34. 'beta' => array(
  35. 'type' => 'link_field',
  36. 'instance_settings' => array(
  37. 'instance[settings][title]' => 'none',
  38. ),
  39. ),
  40. 'gamma' => array(
  41. 'type' => 'link_field',
  42. 'instance_settings' => array(
  43. 'instance[settings][title]' => 'optional',
  44. ),
  45. ),
  46. 'omega' => array(
  47. 'type' => 'link_field',
  48. 'instance_settings' => array(
  49. 'instance[settings][title]' => 'value',
  50. 'instance[settings][title_value]' => $static_title,
  51. ),
  52. ),
  53. ));
  54. // Create importer configuration.
  55. $this->createImporterConfiguration(); //Create a default importer configuration
  56. $this->setSettings('syndication', 'FeedsNodeProcessor', array('content_type' => $typename)); //Processor settings
  57. $this->addMappings('syndication', array(
  58. 0 => array(
  59. 'source' => 'title',
  60. 'target' => 'title'
  61. ),
  62. 1 => array(
  63. 'source' => 'timestamp',
  64. 'target' => 'created'
  65. ),
  66. 2 => array(
  67. 'source' => 'description',
  68. 'target' => 'body'
  69. ),
  70. 3 => array(
  71. 'source' => 'url',
  72. 'target' => 'field_alpha:url'
  73. ),
  74. 4 => array(
  75. 'source' => 'title',
  76. 'target' => 'field_alpha:title'
  77. ),
  78. 5 => array(
  79. 'source' => 'url',
  80. 'target' => 'field_beta:url'
  81. ),
  82. 6 => array(
  83. 'source' => 'url',
  84. 'target' => 'field_gamma:url'
  85. ),
  86. 7 => array(
  87. 'source' => 'title',
  88. 'target' => 'field_gamma:title'
  89. ),
  90. 8 => array(
  91. 'source' => 'url',
  92. 'target' => 'field_omega:url'
  93. ),
  94. ));
  95. // Import RSS file.
  96. $nid = $this->createFeedNode();
  97. // Assert 10 items aggregated after creation of the node.
  98. $this->assertText('Created 10 nodes');
  99. // Edit the imported node.
  100. $this->drupalGet('node/2/edit');
  101. $url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
  102. $title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
  103. $this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
  104. $this->assertNodeFieldValue('beta', array('url' => $url));
  105. $this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
  106. $this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $static_title));
  107. // Test the static title.
  108. $this->drupalGet('node/2');
  109. $this->assertText($static_title, 'Static title link found.');
  110. }
  111. /**
  112. * Override parent::getFormFieldsNames().
  113. */
  114. protected function getFormFieldsNames($field_name, $index) {
  115. if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
  116. $fields = array("field_{$field_name}[und][{$index}][url]");
  117. if (in_array($field_name, array('alpha', 'gamma'))) {
  118. $fields[] = "field_{$field_name}[und][{$index}][title]";
  119. }
  120. return $fields;
  121. }
  122. else {
  123. return parent::getFormFieldsNames($field_name, $index);
  124. }
  125. }
  126. /**
  127. * Override parent::getFormFieldsValues().
  128. */
  129. protected function getFormFieldsValues($field_name, $value) {
  130. if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
  131. if (!is_array($value)) {
  132. $value = array('url' => $value);
  133. }
  134. $values = array($value['url']);
  135. if (in_array($field_name, array('alpha', 'gamma'))) {
  136. $values[] = isset($value['title']) ? $value['title'] : '';
  137. }
  138. return $values;
  139. }
  140. else {
  141. return parent::getFormFieldsValues($field_name, $index);
  142. }
  143. }
  144. }