/** * testPathbuilding * * @return void */ public function testPathbuilding() { $builder = new BasePathBuilder(); $config = $builder->config(); $result = $builder->filename($this->entity); $this->assertEquals($result, 'filestorage1.png'); $result = $builder->path($this->entity); $this->assertEquals($result, '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS); $result = $builder->fullPath($this->entity); $this->assertEquals($result, '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS . 'filestorage1.png'); $builder->config('pathPrefix', 'files'); $result = $builder->path($this->entity); $this->assertEquals($result, 'files' . DS . '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS); $result = $builder->path($this->entity, ['pathPrefix' => 'images']); $this->assertEquals($result, 'images' . DS . '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS); $builder->config('pathPrefix', 'files'); $result = $builder->filename($this->entity); $this->assertEquals($result, 'filestorage1.png'); $builder->config('preserveFilename', true); $result = $builder->filename($this->entity); $this->assertEquals($result, 'cake.icon.png'); $builder->config($config); $builder->config('pathSuffix', 'files'); $result = $builder->path($this->entity); $this->assertEquals($result, '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS . 'files' . DS); $builder->config($config); $builder->config('pathPrefix', 'files'); $result = $builder->path($this->entity); $this->assertEquals($result, 'files' . DS . '14' . DS . '83' . DS . '23' . DS . 'filestorage1' . DS); $builder->config($config); $result = $builder->url($this->entity); $expected = '14/83/23/filestorage1/filestorage1.png'; $this->assertEquals($result, $expected); }
/** * Builds the URL under which the file is accessible. * * This is for example important for S3 and Dropbox but also the Local adapter * if you symlink a folder to your webroot and allow direct access to a file. * * @param \Cake\Datasource\EntityInterface $entity * @param array $options * @return string */ public function url(EntityInterface $entity, array $options = []) { $bucket = $this->_getBucket($entity->adapter); $pathPrefix = $this->ensureSlash($this->_buildCloudUrl($bucket), 'after'); $path = parent::path($entity); $path = str_replace('\\', '/', $path); return $pathPrefix . $path . $this->filename($entity, $options); }