· 9 years ago · Dec 26, 2016, 04:18 PM
1----------------- INFO FILE: --------------------------
2name = Licence Server
3description = The licence server
4core = 7.x
5
6dependencies[] = entity
7
8files[] = ls.utils.inc
9files[] = ls.entities.inc
10files[] = ls.controller.inc
11files[] = ls.api.inc
12files[] = tests/ls_api.test
13files[] = tests/ls_utilities.test
14
15------------------ INSTALL FILE --------------------
16<?php
17
18/**
19 * Implements hook_schema
20 */
21function ls_schema(){
22 $schema = array();
23
24 $schema['ls_licence'] = array(
25 "description" => "Base table for Licenses",
26
27 "fields" => array(
28 "slid" => array(
29 "description" => "The primary identifier of the License",
30 "type" => "serial",
31 "unsigned" => TRUE,
32 "not null" => TRUE
33 ),
34 ...
35 ),
36 'unique keys' => array(
37 'product_key' => array('product_key'),
38 ),
39 'primary key' => array('slid')
40 );
41
42
43 return $schema;
44}
45
46--------- ls_api.test --------
47<?php
48
49class LSAPITestCase extends DrupalWebTestCase
50{
51 protected $base_url = "/api/v1/";
52 protected $licence;
53 protected $secret_key = "aaaaaaaa";
54
55 public static function getInfo()
56 {
57 return array(
58 'name' => 'LS API',
59 'description' => 'Ensure that the API is working correctly.',
60 'group' => 'LS',
61 );
62 }
63
64 function setUp()
65 {
66 parent::setUp(array("entity", 'licence_server'));
67 }
68
69 /**
70 * Post data to a URL
71 *
72 * @param string $url The URL to post the data to
73 * @param array $data The data to post
74 * @return object The response from the server
75 */
76 private function postData($url, array $data)
77 {
78 $url = $this->getAbsoluteUrl($url);
79
80 $options = array(
81 'method' => 'POST',
82 'data' => drupal_http_build_query($data),
83 'timeout' => 15,
84 'headers' => array('Content-Type' => 'application/form-data'),
85 );
86
87 $out = drupal_http_request($url, $options);
88
89 return $out;
90 }
91
92 /**
93 * Test that an end point validates a request.
94 *
95 * The end point needs to:
96 * * Ensure that it is a POST,
97 * * Ensure that the required fields are present, and
98 * * Ensure that HMAC check is valid.
99 *
100 * @param string $end_point The full end point address (including $base_url).
101 * @param array $required_fields an array of required fields
102 */
103 private function endPointVerification($end_point, array $required_fields)
104 {
105 ...
106 }
107
108
109 /**
110 * Test the activation of licence
111 */
112 public function testLicenceActivate()
113 {
114 // First try activate an invalid licence
115 $this->endPointVerification($this->base_url . "licence-activate", array("productKey", "guid", "check"));
116
117 }
118
119
120}