forked from ding2/ting_covers
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathting_covers.test
More file actions
75 lines (59 loc) · 2.72 KB
/
ting_covers.test
File metadata and controls
75 lines (59 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class TingCoversTestCase extends DrupalWebTestCase {
static function getInfo() {
return array(
'name' => 'Ting covers',
'description' => 'Check if we can retrieve covers',
'group' => 'Ding! - Ting covers',
);
}
public function setUp() {
$addi_info = array( 'addi_wsdl_url' => 'http://moreinfo.addi.dk/2.1/moreinfo.wsdl',
'addi_username' => 'netpunkt',
'addi_group' => '010100',
'addi_password' => '20Koster');
$this->profile = 'minimal';
parent::setUp('image', 'ting_covers');
//All variables have been reset to set these again!
foreach ($addi_info as $k => $v) {
variable_set('addi_'.$k, $v);
}
// allow you to log messages with error_log() to "sites/default/files/test.log"
$logfile = conf_path() . '/files/test.log';
ini_set('log_errors', 1);
ini_set('error_log', $logfile);
$this->web_user = $this->drupalCreateUser(array('access content'));
$this->drupalLogin($this->web_user);
}
public function testCoverRetrieval() {
// there's a hard-coded test case for faustnr 12345678 in class AdditionalInformationService
$cover = $coverData[] = "12345678:medium";
$response = json_decode($this->simplePost('ting/covers', $coverData));
$this->assertTrue(isset($response->$cover), t('Local cover url for id %local_id returned', array('%local_id' => array_shift(explode(':', $cover)))), 'Ting covers');
$this->assertTrue(filter_var($response->$cover, FILTER_VALIDATE_URL), t('Local cover url is valid url'), 'Ting covers');
}
/**
* Simplified version of drupalPost() that allows posting to AJAX.
* http://tiger-fish.com/blog/drupal-6-posting-ajax-callbacks-simpletest
*/
protected function simplePost($path, $edit, array $options = array(), array $headers = array()) {
$action = $this->getAbsoluteUrl($path);
/*
$post = array();
foreach ($edit as $key => $value) {
// Encode according to application/x-www-form-urlencoded
// Both names and values needs to be urlencoded.
// $post[$key] = urlencode($key) . '=' . urlencode($value);
$post[$key] = urlencode($key) . '=' . urlencode($value);
}
$post = implode('&', $post);
*/
// there's a hard-coded test case for faustnr 12345678 in class AdditionalInformationService
$post = 'coverData[0]=12345678:medium';
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $post, CURLOPT_POST => TRUE, CURLOPT_HTTPHEADER => $headers));
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
$this->verbose('simplePost has posted data to ' . $path. '. Response: '.$out);
return $out;
}
}