ILIAS  release_7 Revision v7.30-3-g800a261c036
ClientIdTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'libs/composer/vendor/autoload.php';
5
6use ILIAS\Data;
7use PHPUnit\Framework\TestCase;
8
12class ClientIdTest extends TestCase
13{
15 private $f;
16
20 protected function setUp() : void
21 {
22 $this->f = new Data\Factory();
23 }
24
28 public function clientIdProvider() : array
29 {
30 return [
31 'single letter' => ['c'],
32 'multiple letters' => ['client'],
33 'single uppercase letter' => ['C'],
34 'multiple uppercase letters' => ['CLIENT'],
35 'single digit' => ['1'],
36 'multiple digits' => ['12'],
37 'letters + underscores' => ['client_with_underscore'],
38 'letters + underscores + digits' => ['client_with_12345'],
39 'letters + hyphens' => ['client-with-hyphen'],
40 'dots + sharps' => ['.#'] // looks weird, but is considered valid
41 ];
42 }
43
47 public function invalidClientIdProvider() : array
48 {
49 return [
50 'path traversal' => ['../../some/obscure/path'],
51 'space in between' => ['my client'],
52 'wrapped in spaces' => [' myclient '],
53 'umlaut' => ['clüent'],
54 ];
55 }
56
61 public function testValidArguments(string $value)
62 {
63 $clientId = $this->f->clientId($value);
64 $this->assertEquals($value, $clientId->toString());
65 }
66
71 public function testInvalidArguments(string $value)
72 {
73 try {
74 $clientId = $this->f->clientId($value);
75 $this->fail('This should not happen');
76 } catch (\InvalidArgumentException $e) {
77 $this->assertTrue(true);
78 }
79 }
80
82 {
83 $this->expectException(InvalidArgumentException::class);
84
85 $this->f->clientId('');
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
testClientIdCannotBeCreatedByAnEmptyString()
invalidClientIdProvider()
testInvalidArguments(string $value)
testValidArguments(string $value)
Builds data types.
Definition: Factory.php:20