-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistrar_api.test
140 lines (120 loc) · 3.61 KB
/
registrar_api.test
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// $Id$
/**
* @file
* Simpletest tests for the registrar API
* This file does primarily provide some general code, registrar_dummy.test should implement actual tests of this API.
*/
/**
* Base class for Registrar API test cases
*/
abstract class RegistrarAPITestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp();
}
function tearDown() {
parent::tearDown();
}
/**
* Test registrar_api_check_domains through the default registrar.
*/
function testAPICheckDomains() {
$randomdomain = $this->randomDomainName();
// Test a registered name
$actual = registrar_api_check_domains(array('drupal.org', $randomdomain));
$desired = array(
'drupal.org' => array(
'Domain' => 'drupal.org',
'Available' => FALSE,
),
$randomdomain => array(
'Domain' => $randomdomain,
'Available' => TRUE,
/*
'ErrorNo' => '',
'Description' => '',
*/
)
);
$this->assertEqual($actual, $desired, t('Testing check_domains on a registered and free domain name'));
}
/**
* Test registrar_api_domains_getlist through the default registrar.
*/
function testAPIDomainsGetlist() {
// Test a registered name
$actual = registrar_api_domains_getlist();
$this->assertTrue(is_array($actual), t('registrar_api_domains_getlist returns an array'));
// Do some basic check on the returned array formatting.
foreach($actual as $key => $value) {
$this->assertEqual($key, $value['Name'], 'Name attribute equal to array key');
}
}
/**** Helper fuctions ******/
/**
* Define which registrar implementation is the default
* @param $registrar_module
*/
function setDefaultRegistrar($registrar_module) {
variable_set('registrar_api_default_registrar', $registrar_module);
}
/**
* Generate a random domainname, hopefully not already registred.
*
* @return string Generated domain name
*/
function randomDomainName() {
$exts = array('.com', '.net', '.org');
$ext = $exts[mt_rand(0, count($exts) - 1)];
$domain = $this->randomName(12) . $ext;
return $domain;
}
function getContacts() {
// Use the contact info setup by user 1 for now
global $db_prefix;
// Reset the db prefix since simpletest changes this, this obviously
// won't work for those who actually use a prefix.
$tmp = $db_prefix;
$db_prefix = '';
$contacts = registrar_api_get_user_contacts(1);
$db_prefix = $tmp;
return $contacts;
}
}
class GeneralRegistrarAPITestCase extends RegistrarAPITestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
return array(
'name' => t('General Registrar API tests'),
'description' => t('Registrar API functionality.'),
'group' => t('Registrar API'),
);
}
// @todo Test setting the default registrar via /admin/settings/registrar_api
}
class RegistrarAPIUnitTestCase extends DrupalUnitTestCase {
function getInfo() {
return array(
'name' => t('Registrar API Unit tests'),
'description' => t('Tests for the Registrar API helper code.'),
'group' => t('Registrar API'),
);
}
/**
* Test the workings of registrar_api_split_domain_name()
*/
function testSplitDomainName() {
$tests = array(
'drupal.org' => array('drupal', 'org'),
'example.com' => array('example', 'com'),
'example-foo.com' => array('example-foo', 'com'),
'examplecom' => array(), // Missing dot
);
foreach ($tests as $test => $expected) {
$result = registrar_api_split_domain_name($test);
$this->assertEqual($result, $expected);
}
}
}