Bolt\Tests\Controller\Async\FilesystemManagerTest::testDuplicateFile PHP Method

testDuplicateFile() public method

Duplicating a file five times should create FILENAME_copy1-5.EXT. This should work for both regular filenames and dotfiles.
public testDuplicateFile ( )
    public function testDuplicateFile()
    {
        $filenames = ['__phpunit_test_file_delete_me.extension', '.__phpunit_test_dotfile_delete_me'];
        foreach ($filenames as $filename) {
            // Create the file
            $this->getService('filesystem')->put(self::FILESYSTEM . '://' . $filename, '');
            $extensionPos = strrpos($filename, '.') ?: strlen($filename);
            $fileBase = substr($filename, 0, $extensionPos) . '_copy';
            $fileExtension = substr($filename, $extensionPos);
            for ($i = 1; $i <= 5; $i++) {
                $destination = $fileBase . $i . $fileExtension;
                // The file shouldn't exist yet
                $this->assertFalse($this->getService('filesystem')->has(self::FILESYSTEM . '://' . $destination));
                $this->setRequest(Request::create('/async/file/duplicate', 'POST', ['namespace' => self::FILESYSTEM, 'filename' => $filename]));
                $response = $this->controller()->duplicateFile($this->getRequest());
                $this->assertInstanceOf(JsonResponse::class, $response);
                $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
                // The copy should now have been created
                $this->assertTrue($this->getService('filesystem')->has(self::FILESYSTEM . '://' . $destination));
            }
        }
    }