ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
ClientIdTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once 'vendor/composer/vendor/autoload.php';
22 
23 use ILIAS\Data;
25 
29 class 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 }
$clientId
Definition: ltiregend.php:25
static clientIdProvider()
testValidArguments(string $value)
Data Factory $f
static invalidClientIdProvider()
testInvalidArguments(string $value)
testClientIdCannotBeCreatedByAnEmptyString()