]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/SystemTest.php
Add output for installerTest
[friendica.git] / tests / src / Core / SystemTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core;
4
5 use Dice\Dice;
6 use Friendica\App\BaseURL;
7 use Friendica\Core\System;
8 use Friendica\DI;
9 use PHPUnit\Framework\TestCase;
10
11 class SystemTest extends TestCase
12 {
13         private function useBaseUrl()
14         {
15                 $baseUrl = \Mockery::mock(BaseURL::class);
16                 $baseUrl->shouldReceive('getHostname')->andReturn('friendica.local')->once();
17                 $dice = \Mockery::mock(Dice::class);
18                 $dice->shouldReceive('create')->with(BaseURL::class, [])->andReturn($baseUrl);
19
20                 DI::init($dice);
21         }
22
23         private function assertGuid($guid, $length, $prefix = '')
24         {
25                 $length -= strlen($prefix);
26                 $this->assertRegExp("/^" . $prefix . "[a-z0-9]{" . $length . "}?$/", $guid);
27         }
28
29         function testGuidWithoutParameter()
30         {
31                 $this->useBaseUrl();
32                 $guid = System::createGUID();
33                 $this->assertGuid($guid, 16);
34         }
35
36         function testGuidWithSize32()
37         {
38                 $this->useBaseUrl();
39                 $guid = System::createGUID(32);
40                 $this->assertGuid($guid, 32);
41         }
42
43         function testGuidWithSize64()
44         {
45                 $this->useBaseUrl();
46                 $guid = System::createGUID(64);
47                 $this->assertGuid($guid, 64);
48         }
49
50         function testGuidWithPrefix()
51         {
52                 $guid = System::createGUID(23, 'test');
53                 $this->assertGuid($guid, 23, 'test');
54         }
55 }