root / drupal7 / sites / all / modules / feeds / tests / drush / feedsDrushTest.php @ ed9a13f1
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Unish; |
4 |
|
5 |
/**
|
6 |
* Tests Drush integration for Feeds. Based on Drush 8.
|
7 |
*
|
8 |
* To execute this test from the command line:
|
9 |
* @code
|
10 |
* UNISH_NO_TIMEOUTS=1 UNISH_DRUPAL_MAJOR_VERSION=7 /path/to/drush/vendor/bin/phpunit --configuration /path/to/drush/tests /path/to/feeds/tests/drush
|
11 |
* @endcode
|
12 |
* Replace '/path/to' with the appropriate path to the directory in question.
|
13 |
* Also be sure to have Drush installed with its dev dependencies and point to
|
14 |
* the phpunit version that comes with Drush. Fore more information, see the
|
15 |
* Feeds README file.
|
16 |
*
|
17 |
* @group commands
|
18 |
*/
|
19 |
class feedsDrushTest extends CommandUnishTestCase { |
20 |
|
21 |
/**
|
22 |
* {@inheritdoc}
|
23 |
*/
|
24 |
public function setUp() { |
25 |
if (UNISH_DRUPAL_MAJOR_VERSION != 7) { |
26 |
$this->markTestSkipped('This version of Feeds is for D7.'); |
27 |
} |
28 |
|
29 |
// Install the standard install profile.
|
30 |
$site = $this->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'standard'); |
31 |
$root = $this->webroot(); |
32 |
$this->siteOptions = array( |
33 |
'root' => $root, |
34 |
'uri' => key($site), |
35 |
'yes' => NULL, |
36 |
); |
37 |
|
38 |
// Copy the local Feeds directory to the test directory.
|
39 |
$this->copyLocalFeedsDirToTestDir();
|
40 |
|
41 |
// Enable the feeds_import module.
|
42 |
$this->execDrush('pm-enable', array('feeds')); |
43 |
$this->execDrush('pm-enable', array('feeds_import')); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* Copies the local Feeds directory to the directory used in the test.
|
48 |
*/
|
49 |
protected function copyLocalFeedsDirToTestDir() { |
50 |
$source = dirname(dirname(dirname(__FILE__))); |
51 |
$dest = $this->getFeedsDir(); |
52 |
|
53 |
mkdir($dest, 0755, TRUE); |
54 |
foreach (
|
55 |
$iterator = new \RecursiveIteratorIterator( |
56 |
new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), |
57 |
\RecursiveIteratorIterator::SELF_FIRST) as $item |
58 |
) { |
59 |
if ($item->isDir()) { |
60 |
mkdir($dest . "/" . $iterator->getSubPathName()); |
61 |
} |
62 |
else {
|
63 |
copy($item, $dest . "/" . $iterator->getSubPathName()); |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Wrapper around drush to always add the site options.
|
70 |
*
|
71 |
* @param string command
|
72 |
* The drush command to run.
|
73 |
* @param array args
|
74 |
* Command arguments.
|
75 |
* @param array $options
|
76 |
* An associative array containing options.
|
77 |
*/
|
78 |
protected function execDrush($command, array $args, array $options = array()) { |
79 |
return $this->drush($command, $args, $this->siteOptions + $options); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Returns path to Feeds directory.
|
84 |
*/
|
85 |
protected function getFeedsDir() { |
86 |
return $this->webroot() . '/' . $this->drupalSitewideDirectory() . '/modules/feeds'; |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Tests an import using the file option.
|
91 |
*/
|
92 |
public function testImportUsingFileOption() { |
93 |
// Perform an import.
|
94 |
$this->execDrush('feeds-import', array('node'), array( |
95 |
'file' => $this->getFeedsDir() . '/tests/feeds/content.csv', |
96 |
)); |
97 |
|
98 |
// Ensure that two nodes were created.
|
99 |
$eval = "print db_query('SELECT COUNT(*) FROM {node}')->fetchField()"; |
100 |
$this->execDrush('php-eval', array($eval)); |
101 |
$this->assertEquals('2', $this->getOutput()); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Tests if an importer can get disabled.
|
106 |
*/
|
107 |
public function testDisableFeedsImporter() { |
108 |
// First check that the user importer is enabled.
|
109 |
$eval = "print feeds_importer('user')->disabled;"; |
110 |
$this->execDrush('php-eval', array($eval)); |
111 |
$this->assertEquals('', $this->getOutput()); |
112 |
|
113 |
// Disable the user importer.
|
114 |
$this->execDrush('feeds-disable', array('user')); |
115 |
|
116 |
// Ensure that the importer is now disabled.
|
117 |
$this->execDrush('php-eval', array($eval)); |
118 |
$this->assertEquals('1', $this->getOutput()); |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Tests that no nodes get imported for a disabled importer.
|
123 |
*/
|
124 |
public function testNoImportForDisabledImporter() { |
125 |
// Disable the node importer.
|
126 |
$this->execDrush('feeds-disable', array('node')); |
127 |
|
128 |
// Try to perform an import. Drush command should fail.
|
129 |
$this->drush('feeds-import', array('node'), $this->siteOptions + array( |
130 |
'file' => $this->getFeedsDir() . '/tests/feeds/content.csv', |
131 |
), NULL, NULL, static::EXIT_ERROR); |
132 |
|
133 |
// Ensure that no nodes were imported.
|
134 |
$eval = "print db_query('SELECT COUNT(*) FROM {node}')->fetchField()"; |
135 |
$this->execDrush('php-eval', array($eval)); |
136 |
$this->assertEquals('0', $this->getOutput()); |
137 |
} |
138 |
|
139 |
} |