ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ClientIdTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once 'vendor/composer/vendor/autoload.php';
22
23use ILIAS\Data;
24use PHPUnit\Framework\TestCase;
25
29class ClientIdTest extends TestCase
30{
32 private Data\Factory $f;
33
37 protected function setUp(): void
38 {
39 $this->f = new Data\Factory();
40 }
41
45 public static function clientIdProvider(): array
46 {
47 return [
48 'single letter' => ['c'],
49 'multiple letters' => ['client'],
50 'single uppercase letter' => ['C'],
51 'multiple uppercase letters' => ['CLIENT'],
52 'single digit' => ['1'],
53 'multiple digits' => ['12'],
54 'letters + underscores' => ['client_with_underscore'],
55 'letters + underscores + digits' => ['client_with_12345'],
56 'letters + hyphens' => ['client-with-hyphen'],
57 'dots + sharps' => ['.#'] // looks weird, but is considered valid
58 ];
59 }
60
64 public static function invalidClientIdProvider(): array
65 {
66 return [
67 'path traversal' => ['../../../../some/obscure/path'],
68 'space in between' => ['my client'],
69 'wrapped in spaces' => [' myclient '],
70 'umlaut' => ['clüent'],
71 ];
72 }
73
74 #[\PHPUnit\Framework\Attributes\DataProvider('clientIdProvider')]
75 public function testValidArguments(string $value): void
76 {
77 $clientId = $this->f->clientId($value);
78 $this->assertEquals($value, $clientId->toString());
79 }
80
81 #[\PHPUnit\Framework\Attributes\DataProvider('invalidClientIdProvider')]
82 public function testInvalidArguments(string $value): void
83 {
84 try {
85 $clientId = $this->f->clientId($value);
86 $this->fail('This should not happen');
87 } catch (InvalidArgumentException $e) {
88 $this->assertTrue(true);
89 }
90 }
91
93 {
94 $this->expectException(InvalidArgumentException::class);
95
96 $this->f->clientId('');
97 }
98}
Data Factory $f
static clientIdProvider()
static invalidClientIdProvider()
testClientIdCannotBeCreatedByAnEmptyString()
testInvalidArguments(string $value)
testValidArguments(string $value)
$clientId
Definition: ltiregend.php:26