source: sipes/modules_contrib/feeds/tests/feeds_mapper_link.test @ 92213c1

stableversion-3.0
Last change on this file since 92213c1 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

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