1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Tests for Developer Table model |
5
|
|
|
* |
6
|
|
|
* phpMyAdmin Error reporting server |
7
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
8
|
|
|
* |
9
|
|
|
* Licensed under The MIT License |
10
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
11
|
|
|
* Redistributions of files must retain the above copyright notice. |
12
|
|
|
* |
13
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
15
|
|
|
* |
16
|
|
|
* @see https://www.phpmyadmin.net/ |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Test\TestCase\Model\Table; |
20
|
|
|
|
21
|
|
|
use App\Model\Table\DevelopersTable; |
22
|
|
|
use Cake\Datasource\Exception\RecordNotFoundException; |
23
|
|
|
use Cake\ORM\TableRegistry; |
24
|
|
|
use Cake\TestSuite\TestCase; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* App\Model\Table\DevelopersTable Test Case |
28
|
|
|
*/ |
29
|
|
|
class DevelopersTableTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Test subject |
33
|
|
|
* |
34
|
|
|
* @var DevelopersTable |
35
|
|
|
*/ |
36
|
|
|
public $Developers; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Fixtures. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $fixtures = ['app.Developers']; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* setUp method |
47
|
|
|
*/ |
48
|
|
|
public function setUp(): void |
49
|
|
|
{ |
50
|
|
|
parent::setUp(); |
51
|
|
|
$this->Developers = TableRegistry::getTableLocator()->get('Developers'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* tearDown method |
56
|
|
|
*/ |
57
|
|
|
public function tearDown(): void |
58
|
|
|
{ |
59
|
|
|
unset($this->Developers); |
60
|
|
|
|
61
|
|
|
parent::tearDown(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test saveFromGithub method |
66
|
|
|
*/ |
67
|
|
|
public function testSaveFromGithub(): void |
68
|
|
|
{ |
69
|
|
|
$i = 0; |
70
|
|
|
while (1) { |
71
|
|
|
try { |
72
|
|
|
$i++; |
73
|
|
|
$savedDeveloper = $this->Developers->get($i); |
74
|
|
|
} catch (RecordNotFoundException $e) { |
75
|
|
|
break; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$nextId = $i; |
80
|
|
|
|
81
|
|
|
$githubInfo = [ |
82
|
|
|
'login' => 'pma-bot', |
83
|
|
|
'id' => 1231231, |
84
|
|
|
'gravatar_id' => '', |
85
|
|
|
'url' => 'https://api.github.com/users/pma-bot', |
86
|
|
|
'name' => 'PMA BOT', |
87
|
|
|
'email' => '[email protected]', |
88
|
|
|
'has_commit_access' => 0, |
89
|
|
|
]; |
90
|
|
|
$developer = $this->Developers->newEmptyEntity(); |
91
|
|
|
$access_token = 'abc'; |
92
|
|
|
|
93
|
|
|
$this->Developers->saveFromGithub($githubInfo, $access_token, $developer); |
94
|
|
|
|
95
|
|
|
$savedDeveloper = $this->Developers->get($nextId); |
96
|
|
|
$this->assertNotEquals(null, $savedDeveloper); |
97
|
|
|
$this->assertEquals(1231231, $savedDeveloper->github_id); |
98
|
|
|
$this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
99
|
|
|
$this->assertEquals('[email protected]', $savedDeveloper->email); |
100
|
|
|
$this->assertEquals(false, $savedDeveloper->has_commit_access); |
101
|
|
|
|
102
|
|
|
$updatedGithubInfo = [ |
103
|
|
|
'login' => 'pma-bot', |
104
|
|
|
'id' => 1231231, |
105
|
|
|
'gravatar_id' => '', |
106
|
|
|
'url' => 'https://api.github.com/users/pma-bot', |
107
|
|
|
'name' => 'PMA BOT', |
108
|
|
|
'email' => '[email protected]', |
109
|
|
|
'has_commit_access' => 1,// changed |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
$this->Developers->saveFromGithub($updatedGithubInfo, $access_token, $developer); |
113
|
|
|
|
114
|
|
|
$savedDeveloper = $this->Developers->get($nextId); |
115
|
|
|
$this->assertNotEquals(null, $savedDeveloper); |
116
|
|
|
$this->assertEquals(1231231, $savedDeveloper->github_id); |
117
|
|
|
$this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
118
|
|
|
$this->assertEquals('[email protected]', $savedDeveloper->email); |
119
|
|
|
$this->assertEquals(true, $savedDeveloper->has_commit_access); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|