From 4983643fb3c60b74d3e0081d7093478c40053b48 Mon Sep 17 00:00:00 2001 From: Volodymyr Hadomskyi Date: Thu, 15 Aug 2024 21:56:39 +0200 Subject: [PATCH] Fix translation link ENG-17101 --- .github/workflows/e2e.yml | 2 +- e2e/Makefile | 66 +++++++++---------- src/elements/Translation.php | 11 ++++ tests/_bootstrap.php | 1 + .../job/GetJobCreateFormControllerCest.php | 4 +- .../job/GetJobEditFormControllerCest.php | 4 +- .../GetTranslationReviewControllerCest.php | 7 +- 7 files changed, 55 insertions(+), 40 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 7142070b..64991b28 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -31,7 +31,7 @@ jobs: "cypress/e2e/jobs/verified/success-path-single.cy.js", "cypress/e2e/jobs/instant/success-path-single.cy.js", ] - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set the value diff --git a/e2e/Makefile b/e2e/Makefile index 8ad18eb2..8d69de2e 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -16,8 +16,8 @@ composer-install: composer require --ignore-platform-reqs "lilt/craft-lilt-plugin":"^999.9.9" reset: cp composer-install - docker-compose exec -T app sh -c 'php craft db/restore happylager.sql' - docker-compose exec -T app sh -c 'php craft plugin/install craft-lilt-plugin' + docker compose exec -T app sh -c 'php craft db/restore happylager.sql' + docker compose exec -T app sh -c 'php craft plugin/install craft-lilt-plugin' install: clone @@ -28,23 +28,23 @@ install: clone composer require craftcms/cms:3.7.68 -W backup-db: - docker-compose exec -T app sh -c 'php craft db/backup' + docker compose exec -T app sh -c 'php craft db/backup' refresh: - docker-compose exec -T app sh -c 'rm -rf /app/vendor/lilt/craft-lilt-plugin' - docker-compose exec -T app sh -c 'composer require --ignore-platform-reqs "lilt/craft-lilt-plugin":"^999.9.9"' + docker compose exec -T app sh -c 'rm -rf /app/vendor/lilt/craft-lilt-plugin' + docker compose exec -T app sh -c 'composer require --ignore-platform-reqs "lilt/craft-lilt-plugin":"^999.9.9"' build: docker build -f happy-lager-main/Dockerfile happy-lager-main -t happy-lager down: - docker-compose down --remove-orphans -v + docker compose down --remove-orphans -v mup: #migrate app up - docker-compose exec -T app sh -c 'php craft migrate/up' + docker compose exec -T app sh -c 'php craft migrate/up' mdown: #migrate app down - docker-compose exec -T app sh -c 'php craft migrate/down' + docker compose exec -T app sh -c 'php craft migrate/down' cp: rm -rf happy-lager-main/plugin-src @@ -84,32 +84,32 @@ wait-service: @echo "Service is up and running or max retries reached!" up: clone down composer-install - docker-compose up --build -d - docker-compose ps - docker-compose exec -T app sh -c 'chmod -R 777 /app' - docker-compose exec -T app sh -c 'chown -R www-data:www-data /app' - docker-compose exec -T mysql sh -c 'while ! mysqladmin ping -h"mysql" --silent; do sleep 1; done' - docker-compose exec -T app sh -c 'php craft setup/security-key' - docker-compose exec -T app sh -c 'echo DB_DRIVER=mysql >> .env' - docker-compose exec -T app sh -c 'echo DB_SERVER=mysql >> .env' - docker-compose exec -T app sh -c 'echo DB_DATABASE=${DB_DATABASE} >> .env' - docker-compose exec -T app sh -c 'echo DB_USER=craft-lilt >> .env' - docker-compose exec -T app sh -c 'echo DB_PASSWORD=craft-lilt >> .env' - docker-compose exec -T app sh -c 'echo DB_SCHEMA=public >> .env' - docker-compose exec -T app sh -c 'echo DB_TABLE_PREFIX= >> .env' - docker-compose exec -T app sh -c 'echo CRAFT_LILT_PLUGIN_QUEUE_DELAY_IN_SECONDS=1 >> .env' - docker-compose exec -T app sh -c 'echo CRAFT_LILT_PLUGIN_QUEUE_MANAGER_WAIT_TIME_IN_SECONDS=86400 >> .env' - docker-compose exec -T app sh -c 'php craft db/restore happylager.sql' - docker-compose exec -T app sh -c 'php craft plugin/install craft-lilt-plugin' - docker-compose exec -T app sh -c 'php craft plugin/install neo' - docker-compose exec -T app sh -c 'php craft plugin/install super-table' - docker-compose exec -T app sh -c 'php craft project-config/rebuild' - docker-compose exec -T app sh -c 'php craft up' - docker-compose exec -T app sh -c 'php craft migrate/up' - docker-compose exec -T app sh -c 'nohup ./queue_listen.sh > queue.log 2>&1 &' - docker-compose exec -T app sh -c 'cat .env' + docker compose up --build -d + docker compose ps + docker compose exec -T app sh -c 'chmod -R 777 /app' + docker compose exec -T app sh -c 'chown -R www-data:www-data /app' + docker compose exec -T mysql sh -c 'while ! mysqladmin ping -h"mysql" --silent; do sleep 1; done' + docker compose exec -T app sh -c 'php craft setup/security-key' + docker compose exec -T app sh -c 'echo DB_DRIVER=mysql >> .env' + docker compose exec -T app sh -c 'echo DB_SERVER=mysql >> .env' + docker compose exec -T app sh -c 'echo DB_DATABASE=${DB_DATABASE} >> .env' + docker compose exec -T app sh -c 'echo DB_USER=craft-lilt >> .env' + docker compose exec -T app sh -c 'echo DB_PASSWORD=craft-lilt >> .env' + docker compose exec -T app sh -c 'echo DB_SCHEMA=public >> .env' + docker compose exec -T app sh -c 'echo DB_TABLE_PREFIX= >> .env' + docker compose exec -T app sh -c 'echo CRAFT_LILT_PLUGIN_QUEUE_DELAY_IN_SECONDS=1 >> .env' + docker compose exec -T app sh -c 'echo CRAFT_LILT_PLUGIN_QUEUE_MANAGER_WAIT_TIME_IN_SECONDS=86400 >> .env' + docker compose exec -T app sh -c 'php craft db/restore happylager.sql' + docker compose exec -T app sh -c 'php craft plugin/install craft-lilt-plugin' + docker compose exec -T app sh -c 'php craft plugin/install neo' + docker compose exec -T app sh -c 'php craft plugin/install super-table' + docker compose exec -T app sh -c 'php craft project-config/rebuild' + docker compose exec -T app sh -c 'php craft up' + docker compose exec -T app sh -c 'php craft migrate/up' + docker compose exec -T app sh -c 'nohup ./queue_listen.sh > queue.log 2>&1 &' + docker compose exec -T app sh -c 'cat .env' cli: - docker-compose exec app sh + docker compose exec app sh test: docker run -u root -t -v ${PWD}:/e2e -w /e2e --env CYPRESS_CACHE_FOLDER=${CYPRESS_CACHE_FOLDER} node:18.12.1 npm install diff --git a/src/elements/Translation.php b/src/elements/Translation.php index 89f2205e..6ede1a9a 100644 --- a/src/elements/Translation.php +++ b/src/elements/Translation.php @@ -19,6 +19,7 @@ use lilthq\craftliltplugin\elements\actions\JobEdit; use lilthq\craftliltplugin\elements\db\TranslationQuery; use lilthq\craftliltplugin\models\TranslationModelTrait; +use craft\elements\User; use lilthq\craftliltplugin\records\TranslationNotificationsRecord; use lilthq\craftliltplugin\records\TranslationRecord; @@ -128,6 +129,16 @@ public function getIsReviewed(): bool return $this->getIsPublished() || $this->status === TranslationRecord::STATUS_READY_TO_PUBLISH; } + public function getUrl(): ?string + { + return $this->getCpEditUrl(); + } + + public function canView(User $user): bool + { + return true; + } + public function getStatusHtml(): string { $label = self::statuses()[$this->status]['label'] ?? self::statuses()[$this->status]; diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index b604016c..186b9e39 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -17,6 +17,7 @@ define('TEST_SUPERTABLE_PLUGIN', false); define('TEST_LINKIT_PLUGIN', false); define('TEST_COLOUR_SWATCHES_PLUGIN', false); +define('PRIMARY_SITE_URL', 'test.craftcms.test:80'); $devMode = true; diff --git a/tests/integration/controllers/job/GetJobCreateFormControllerCest.php b/tests/integration/controllers/job/GetJobCreateFormControllerCest.php index 0f0596b8..c6cafc7d 100644 --- a/tests/integration/controllers/job/GetJobCreateFormControllerCest.php +++ b/tests/integration/controllers/job/GetJobCreateFormControllerCest.php @@ -266,11 +266,11 @@ private function getExpected(): array 'crumbs' => [ 0 => [ 'label' => 'Lilt Plugin', - 'url' => 'http://$PRIMARY_SITE_URL/index.php?p=admin/admin/craft-lilt-plugin&site=default', + 'url' => 'http://test.craftcms.test:80/index.php?p=admin/admin/craft-lilt-plugin&site=default', ], 1 => [ 'label' => 'Jobs', - 'url' => 'http://$PRIMARY_SITE_URL/index.php?p=admin/admin/craft-lilt-plugin/jobs&site=default', + 'url' => 'http://test.craftcms.test:80/index.php?p=admin/admin/craft-lilt-plugin/jobs&site=default', ], ], ], diff --git a/tests/integration/controllers/job/GetJobEditFormControllerCest.php b/tests/integration/controllers/job/GetJobEditFormControllerCest.php index 17f5db74..f1dd8385 100644 --- a/tests/integration/controllers/job/GetJobEditFormControllerCest.php +++ b/tests/integration/controllers/job/GetJobEditFormControllerCest.php @@ -331,11 +331,11 @@ private function getExpected(Job $job): array 'crumbs' => [ 0 => [ 'label' => 'Lilt Plugin', - 'url' => 'http://$PRIMARY_SITE_URL/index.php?p=admin/admin/craft-lilt-plugin&site=default', + 'url' => 'http://test.craftcms.test:80/index.php?p=admin/admin/craft-lilt-plugin&site=default', ], 1 => [ 'label' => 'Jobs', - 'url' => 'http://$PRIMARY_SITE_URL/index.php?p=admin/admin/craft-lilt-plugin/jobs&site=default', + 'url' => 'http://test.craftcms.test:80/index.php?p=admin/admin/craft-lilt-plugin/jobs&site=default', ], ], ], diff --git a/tests/integration/controllers/job/GetTranslationReviewControllerCest.php b/tests/integration/controllers/job/GetTranslationReviewControllerCest.php index 15fcec87..3c185321 100644 --- a/tests/integration/controllers/job/GetTranslationReviewControllerCest.php +++ b/tests/integration/controllers/job/GetTranslationReviewControllerCest.php @@ -53,6 +53,9 @@ private function getController(): GetTranslationReviewController */ public function testSuccess(IntegrationTester $I): void { + $urlManager = Craft::$app->urlManager; + $urlManager->setHostInfo('https://test.craftcms.test:80'); + $user = Craft::$app->getUsers()->getUserById(1); $I->amLoggedInAs($user); @@ -119,7 +122,7 @@ public function testSuccess(IntegrationTester $I): void if (method_exists(Assert::class, 'assertMatchesRegularExpression')) { Assert::assertMatchesRegularExpression( - "/^http:\/\/\\\$PRIMARY_SITE_URL\/index\.php\?p=blog\/first-entry-user-1&token=[0-9a-zA-Z\S]+$/", + "/^http:\/\/test\.craftcms\.test:80\/index\.php\?p=blog\/first-entry-user-1&token=[0-9a-zA-Z\S]+$/", $actual['variables']['originalUrl'] ); Assert::assertMatchesRegularExpression( @@ -128,7 +131,7 @@ public function testSuccess(IntegrationTester $I): void ); } else { Assert::assertRegExp( - "/^http:\/\/\\\$PRIMARY_SITE_URL\/index\.php\?p=blog\/first-entry-user-1&token=[0-9a-zA-Z\S]+$/", + "/^http:\/\/test\.craftcms\.test:80\/index\.php\?p=blog\/first-entry-user-1&token=[0-9a-zA-Z\S]+$/", $actual['variables']['originalUrl'] ); Assert::assertRegExp(