Chris@0: assertEquals('/fake-dir', $this->getXdg()->getHomeDir()); Chris@0: } Chris@0: Chris@0: public function testGetFallbackHomeDir() Chris@0: { Chris@0: putenv('HOME='); Chris@0: putenv('HOMEDRIVE=C:'); Chris@0: putenv('HOMEPATH=fake-dir'); Chris@0: $this->assertEquals('C:/fake-dir', $this->getXdg()->getHomeDir()); Chris@0: } Chris@0: Chris@0: public function testXdgPutCache() Chris@0: { Chris@0: putenv('XDG_DATA_HOME=tmp/'); Chris@0: putenv('XDG_CONFIG_HOME=tmp/'); Chris@0: putenv('XDG_CACHE_HOME=tmp/'); Chris@0: $this->assertEquals('tmp/', $this->getXdg()->getHomeCacheDir()); Chris@0: } Chris@0: Chris@0: public function testXdgPutData() Chris@0: { Chris@0: putenv('XDG_DATA_HOME=tmp/'); Chris@0: $this->assertEquals('tmp/', $this->getXdg()->getHomeDataDir()); Chris@0: } Chris@0: Chris@0: public function testXdgPutConfig() Chris@0: { Chris@0: putenv('XDG_CONFIG_HOME=tmp/'); Chris@0: $this->assertEquals('tmp/', $this->getXdg()->getHomeConfigDir()); Chris@0: } Chris@0: Chris@0: public function testXdgDataDirsShouldIncludeHomeDataDir() Chris@0: { Chris@0: putenv('XDG_DATA_HOME=tmp/'); Chris@0: putenv('XDG_CONFIG_HOME=tmp/'); Chris@0: Chris@0: $this->assertArrayHasKey('tmp/', array_flip($this->getXdg()->getDataDirs())); Chris@0: } Chris@0: Chris@0: public function testXdgConfigDirsShouldIncludeHomeConfigDir() Chris@0: { Chris@0: putenv('XDG_CONFIG_HOME=tmp/'); Chris@0: Chris@0: $this->assertArrayHasKey('tmp/', array_flip($this->getXdg()->getConfigDirs())); Chris@0: } Chris@0: Chris@0: /** Chris@0: * If XDG_RUNTIME_DIR is set, it should be returned Chris@0: */ Chris@0: public function testGetRuntimeDir() Chris@0: { Chris@0: putenv('XDG_RUNTIME_DIR=/tmp/'); Chris@0: $runtimeDir = $this->getXdg()->getRuntimeDir(); Chris@0: Chris@0: $this->assertEquals(is_dir($runtimeDir), true); Chris@0: } Chris@0: Chris@0: /** Chris@0: * In strict mode, an exception should be shown if XDG_RUNTIME_DIR does not exist Chris@0: * Chris@0: * @expectedException \RuntimeException Chris@0: */ Chris@0: public function testGetRuntimeDirShouldThrowException() Chris@0: { Chris@0: putenv('XDG_RUNTIME_DIR='); Chris@0: $this->getXdg()->getRuntimeDir(true); Chris@0: } Chris@0: Chris@0: /** Chris@0: * In fallback mode a directory should be created Chris@0: */ Chris@0: public function testGetRuntimeDirShouldCreateDirectory() Chris@0: { Chris@0: putenv('XDG_RUNTIME_DIR='); Chris@0: $dir = $this->getXdg()->getRuntimeDir(false); Chris@0: $permission = decoct(fileperms($dir) & 0777); Chris@0: $this->assertEquals(700, $permission); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Ensure, that the fallback directories are created with correct permission Chris@0: */ Chris@0: public function testGetRuntimeShouldDeleteDirsWithWrongPermission() Chris@0: { Chris@0: $runtimeDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . XdgBaseDir\Xdg::RUNTIME_DIR_FALLBACK . getenv('USER'); Chris@0: Chris@0: rmdir($runtimeDir); Chris@0: mkdir($runtimeDir, 0764, true); Chris@0: Chris@0: // Permission should be wrong now Chris@0: $permission = decoct(fileperms($runtimeDir) & 0777); Chris@0: $this->assertEquals(764, $permission); Chris@0: Chris@0: putenv('XDG_RUNTIME_DIR='); Chris@0: $dir = $this->getXdg()->getRuntimeDir(false); Chris@0: Chris@0: // Permission should be fixed Chris@0: $permission = decoct(fileperms($dir) & 0777); Chris@0: $this->assertEquals(700, $permission); Chris@0: } Chris@0: }