]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/SystemTest.php
Merge pull request #9187 from MrPetovan/bug/9182-frio-modal-width
[friendica.git] / tests / src / Core / SystemTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Core;
23
24 use Dice\Dice;
25 use Friendica\App\BaseURL;
26 use Friendica\Core\System;
27 use Friendica\DI;
28 use PHPUnit\Framework\TestCase;
29
30 class SystemTest extends TestCase
31 {
32         private function useBaseUrl()
33         {
34                 $baseUrl = \Mockery::mock(BaseURL::class);
35                 $baseUrl->shouldReceive('getHostname')->andReturn('friendica.local')->once();
36                 $dice = \Mockery::mock(Dice::class);
37                 $dice->shouldReceive('create')->with(BaseURL::class)->andReturn($baseUrl);
38
39                 DI::init($dice);
40         }
41
42         private function assertGuid($guid, $length, $prefix = '')
43         {
44                 $length -= strlen($prefix);
45                 $this->assertRegExp("/^" . $prefix . "[a-z0-9]{" . $length . "}?$/", $guid);
46         }
47
48         function testGuidWithoutParameter()
49         {
50                 $this->useBaseUrl();
51                 $guid = System::createGUID();
52                 $this->assertGuid($guid, 16);
53         }
54
55         function testGuidWithSize32()
56         {
57                 $this->useBaseUrl();
58                 $guid = System::createGUID(32);
59                 $this->assertGuid($guid, 32);
60         }
61
62         function testGuidWithSize64()
63         {
64                 $this->useBaseUrl();
65                 $guid = System::createGUID(64);
66                 $this->assertGuid($guid, 64);
67         }
68
69         function testGuidWithPrefix()
70         {
71                 $guid = System::createGUID(23, 'test');
72                 $this->assertGuid($guid, 23, 'test');
73         }
74 }