View source
<?php
namespace Unish;
class feedsDrushTest extends CommandUnishTestCase {
public function setUp() {
if (UNISH_DRUPAL_MAJOR_VERSION != 7) {
$this
->markTestSkipped('This version of Feeds is for D7.');
}
$site = $this
->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'standard');
$root = $this
->webroot();
$this->siteOptions = array(
'root' => $root,
'uri' => key($site),
'yes' => NULL,
);
$this
->copyLocalFeedsDirToTestDir();
$this
->execDrush('pm-enable', array(
'feeds',
));
$this
->execDrush('pm-enable', array(
'feeds_import',
));
}
protected function copyLocalFeedsDirToTestDir() {
$source = dirname(dirname(dirname(__FILE__)));
$dest = $this
->getFeedsDir();
mkdir($dest, 0755, TRUE);
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item
->isDir()) {
mkdir($dest . "/" . $iterator
->getSubPathName());
}
else {
copy($item, $dest . "/" . $iterator
->getSubPathName());
}
}
}
protected function execDrush($command, array $args, array $options = array()) {
return $this
->drush($command, $args, $this->siteOptions + $options);
}
protected function getFeedsDir() {
return $this
->webroot() . '/' . $this
->drupalSitewideDirectory() . '/modules/feeds';
}
public function testImportUsingFileOption() {
$this
->execDrush('feeds-import', array(
'node',
), array(
'file' => $this
->getFeedsDir() . '/tests/feeds/content.csv',
));
$eval = "print db_query('SELECT COUNT(*) FROM {node}')->fetchField()";
$this
->execDrush('php-eval', array(
$eval,
));
$this
->assertEquals('2', $this
->getOutput());
}
public function testDisableFeedsImporter() {
$eval = "print feeds_importer('user')->disabled;";
$this
->execDrush('php-eval', array(
$eval,
));
$this
->assertEquals('', $this
->getOutput());
$this
->execDrush('feeds-disable', array(
'user',
));
$this
->execDrush('php-eval', array(
$eval,
));
$this
->assertEquals('1', $this
->getOutput());
}
public function testNoImportForDisabledImporter() {
$this
->execDrush('feeds-disable', array(
'node',
));
$this
->drush('feeds-import', array(
'node',
), $this->siteOptions + array(
'file' => $this
->getFeedsDir() . '/tests/feeds/content.csv',
), NULL, NULL, static::EXIT_ERROR);
$eval = "print db_query('SELECT COUNT(*) FROM {node}')->fetchField()";
$this
->execDrush('php-eval', array(
$eval,
));
$this
->assertEquals('0', $this
->getOutput());
}
}