ILIAS  release_8 Revision v8.24
AccessTokenTest.php
Go to the documentation of this file.
1<?php
2
20
25
30require_once __DIR__ . '/../AbstractBaseTest.php';
31
33{
34 private const TEST_SVG = 'test.svg';
35 private const INSIDE = __DIR__ . '/files/inside/';
36 private const OUTSIDE = __DIR__ . '/files/outside/';
37 private const INSIDE_FILE = self::INSIDE . self::TEST_SVG;
38 private const OUTSIDE_FILE = self::OUTSIDE . self::TEST_SVG;
39
40 public function testMemoryStream(): void
41 {
42 $tof = new TokenFactory(__DIR__);
43
44 $file_stream = Streams::ofString('test');
45 $token = $tof->lease($file_stream);
46
47 $this->assertFalse($token->hasStreamableStream());
48 $this->assertTrue($token->hasInMemoryStream());
49
50 $token_stream = $token->resolveStream();
51
52 $this->assertFalse($token->hasStreamableStream());
53
54 $this->assertTrue($token_stream->isReadable());
55 $this->assertFalse($token_stream->isWritable());
56 $this->assertEquals('application/x-empty', $token_stream->getMimeType());
57 }
58
59 public function testRealStream(): void
60 {
61 $tof = new TokenFactory(__DIR__);
62
63 $file_stream = Streams::ofResource(fopen(self::INSIDE_FILE, 'rb'));
64
65 $token = $tof->lease($file_stream);
66 $this->assertFalse($token->hasStreamableStream());
67 $this->assertFalse($token->hasInMemoryStream());
68
69 $token_stream = $token->resolveStream();
70
71 $this->assertTrue($token->hasStreamableStream());
72 $this->assertFalse($token->hasInMemoryStream());
73
74 $this->assertTrue($token_stream->isReadable());
75 $this->assertFalse($token_stream->isWritable());
76 $this->assertEquals('image/svg+xml', $token_stream->getMimeType());
77
78 $token2 = $tof->lease($file_stream, true);
79 $this->assertTrue($token->hasStreamableStream());
80 $this->assertFalse($token->hasInMemoryStream());
81 }
82
83
84 public function testStreamAccessInfoWrongDirectory(): void
85 {
86 $this->expectException(\InvalidArgumentException::class);
87 $sif = new TokenFactory('/loremipsum/');
88 $sif->check('loremipsum');
89 }
90
92 {
93 $tof = new TokenFactory(self::INSIDE);
94 $file_stream_outside = Streams::ofResource(fopen(self::OUTSIDE_FILE, 'rb'));
95 $file_stream_inside = Streams::ofResource(fopen(self::INSIDE_FILE, 'rb'));
96 $this->assertInstanceOf(Token::class, $tof->lease($file_stream_inside));
97 $this->expectException(\InvalidArgumentException::class);
98 $tof->lease($file_stream_outside);
99 }
100}
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:65
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$token
Definition: xapitoken.php:70