of('p1') === null); check('taking down a project without a release says so', $releases->takeDown('p1') === false); $doc = ['id' => 'p1', 'name' => 'Game', 'revision' => 4, 'project' => ['id' => 'p1', 'assets' => [['id' => 'a']]]]; $first = $releases->publish($doc); check('publishing hands out a 128-bit token', ReleaseStore::isValidToken($first['token']), $first); check('the summary names the revision it copied', $first['revision'] === 4, $first); check('the project now has that release', $releases->of('p1') === $first, $releases->of('p1')); $loaded = $releases->load($first['token']); check( 'the token loads the copy, its name and its project', $loaded !== null && $loaded['project'] === $doc['project'] && $loaded['name'] === 'Game' && $loaded['projectId'] === 'p1', $loaded, ); check('the release file is not readable for the web server', (fileperms("{$dir}/{$first['token']}.json") & 0o007) === 0); check('nor is the file that says which link a project has', (fileperms("{$dir}/projects/p1.json") & 0o007) === 0); $changed = ['revision' => 7, 'project' => ['id' => 'p1', 'assets' => []]] + $doc; $second = $releases->publish($changed); check('publishing again keeps the link', $second['token'] === $first['token'], $second); check('and replaces the copy', $releases->load($first['token'])['project'] === $changed['project']); check('with the new revision', $second['revision'] === 7, $second); $other = $releases->publish(['id' => 'p2'] + $doc); check('another project gets another link', $other['token'] !== $first['token']); check('an unknown token loads nothing', $releases->load(str_repeat('0', 32)) === null); check('a token of the wrong shape loads nothing', $releases->load('../projects/p1') === null); check('a project id is not a token', $releases->load('p1') === null); check('taking down a release says so', $releases->takeDown('p1') === true); check('the link is dead afterwards', $releases->load($first['token']) === null); check('and the project has no release', $releases->of('p1') === null); check('the other project keeps its own', $releases->load($other['token']) !== null); $again = $releases->publish($doc); check('publishing after a take-down hands out a new link', $again['token'] !== $first['token'], $again); foreach (array_merge(glob("{$dir}/projects/*") ?: [], glob("{$dir}/*.json") ?: []) as $file) { unlink($file); } @rmdir("{$dir}/projects"); @rmdir($dir); echo $failed === 0 ? "ALL PASSED – {$passed} checks\n" : "{$failed} FAILED, {$passed} passed\n"; exit($failed === 0 ? 0 : 1);