getProjectDir()); self::$projectDir = str_replace('\\', '/', self::$projectDir_orig); self::$media_path = self::$projectDir.'/public/media'; self::$footprint_path = self::$projectDir.'/public/img/footprints'; } public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); //Get an service instance. self::bootKernel(); self::$service = self::$container->get(AttachmentPathResolver::class); } public function testParameterToAbsolutePath(): void { //If null is passed, null must be returned $this->assertNull(self::$service->parameterToAbsolutePath(null)); //Absolute path should be returned like they are (we use projectDir here, because we know that this dir exists) $this->assertSame(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir)); //Relative pathes should be resolved $this->assertSame(self::$projectDir_orig.DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('src')); $this->assertSame(self::$projectDir_orig.DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('./src')); //Invalid pathes should return null $this->assertNull(self::$service->parameterToAbsolutePath('/this/path/does/not/exist')); $this->assertNull(self::$service->parameterToAbsolutePath('/./this/one/too')); } public function placeholderDataProvider() { return [ ['%FOOTPRINTS%/test/test.jpg', self::$footprint_path.'/test/test.jpg'], ['%FOOTPRINTS%/test/', self::$footprint_path.'/test/'], ['%MEDIA%/test', self::$media_path.'/test'], ['%MEDIA%', self::$media_path], ['%FOOTPRINTS%', self::$footprint_path], //Footprints 3D are disabled ['%FOOTPRINTS_3D%', null], //Check that invalid pathes return null ['/no/placeholder', null], ['%INVALID_PLACEHOLDER%', null], ['%FOOTPRINTS/test/', null], //Malformed placeholder ['/wrong/%FOOTRPINTS%/', null], //Placeholder not at beginning ['%FOOTPRINTS%/%MEDIA%', null], //No more than one placholder ['%FOOTPRINTS%/%FOOTPRINTS%', null], ['%FOOTPRINTS%/../../etc/passwd', null], ['%FOOTPRINTS%/0\..\test', null], ]; } public function realPathDataProvider() { return [ [self::$media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'], [self::$media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true], [self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'], [self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true], //Every kind of absolute path, that is not based with our placeholder dirs must be invald ['/etc/passwd', null], ['C:\\not\\existing.txt', null], //More then one placeholder is not allowed [self::$footprint_path.'/test/'.self::$footprint_path, null], //Path must begin with path ['/not/root'.self::$footprint_path, null], ]; } /** * @dataProvider placeholderDataProvider */ public function testPlaceholderToRealPath($param, $expected): void { $this->assertSame($expected, self::$service->placeholderToRealPath($param)); } /** * @dataProvider realPathDataProvider */ public function testRealPathToPlaceholder($param, $expected, $old_method = false): void { $this->assertSame($expected, self::$service->realPathToPlaceholder($param, $old_method)); } }