12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- class backendCase extends Drush_TestCase {
- const DRUSH_BACKEND_OUTPUT_DELIMITER = 'DRUSH_BACKEND_OUTPUT_START>>>%s<<<DRUSH_BACKEND_OUTPUT_END';
-
- function testOrigin() {
- $exec = sprintf('%s %s version --simulate --ssh-options=%s | grep ssh', self::escapeshellarg(UNISH_DRUSH), self::escapeshellarg('user@server/path/to/drupal#sitename'), self::escapeshellarg('-i mysite_dsa'));
- $this->execute($exec);
-
- $expected = "proc_open: ssh -i mysite_dsa 'user'@'server' 'drush --uri='\''sitename'\'' --root='\''/path/to/drupal'\'' --simulate version --backend 2>&1' 2>&1";
- $output = $this->getOutput();
- $this->assertEquals($expected, $output, 'Expected ssh command was built');
- }
-
- function testTarget() {
- $stdin = json_encode(array('filter'=>'sql'));
- $exec = sprintf('echo %s | %s help --backend', self::escapeshellarg($stdin), self::escapeshellarg(UNISH_DRUSH));
- $this->execute($exec);
- $parsed = $this->parse($this->getOutput());
- $this->assertTrue((bool) $parsed, 'Successfully parsed backend output');
- $this->assertArrayHasKey('log', $parsed);
- $this->assertArrayHasKey('output', $parsed);
- $this->assertArrayHasKey('object', $parsed);
- $this->assertEquals(self::EXIT_SUCCESS, $parsed['error_status']);
-
- $this->assertStringStartsWith('SQL commands', $parsed['output']);
- $this->assertEquals('Bootstrap to phase 0.', $parsed['log'][0]['message']);
-
- $exec = sprintf('%s core-cron --backend 2>/dev/null', self::escapeshellarg(UNISH_DRUSH));
- $this->execute($exec, self::EXIT_ERROR);
- $parsed = $this->parse($this->getOutput());
- $this->assertEquals(1, $parsed['error_status']);
- $this->assertArrayHasKey('DRUSH_NO_DRUPAL_ROOT', $parsed['error_log']);
- }
-
- function parse($string) {
- $regex = sprintf(self::DRUSH_BACKEND_OUTPUT_DELIMITER, '(.*)');
- preg_match("/$regex/s", $string, $match);
- if ($match[1]) {
-
- $output = $match[1];
-
- $string = trim(str_replace(sprintf(self::DRUSH_BACKEND_OUTPUT_DELIMITER, $match[1]), '', $string));
- }
- if ($output) {
- $data = json_decode($output, TRUE);
- if (is_array($data)) {
- return $data;
- }
- }
- return $string;
- }
- }
|