diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 52db2c36..8b2d250d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,10 +9,10 @@ on: jobs: testsuite: name: all tests - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: matrix: - php: ['8.0', '8.1', '8.2'] + php: ['8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 @@ -31,3 +31,6 @@ jobs: - name: Unit tests run: mkdir -p .Build/Web/typo3conf/ && rm -rf .Build/Web/typo3conf/ext && ln -sfn ../../../../ .Build/Web/typo3conf/ext && Build/Scripts/runTests.sh -p ${{ matrix.php }} -s unit + + - name: Functional tests + run: mkdir -p .Build/Web/typo3conf/ && rm -rf .Build/Web/typo3conf/ext && ln -sfn ../../../../ .Build/Web/typo3conf/ext && Build/Scripts/runTests.sh -p ${{ matrix.php }} -d sqlite -s functional diff --git a/Build/FunctionalTests.xml b/Build/FunctionalTests.xml new file mode 100644 index 00000000..0a2f44a8 --- /dev/null +++ b/Build/FunctionalTests.xml @@ -0,0 +1,13 @@ + + + + + ../Tests/Functional/ + + + + + + + + diff --git a/Build/FunctionalTestsBootstrap.php b/Build/FunctionalTestsBootstrap.php new file mode 100644 index 00000000..fbb94672 --- /dev/null +++ b/Build/FunctionalTestsBootstrap.php @@ -0,0 +1,30 @@ +defineOriginalRootPath(); + $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests'); + $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient'); +})(); diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 4cebf008..aa1b9a88 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -5,15 +5,15 @@ # # Function to write a .env file in Build/testing-docker/local -# This is read by docker-compose and vars defined here are -# used in Build/testing-docker/local/docker-compose.yml +# This is read by docker compose and vars defined here are +# used in Build/testing-docker/local/docker compose.yml setUpDockerComposeDotEnv() { # Delete possibly existing local .env file if exists [ -e .env ] && rm .env - # Set up a new .env file for docker-compose + # Set up a new .env file for docker compose echo "COMPOSE_PROJECT_NAME=local" >> .env # To prevent access rights of files created by the testing, the docker image later - # runs with the same user that is currently executing the script. docker-compose can't + # runs with the same user that is currently executing the script. docker compose can't # use $UID directly itself since it is a shell variable and not an env variable, so # we have to set it explicitly here. echo "HOST_UID=`id -u`" >> .env @@ -103,18 +103,12 @@ Examples: ./Build/Scripts/runTests.sh -p 7.3 EOF -# Test if docker-compose exists, else exit out with error -if ! type "docker-compose" > /dev/null; then - echo "This script relies on docker and docker-compose. Please install" >&2 - exit 1 -fi - # Go to the directory this script is located, so everything else is relative # to this dir, no matter from where this script is called. THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" cd "$THIS_SCRIPT_DIR" || exit 1 -# Go to directory that contains the local docker-compose.yml file +# Go to directory that contains the local docker compose.yml file cd ../testing-docker || exit 1 # Option defaults @@ -200,41 +194,41 @@ fi case ${TEST_SUITE} in composerInstall) setUpDockerComposeDotEnv - docker-compose run composer_install + docker compose run composer_install SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; composerInstallMax) setUpDockerComposeDotEnv - docker-compose run composer_install_max + docker compose run composer_install_max SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; composerInstallMin) setUpDockerComposeDotEnv - docker-compose run composer_install_min + docker compose run composer_install_min SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; composerValidate) setUpDockerComposeDotEnv - docker-compose run composer_validate + docker compose run composer_validate SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; functional) setUpDockerComposeDotEnv case ${DBMS} in mariadb) - docker-compose run functional_mariadb10 + docker compose run functional_mariadb10 SUITE_EXIT_CODE=$? ;; mssql) - docker-compose run functional_mssql2019latest + docker compose run functional_mssql2019latest SUITE_EXIT_CODE=$? ;; postgres) - docker-compose run functional_postgres10 + docker compose run functional_postgres10 SUITE_EXIT_CODE=$? ;; sqlite) @@ -243,7 +237,9 @@ case ${TEST_SUITE} in # root if docker creates it. Thank you, docker. We create the path beforehand # to avoid permission issues. mkdir -p ${ROOT_DIR}/.Build/Web/typo3temp/var/tests/functional-sqlite-dbs/ - docker-compose run functional_sqlite + rm -rf ${ROOT_DIR}/.Build/minio-data || true + cp -a ${ROOT_DIR}/Build/testing-docker/minio-data ${ROOT_DIR}/.Build/minio-data + docker compose run --rm functional_sqlite SUITE_EXIT_CODE=$? ;; *) @@ -252,19 +248,19 @@ case ${TEST_SUITE} in echo "${HELP}" >&2 exit 1 esac - docker-compose down + docker compose down ;; lint) setUpDockerComposeDotEnv - docker-compose run lint + docker compose run lint SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; unit) setUpDockerComposeDotEnv - docker-compose run unit + docker compose run unit SUITE_EXIT_CODE=$? - docker-compose down + docker compose down ;; update) # pull typo3/core-testing-*:latest versions of those ones that exist locally @@ -279,4 +275,4 @@ case ${TEST_SUITE} in exit 1 esac -exit $SUITE_EXIT_CODE \ No newline at end of file +exit $SUITE_EXIT_CODE diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml index cb2ca7d6..efb30efc 100644 --- a/Build/testing-docker/docker-compose.yml +++ b/Build/testing-docker/docker-compose.yml @@ -22,6 +22,13 @@ services: tmpfs: - /var/lib/postgresql/data:rw,noexec,nosuid + minio: + image: minio/minio + user: ${HOST_UID} + command: server /minio-data + volumes: + - ../../.Build/minio-data:/minio-data + composer_install: image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest user: ${HOST_UID} @@ -139,13 +146,13 @@ services: echo Database is up; php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ + export XDEBUG_MODE=\"off\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ + export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` + export XDEBUG_MODE=\"debug,develop\" + export XDEBUG_TRIGGER=\"foo\" + export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; fi " @@ -182,13 +189,13 @@ services: echo Database is up; php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ + export XDEBUG_MODE=\"off\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE}; else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ + export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` + export XDEBUG_MODE=\"debug,develop\" + export XDEBUG_TRIGGER=\"foo\" + export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-mssql ${TEST_FILE}; fi " @@ -222,13 +229,13 @@ services: echo Database is up; php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ + export XDEBUG_MODE=\"off\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE}; else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ + export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` + export XDEBUG_MODE=\"debug,develop\" + export XDEBUG_TRIGGER=\"foo\" + export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-postgres ${TEST_FILE}; fi " @@ -236,6 +243,8 @@ services: functional_sqlite: image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest user: ${HOST_UID} + links: + - minio volumes: - ${ROOT_DIR}:${ROOT_DIR} - ${HOST_HOME}:${HOST_HOME} @@ -253,13 +262,13 @@ services: fi php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ + export XDEBUG_MODE=\"off\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE}; else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ + export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` + export XDEBUG_MODE=\"debug,develop\" + export XDEBUG_TRIGGER=\"foo\" + export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} --exclude-group not-sqlite ${TEST_FILE}; fi " @@ -297,13 +306,13 @@ services: fi php -v | grep '^PHP' if [ ${PHP_XDEBUG_ON} -eq 0 ]; then - XDEBUG_MODE=\"off\" \ + export XDEBUG_MODE=\"off\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; else - DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` - XDEBUG_MODE=\"debug,develop\" \ - XDEBUG_TRIGGER=\"foo\" \ - XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ + export DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` + export XDEBUG_MODE=\"debug,develop\" + export XDEBUG_TRIGGER=\"foo\" + export XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" bin/phpunit -c Web/typo3conf/ext/aus_driver_amazon_s3/Build/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; fi - " \ No newline at end of file + " diff --git a/Build/testing-docker/minio-data/.minio.sys/buckets/.heal/mrf/list.bin b/Build/testing-docker/minio-data/.minio.sys/buckets/.heal/mrf/list.bin new file mode 100644 index 00000000..a3568729 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/buckets/.heal/mrf/list.bin differ diff --git a/Build/testing-docker/minio-data/.minio.sys/buckets/test-bucket/.metadata.bin/xl.meta b/Build/testing-docker/minio-data/.minio.sys/buckets/test-bucket/.metadata.bin/xl.meta new file mode 100644 index 00000000..46264b97 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/buckets/test-bucket/.metadata.bin/xl.meta differ diff --git a/Build/testing-docker/minio-data/.minio.sys/config/config.json/xl.meta b/Build/testing-docker/minio-data/.minio.sys/config/config.json/xl.meta new file mode 100644 index 00000000..c3b0bda1 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/config/config.json/xl.meta differ diff --git a/Build/testing-docker/minio-data/.minio.sys/config/iam/format.json/xl.meta b/Build/testing-docker/minio-data/.minio.sys/config/iam/format.json/xl.meta new file mode 100644 index 00000000..b91aa4c1 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/config/iam/format.json/xl.meta differ diff --git a/Build/testing-docker/minio-data/.minio.sys/config/iam/policydb/users/test-key.json/xl.meta b/Build/testing-docker/minio-data/.minio.sys/config/iam/policydb/users/test-key.json/xl.meta new file mode 100644 index 00000000..160395b2 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/config/iam/policydb/users/test-key.json/xl.meta differ diff --git a/Build/testing-docker/minio-data/.minio.sys/config/iam/users/test-key/identity.json/xl.meta b/Build/testing-docker/minio-data/.minio.sys/config/iam/users/test-key/identity.json/xl.meta new file mode 100644 index 00000000..e774c48d Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/config/iam/users/test-key/identity.json/xl.meta differ diff --git a/Build/testing-docker/minio-data/.minio.sys/format.json b/Build/testing-docker/minio-data/.minio.sys/format.json new file mode 100644 index 00000000..61f904be --- /dev/null +++ b/Build/testing-docker/minio-data/.minio.sys/format.json @@ -0,0 +1 @@ +{"version":"1","format":"xl-single","id":"c47cf73c-fb20-444e-bdab-048ef7dabead","xl":{"version":"3","this":"e985e316-adcb-48e4-85e5-702c21c608b7","sets":[["e985e316-adcb-48e4-85e5-702c21c608b7"]],"distributionAlgo":"SIPMOD+PARITY"}} \ No newline at end of file diff --git a/Build/testing-docker/minio-data/.minio.sys/pool.bin/xl.meta b/Build/testing-docker/minio-data/.minio.sys/pool.bin/xl.meta new file mode 100644 index 00000000..baa7ef40 Binary files /dev/null and b/Build/testing-docker/minio-data/.minio.sys/pool.bin/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/23.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/23.txt/xl.meta new file mode 100644 index 00000000..e7b2e487 Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/23.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/folder1/1.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/folder1/1.txt/xl.meta new file mode 100644 index 00000000..5dcade14 Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/folder1/1.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/folder1/2.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/folder1/2.txt/xl.meta new file mode 100644 index 00000000..d53b6367 Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/folder1/2.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/folder1/subfolder11/11.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/folder1/subfolder11/11.txt/xl.meta new file mode 100644 index 00000000..038d3a4b Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/folder1/subfolder11/11.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/folder1/subfolder12/12.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/folder1/subfolder12/12.txt/xl.meta new file mode 100644 index 00000000..720d0263 Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/folder1/subfolder12/12.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/folder2/2.txt/xl.meta b/Build/testing-docker/minio-data/test-bucket/folder2/2.txt/xl.meta new file mode 100644 index 00000000..b56364f4 Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/folder2/2.txt/xl.meta differ diff --git a/Build/testing-docker/minio-data/test-bucket/images/bytes-1009.png/xl.meta b/Build/testing-docker/minio-data/test-bucket/images/bytes-1009.png/xl.meta new file mode 100644 index 00000000..2e80145c Binary files /dev/null and b/Build/testing-docker/minio-data/test-bucket/images/bytes-1009.png/xl.meta differ diff --git a/Build/testing-docker/prepare-minio-data.sh b/Build/testing-docker/prepare-minio-data.sh new file mode 100755 index 00000000..2b93e965 --- /dev/null +++ b/Build/testing-docker/prepare-minio-data.sh @@ -0,0 +1,27 @@ +#!/bin/sh +#prepare the minio-data directory that is being used as test basis +set -ex + +which mc >> /dev/null || (echo 'Minio client executable not found'; exit 1) + +rm -r minio-data || true +rm -r ../../.Build/minio-data || true +mkdir ../../.Build/minio-data + +docker stop minio-setup || true +docker-compose run -d --rm --name minio-setup -p 9000:9000 minio +# minio needs some time to start up +sleep 5 + +mc alias remove typo3s3test || true +mc alias set typo3s3test http://127.0.0.1:9000 minioadmin minioadmin +mc mb typo3s3test/test-bucket/ +mc anonymous set download typo3s3test/test-bucket/ +mc admin user add typo3s3test test-key test-secretkey +mc admin policy attach typo3s3test readwrite --user test-key + +mc cp --recursive ../../Tests/Functional/Bucketfiles/* typo3s3test/test-bucket/ + +docker stop minio-setup +cp -a ../../.Build/minio-data . +rm -r minio-data/.minio.sys/tmp/.trash/* diff --git a/Tests/Functional/Bucketfiles/23.txt b/Tests/Functional/Bucketfiles/23.txt new file mode 100644 index 00000000..d81cc071 --- /dev/null +++ b/Tests/Functional/Bucketfiles/23.txt @@ -0,0 +1 @@ +42 diff --git a/Tests/Functional/Bucketfiles/folder1/1.txt b/Tests/Functional/Bucketfiles/folder1/1.txt new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/Tests/Functional/Bucketfiles/folder1/1.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/Functional/Bucketfiles/folder1/2.txt b/Tests/Functional/Bucketfiles/folder1/2.txt new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/Tests/Functional/Bucketfiles/folder1/2.txt @@ -0,0 +1 @@ +2 diff --git a/Tests/Functional/Bucketfiles/folder1/subfolder11/11.txt b/Tests/Functional/Bucketfiles/folder1/subfolder11/11.txt new file mode 100644 index 00000000..b4de3947 --- /dev/null +++ b/Tests/Functional/Bucketfiles/folder1/subfolder11/11.txt @@ -0,0 +1 @@ +11 diff --git a/Tests/Functional/Bucketfiles/folder1/subfolder12/12.txt b/Tests/Functional/Bucketfiles/folder1/subfolder12/12.txt new file mode 100644 index 00000000..48082f72 --- /dev/null +++ b/Tests/Functional/Bucketfiles/folder1/subfolder12/12.txt @@ -0,0 +1 @@ +12 diff --git a/Tests/Functional/Bucketfiles/folder2/2.txt b/Tests/Functional/Bucketfiles/folder2/2.txt new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/Tests/Functional/Bucketfiles/folder2/2.txt @@ -0,0 +1 @@ +2 diff --git a/Tests/Functional/Bucketfiles/images/bytes-1009.png b/Tests/Functional/Bucketfiles/images/bytes-1009.png new file mode 100644 index 00000000..898e92e7 Binary files /dev/null and b/Tests/Functional/Bucketfiles/images/bytes-1009.png differ diff --git a/Tests/Functional/Driver/AmazonS3DriverTest.php b/Tests/Functional/Driver/AmazonS3DriverTest.php new file mode 100644 index 00000000..68b12d5e --- /dev/null +++ b/Tests/Functional/Driver/AmazonS3DriverTest.php @@ -0,0 +1,284 @@ + 'test-bucket', + 'region' => 'eu-central-1', + 'customHost' => 'http://minio:9000', + 'pathStyleEndpoint' => 1, + 'key' => 'test-key', + 'secretKey' => 'test-secretkey', + 'publicBaseUrl' => 'minio', + 'baseFolder' => '', + 'cacheHeaderDuration' => 0, + 'protocol' => 'http://', + 'signature' => 0, + 'caseSensitive' => 1, + ]; + + public function setUp(): void + { + parent::setUp(); + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][AmazonS3Driver::EXTENSION_KEY] = [ + 'dnsPrefetch' => '1', + 'doNotLoadAmazonLib' => '0', + 'enablePermissionsCheck' => '0', + ]; + + $cacheManager = GeneralUtility::makeInstance(CacheManager::class); + $cacheManager->setCacheConfigurations([ + 'ausdriveramazons3_metainfocache' => [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend::class, + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + ], + 'ausdriveramazons3_requestcache' => [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend::class, + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + ] + ]); + $this->driver = new AmazonS3Driver( + $this->testConfiguration, + null, + GeneralUtility::makeInstance(NoopEventDispatcher::class) + ); + $this->driver->setStorageUid(42); + $this->driver->initialize(); + } + + public function testDeleteFile() + { + $localPath = __DIR__ . '/tmp.txt'; + file_put_contents($localPath, '42'); + $this->assertTrue(file_exists($localPath)); + $this->assertFalse($this->driver->fileExists('tmp-uploaded.txt')); + + $this->assertEquals( + 'tmp-uploaded.txt', + $this->driver->addFile( + $localPath, + $this->driver->getRootLevelFolder(), + 'tmp-uploaded.txt' + ) + ); + $this->assertFalse(file_exists($localPath)); + + $this->assertTrue($this->driver->deleteFile('tmp-uploaded.txt')); + $this->assertFalse($this->driver->fileExists('tmp-uploaded.txt')); + } + + public function testDeleteFolder() + { + $this->assertFalse($this->driver->folderExists('tmp-dir')); + + $this->assertEquals('/tmp-dir/', $this->driver->createFolder('tmp-dir')); + $this->assertTrue($this->driver->folderExists('tmp-dir')); + + $this->assertTrue($this->driver->deleteFolder('tmp-dir/')); + $this->assertFalse($this->driver->folderExists('tmp-dir')); + + $this->markTestSkipped('deleteFolder("tmp-dir/") fails currently'); + } + + public function testFileExists() + { + $this->assertFalse($this->driver->fileExists('doesnotexist.txt')); + $this->assertTrue($this->driver->fileExists('23.txt')); + $this->assertTrue($this->driver->fileExists('images/bytes-1009.png')); + } + + public function testFolderExists() + { + $this->assertTrue( + $this->driver->folderExists($this->driver->getDefaultFolder()) + ); + + $this->assertFalse($this->driver->folderExists('doesnotexist')); + $this->assertFalse($this->driver->folderExists('doesnotexist/')); + + $this->assertTrue($this->driver->folderExists('images')); + $this->assertTrue($this->driver->folderExists('images/')); + } + + public function testFolderExistsInFolder() + { + $this->markTestSkipped('Currently broken: leading slash must be removed'); + $this->assertTrue( + $this->driver->folderExistsInFolder( + 'images', + $this->driver->getDefaultFolder() + ) + ); + } + + public function testGetFileContents() + { + $this->assertEquals("42\n", $this->driver->getFileContents('23.txt')); + } + + public function testGetPublicUrl() + { + $this->assertEquals( + 'http://minio/file.txt', + $this->driver->getPublicUrl('file.txt') + ); + } + + public function testGetFilesInFolderRoot() + { + $this->assertEquals( + [ + '23.txt' => '23.txt', + ], + $this->driver->getFilesInFolder($this->driver->getDefaultFolder()) + ); + } + + public function testGetFilesInFolder() + { + $this->assertEquals( + [ + 'images/bytes-1009.png' => 'images/bytes-1009.png', + ], + $this->driver->getFilesInFolder('images/') + ); + } + + public function testGetFileInfoByIdentifierAllProperties() + { + $info = $this->driver->getFileInfoByIdentifier('images/bytes-1009.png'); + $this->assertEquals('bytes-1009.png', $info['name']); + $this->assertEquals('images/bytes-1009.png', $info['identifier']); + $this->assertEquals('8b6249ec878b12d3f014e616336fefaac0b4d0dd', $info['identifier_hash']); + $this->assertEquals('c1a406ab82b5588738d1587da2761746ec584a6c', $info['folder_hash']); + $this->assertEquals('png', $info['extension']); + $this->assertEquals(42, $info['storage']); + $this->assertEquals('image/png', $info['mimetype']); + $this->assertEquals(1009, $info['size']); + } + + public function testGetFileInfoByIdentifierOnlyMimetype() + { + $info = $this->driver->getFileInfoByIdentifier('images/bytes-1009.png', ['mimetype']); + $this->assertEquals('image/png', $info['mimetype']); + } + + public function testGetFoldersInFolderRoot() + { + $this->markTestSkipped('need sys_file_storage for this'); + $this->assertEquals( + [], + $this->driver->getFoldersInFolder($this->driver->getRootLevelFolder()) + ); + } + + public function testIsFolderEmptySlash() + { + $this->markTestSkipped('Currently broken'); + $this->assertCount(1, $this->driver->getFilesInFolder('images/')); + $this->assertFalse($this->driver->isFolderEmpty('images/')); + } + + public function testIsFolderEmptyNoSlash() + { + $this->markTestSkipped('Slash is not added automatically'); + $this->assertCount(1, $this->driver->getFilesInFolder('images')); + $this->assertFalse($this->driver->isFolderEmpty('images')); + } + + public function testCopyFileWithinStorage() + { + $this->assertFalse($this->driver->fileExists('copytarget.txt')); + $this->assertEquals( + 'copytarget.txt', + $this->driver->copyFileWithinStorage('23.txt', '', 'copytarget.txt') + ); + $this->assertTrue($this->driver->fileExists('copytarget.txt')); + + $this->assertTrue($this->driver->deleteFile('copytarget.txt')); + } + + public function testMoveFileWithinStorageRoot() + { + $this->assertTrue($this->driver->fileExists('23.txt')); + $this->assertFalse($this->driver->fileExists('movetarget.txt')); + $this->assertEquals( + 'movetarget.txt', + $this->driver->moveFileWithinStorage('23.txt', '', 'movetarget.txt') + ); + $this->assertTrue($this->driver->fileExists('movetarget.txt')); + $this->assertFalse($this->driver->fileExists('23.txt')); + + $this->assertEquals( + '23.txt', + $this->driver->moveFileWithinStorage('movetarget.txt', '', '23.txt') + ); + } + + public function testMoveFileWithinStorageSubfolder() + { + $this->assertTrue($this->driver->fileExists('23.txt')); + $this->assertFalse($this->driver->fileExists('images/movetarget.txt')); + $this->assertEquals( + 'images/movetarget.txt', + $this->driver->moveFileWithinStorage('23.txt', 'images/', 'movetarget.txt') + ); + $this->assertTrue($this->driver->fileExists('images/movetarget.txt')); + $this->assertFalse($this->driver->fileExists('23.txt')); + + $this->assertEquals( + '23.txt', + $this->driver->moveFileWithinStorage('images/movetarget.txt', '', '23.txt') + ); + } + + public function testMoveFileWithinStorageSubfolderNoSlash() + { + $this->markTestSkipped('moving to "images" folder with slash fails currently'); + + $this->assertTrue($this->driver->fileExists('23.txt')); + $this->assertFalse($this->driver->fileExists('images/movetarget.txt')); + $this->assertEquals( + 'images/movetarget.txt', + $this->driver->moveFileWithinStorage('23.txt', 'images', 'movetarget.txt') + ); + $this->assertTrue($this->driver->fileExists('images/movetarget.txt')); + $this->assertFalse($this->driver->fileExists('23.txt')); + + $this->assertEquals( + '23.txt', + $this->driver->moveFileWithinStorage('images/movetarget.txt', '', '23.txt') + ); + } + + public function testSetFileContents() + { + $this->assertEquals(5, $this->driver->setFileContents('write.txt', 'write')); + $this->assertEquals('write', $this->driver->getFileContents('write.txt')); + $this->assertTrue($this->driver->deleteFile('write.txt')); + } +} diff --git a/composer.json b/composer.json index 51f55cc3..5d510e7d 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require-dev": { "pluswerk/grumphp-config": "^5.0", - "typo3/testing-framework": "^7.0", + "typo3/testing-framework": "^8.0", "phpspec/prophecy": "dev-master", "phpspec/prophecy-phpunit": "dev-master", "saschaegerer/phpstan-typo3": "^1.8.9",