*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } protected function tearDown(): void { $this->clearImages(); parent::tearDown(); } /** * Writes a small file with the given leading bytes. * * @param string $head First bytes * @return string Path */ protected function makeAudio(string $head = "ID3\x03\x00\x00\x00\x00\x00\x00"): string { $path = tempnam(sys_get_temp_dir(), 'plen'); file_put_contents($path, $head . str_repeat("\x00", 2000)); $this->imageFiles[] = $path; return $path; } protected function upload(string $token, ?string $path, array $data = []): void { $this->_request['files'] = $path === null ? [] : [ 'audio' => new UploadedFile($path, (int)filesize($path), UPLOAD_ERR_OK, 'musik.mp3', 'audio/mpeg'), ]; try { $this->post("/admin/$token/audio", $data); } finally { $this->_request['files'] = []; } } public function testUploadServeReplaceAndRemove(): void { [$poll, $token] = $this->createPoll(); $this->upload($token, $this->makeAudio()); $this->assertRedirect(['_name' => 'admin', 'token' => $token, '#' => 'audio']); $first = (string)$this->pollsTable()->get($poll->id)->audio; $this->assertMatchesRegularExpression('/^[a-f0-9]{24}\.mp3$/', $first); $this->assertSame([$first], $this->storedImages($poll->id)); $this->get("/admin/$token"); $this->assertResponseOk(); $this->assertResponseContains('