Skip to content
Snippets Groups Projects
Commit e599e774 authored by Alex Barth's avatar Alex Barth
Browse files

alex_b: Fix file mapper, add file mapper tests, make flickr.xml point to local assets.

parent e9c27ed5
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX
---------------------------------
- alex_b: Fix file mapper, add file mapper tests, make flickr.xml point to
local assets.
- #953538 yhahn: Remove BOM from UTF-8 files.
Adds sanitizeFile() and sanitizeRaw() methods to FeedsFetcherResult.
Extending classes that override either the getRaw() or getFilePath() methods
......
......@@ -13,6 +13,7 @@ files[] = tests/feeds.test.inc
files[] = tests/feeds_date_time.test
files[] = tests/feeds_mapper_date.test
files[] = tests/feeds_mapper_field.test
files[] = tests/feeds_mapper_file.test
files[] = tests/feeds_mapper_test.inc
files[] = tests/feeds_fetcher_file.test
files[] = tests/feeds_processor_node.test
......
......@@ -872,6 +872,8 @@ function feeds_include_library($file, $library) {
require libraries_get_path($library) ."/$file";
}
else {
// @todo: Throws "Deprecated function: Assigning the return value of new
// by reference is deprecated."
require DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file";
}
}
......
......@@ -240,10 +240,14 @@ class FeedsGeoTermElement extends FeedsTermElement {
*/
class FeedsEnclosure extends FeedsElement {
protected $mime_type;
protected $file;
/**
* Constructor, requires MIME type.
*
* @param $value
* A path to a local file or a URL to a remote document.
* @param $mimetype
* The mime type of the resource.
*/
public function __construct($value, $mime_type) {
parent::__construct($value);
......@@ -276,34 +280,30 @@ class FeedsEnclosure extends FeedsElement {
*
* @param $destination
* The path or uri specifying the target directory in which the file is
* expected. If not given, a previously defined directory will be assumed.
* The default directory is tmp.
* expected.
*
* @return
* A file path to the enclosed resource.
* A Drupal file object of the enclosed resource. The file object is
* permanent.
*
* @todo file_destination(*, FILE_EXISTS_RENAME) is not concurrency safe.
* @throws Exception
* If file object could not be created.
*/
public function getFile($destination) {
if (empty($this->file) && $this->getValue()) {
// File is in the right place, nothing to do.
if (strpos($this->getValue(), $destination) === 0) {
$this->file = $this->getValue();
return $this->file;
}
if ($this->getValue()) {
// Prepare destination directory.
file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
// Copy or save file depending its location.
// Copy or save file depending on whether it is remote or local.
if (drupal_realpath($this->getValue())) {
$file = new stdClass();
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->uri = $this->getValue();
$this->file = file_copy($file, $destination);
if (strpos($file->uri, $destination) !== 0) {
$file = file_copy($file, $destination);
}
}
else {
$filename = basename($this->getValue());
......@@ -311,15 +311,15 @@ class FeedsEnclosure extends FeedsElement {
require_once (drupal_get_path('module', 'transliteration') . '/transliteration.inc');
$filename = transliteration_clean_filename($filename);
}
$this->file = file_save_data($this->getContent(), "$destination/$filename");
$file = file_save_data($this->getContent(), "$destination/$filename");
}
// We couldn't make sense of this enclosure, throw an exception.
if (!$this->file) {
if (!$file) {
throw new Exception(t('Invalid enclosure %enclosure', array('%enclosure' => $this->getValue())));
}
}
return $this->file;
return $file;
}
}
......
tests/feeds/assets/attersee.jpeg

223 KiB

tests/feeds/assets/foosball.jpeg

94.3 KiB

tests/feeds/assets/hstreet.jpeg

92.5 KiB

tests/feeds/assets/tubing.jpeg

112 KiB

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?php
print '<?xml version="1.0" encoding="utf-8" standalone="yes"?>';
?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:flickr="urn:flickr:" xmlns:media="http://search.yahoo.com/mrss/">
......@@ -29,7 +31,7 @@
<uri>http://www.flickr.com/people/a-barth/</uri>
</author>
<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/deed.en" />
<link rel="enclosure" type="image/jpeg" href="http://farm4.static.flickr.com/3599/3596408735_ce2f0c4824_b.jpg" />
<link rel="enclosure" type="image/jpeg" href="<?php print $image_urls[0]; ?>" />
<category term="color" scheme="http://www.flickr.com/photos/tags/" />
<category term="film" scheme="http://www.flickr.com/photos/tags/" />
......@@ -61,7 +63,7 @@
<uri>http://www.flickr.com/people/a-barth/</uri>
</author>
<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/deed.en" />
<link rel="enclosure" type="image/jpeg" href="http://farm4.static.flickr.com/3261/2640019371_495c3f51a2_b.jpg" />
<link rel="enclosure" type="image/jpeg" href="<?php print $image_urls[1]; ?>" />
<category term="b" scheme="http://www.flickr.com/photos/tags/" />
<category term="blackandwhite" scheme="http://www.flickr.com/photos/tags/" />
......@@ -104,7 +106,7 @@
<uri>http://www.flickr.com/people/a-barth/</uri>
</author>
<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/deed.en" />
<link rel="enclosure" type="image/jpeg" href="http://farm4.static.flickr.com/3606/3686290986_334c427e8c_b.jpg" />
<link rel="enclosure" type="image/jpeg" href="<?php print $image_urls[2]; ?>" />
<category term="lake" scheme="http://www.flickr.com/photos/tags/" />
<category term="green" scheme="http://www.flickr.com/photos/tags/" />
......@@ -139,7 +141,7 @@
<uri>http://www.flickr.com/people/a-barth/</uri>
</author>
<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/deed.en" />
<link rel="enclosure" type="image/jpeg" href="http://farm4.static.flickr.com/3083/2640845934_85c11e5a18_b.jpg" />
<link rel="enclosure" type="image/jpeg" href="<?php print $image_urls[3]; ?>" />
<category term="nightphotography" scheme="http://www.flickr.com/photos/tags/" />
<category term="b" scheme="http://www.flickr.com/photos/tags/" />
......
<?php
// $Id$
/**
* @file
* Test case for Filefield mapper mappers/filefield.inc.
*/
/**
* Class for testing Feeds file mapper.
*
* @todo Add a test for enclosures using a local file that is
* a) in place and that
* b) needs to be copied from one location to another.
*/
class FeedsMapperFileTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => t('Mapper: File field'),
'description' => t('Test Feeds Mapper support for file fields. <strong>Requires SimplePie library</strong>.'),
'group' => t('Feeds'),
);
}
/**
* Set up the
*/
public function setUp() {
// Call parent setup with the required module
parent::setUp(array('file', 'feeds_tests'));
}
/**
* Basic test loading a single entry CSV file.
*/
public function test() {
$typename = $this->createContentType(NULL, array('files' => 'file'));
// Create importer configuration.
$this->createImporterConfiguration();
$this->setPlugin('syndication', 'FeedsSimplePieParser');
$this->setSettings('syndication', 'FeedsNodeProcessor', array('content_type' => $typename));
$this->addMappings('syndication', array(
array(
'source' => 'title',
'target' => 'title'
),
array(
'source' => 'timestamp',
'target' => 'created'
),
array(
'source' => 'description',
'target' => 'body'
),
array(
'source' => 'enclosures',
'target' => 'field_files'
),
));
$nid = $this->createFeedNode('syndication', $GLOBALS['base_url'] . '/testing/feeds/flickr.xml');
$this->assertText('Created 4 nodes');
$filename = array('tubing', 'foosball', 'attersee', 'hstreet');
for($i = 0; $i < 4; $i++) {
$this->drupalGet('node/'. ($i+2) .'/edit');
$this->assertText($filename[$i]);
}
}
/**
* Handle file field widgets.
*/
public function selectFieldWidget($fied_name, $field_type) {
if ($field_type == 'file') {
return 'file_generic';
}
else {
return parent::selectFieldWidget($fied_name, $field_type);
}
}
}
; $Id$
name = "Feeds module tests"
description = "Support module for Feeds related testing."
package = Testing
version = VERSION
core = 7.x
files[] = feeds_test.module
hidden = TRUE
<?php
// $Id$
/**
* Implements hook_menu().
*/
function feeds_tests_menu() {
$items['testing/feeds/flickr.xml'] = array(
'page callback' => 'feeds_tests_flickr',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_theme().
*/
function feeds_tests_theme() {
return array(
'feeds_tests_flickr' => array(
'variables' => array('image_urls' => array()),
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
'template' => 'feeds-tests-flickr',
),
);
}
/**
* Outputs flickr test feed.
*/
function feeds_tests_flickr() {
$images = array(
0 => "tubing.jpeg",
1 => "foosball.jpeg",
2 => "attersee.jpeg",
3 => "hstreet.jpeg",
);
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
foreach ($images as &$image) {
$image = url("$path/$image", array('absolute' => TRUE));
}
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
print theme('feeds_tests_flickr', array('image_urls' => $images));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment