Test Failed
Branch release_2_0 (5e3e46)
by Stefan
08:20
created

MockProfileSilverbullet   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
/*
3
 * *****************************************************************************
4
 * Contributions to this work were made on behalf of the GÉANT project, a 
5
 * project that has received funding from the European Union’s Framework 
6
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
7
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
8
 * 691567 (GN4-1) and No. 731122 (GN4-2).
9
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
10
 * of the copyright in all material which was developed by a member of the GÉANT
11
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
12
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
13
 * UK as a branch of GÉANT Vereniging.
14
 * 
15
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
16
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
17
 *
18
 * License: see the web/copyright.inc.php file in the file structure or
19
 *          <base_url>/copyright.php after deploying the software
20
 */
21
22
/**
23
 * 
24
 * @author Zilvinas Vaira
25
 *
26
 */
27
class MockProfileSilverbullet extends \core\ProfileSilverbullet{
28
    
29
    /**
30
     * 
31
     * @var int
32
     */
33
    private $instId;
34
    
35
    /**
36
     * 
37
     * @var array
38
     */
39
    private $generatedCertificates = array();
40
    
41
    /**
42
     * 
43
     * @param \core\DBConnection $databaseHandle
44
     */
45
    public function __construct(\core\DBConnection $databaseHandle){
46
        $this->databaseHandle = $databaseHandle;
47
        if($this->databaseHandle->exec("INSERT INTO institution (country) VALUES('LT')")){
48
            $this->instId = $this->databaseHandle->lastID();
49
        }
50
        if($this->databaseHandle->exec("INSERT INTO profile (inst_id, realm) VALUES($this->instId, 'test.realm.tst')")){
51
            $this->identifier = $this->databaseHandle->lastID();
52
        }
53
        $this->attributes = array(array('name' => 'hiddenprofile:tou_accepted'));
54
    }
55
    
56
    /**
57
     * 
58
     */
59
    public function delete(){
60
        $this->databaseHandle->exec("DELETE FROM `institution` WHERE `inst_id`='" . $this->instId . "'");
61
        $this->databaseHandle->exec("DELETE FROM `profile` WHERE `profile_id`='" . $this->identifier . "'");
62
    }
63
    
64
    /**
65
     * 
66
     * {@inheritDoc}
67
     * @see \core\ProfileSilverbullet::generateCertificate()
68
     */
69
    public function generateCertificate($serial, $cn){
70
        $this->generatedCertificates[$serial] = $cn;
71
    }
72
        
73
    /**
74
     * 
75
     * @param string $serial
76
     * @param string $cn
77
     * @return boolean
78
     */
79
    public function isGeneratedCertificate($serial, $cn){
80
        return isset($this->generatedCertificates[$serial]) && $this->generatedCertificates[$serial]==$cn;
81
    }
82
}
83