Skip to content

Commit

Permalink
Make plugin ready for Laravel 6 update (#600)
Browse files Browse the repository at this point in the history
Make slug parameters optional in routes
  • Loading branch information
Ben Thomson authored Oct 2, 2020
1 parent d5a2401 commit f6e5450
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 27 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Tests

on:
push:
branches:
- master
pull_request:

jobs:
phpUnitTests:
runs-on: ubuntu-latest
name: Unit Tests / PHP ${{ matrix.phpVersions }}
strategy:
max-parallel: 6
matrix:
phpVersions: ['7.2', '7.3', '7.4']
fail-fast: false
env:
phpExtensions: mbstring, intl, gd, xml, sqlite
cacheKey: ext-cache-v1
octoberCmsRelease: develop
steps:
- name: Checkout changes
uses: actions/checkout@v2
with:
path: translate-plugin

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.phpVersions }}
extensions: ${{ env.phpExtensions }}
key: ${{ env.cacheKey }}

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Install PHP and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpVersions }}
extensions: ${{ env.phpExtensions }}
tools: composer
coverage: none

- name: Install October CMS
run: |
wget https://github.com/octobercms/october/archive/${{ env.octoberCmsRelease }}.zip
unzip ${{ env.octoberCmsRelease }}.zip
shopt -s dotglob
mv october-${{ env.octoberCmsRelease }}/* ./
shopt -u dotglob
cp config/cms.php config/testing/cms.php
mkdir -p plugins/rainlab
mv translate-plugin plugins/rainlab/translate
- name: Get Composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --no-suggest

- name: Run linting
run: ./vendor/bin/parallel-lint plugins/rainlab/translate

- name: Run unit tests
run: |
cd plugins/rainlab/translate
../../../vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
composer.lock
.DS_Store
.phpunit.result.cache
20 changes: 10 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../../tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../../tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Plugin Unit Test Suite">
Expand Down
15 changes: 7 additions & 8 deletions routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
/*
* Adds a custom route to check for the locale prefix.
*/
App::before(function($request) {

App::before(function ($request) {
if (Config::get('rainlab.translate::disableLocalePrefixRoutes', false)) {
return;
}
Expand All @@ -29,8 +28,8 @@
/*
* Register routes
*/
Route::group(['prefix' => $locale, 'middleware' => 'web'], function() {
Route::any('{slug}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?');
Route::group(['prefix' => $locale, 'middleware' => 'web'], function () {
Route::any('{slug?}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?');
});

Route::any($locale, 'Cms\Classes\CmsController@run')->middleware('web');
Expand All @@ -39,17 +38,17 @@
* Ensure Url::action() retains the localized URL
* by re-registering the route after the CMS.
*/
Event::listen('cms.route', function() use ($locale) {
Route::group(['prefix' => $locale, 'middleware' => 'web'], function() {
Route::any('{slug}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?');
Event::listen('cms.route', function () use ($locale) {
Route::group(['prefix' => $locale, 'middleware' => 'web'], function () {
Route::any('{slug?}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?');
});
});
});

/*
* Save any used messages to the contextual cache.
*/
App::after(function($request) {
App::after(function ($request) {
if (class_exists('RainLab\Translate\Models\Message')) {
Message::saveToCache();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/behaviors/TranslatableCmsObjectTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php namespace RainLab\Translate\Tests\Unit\Behaviors;

use File;
use PluginTestCase;
use October\Rain\Halcyon\Model;
use October\Rain\Filesystem\Filesystem;
use October\Rain\Halcyon\Datasource\FileDatasource;
use October\Rain\Halcyon\Datasource\Resolver;
use RainLab\Translate\Tests\Fixtures\Classes\Feature as FeatureModel;
use RainLab\Translate\Models\Locale as LocaleModel;
use PluginTestCase;

class TranslatableCmsObjectTest extends PluginTestCase
{
public $themePath;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -22,7 +22,7 @@ public function setUp()
$this->seedSampleSourceAndData();
}

public function tearDown()
public function tearDown(): void
{
$this->cleanUp();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/behaviors/TranslatableModelTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php namespace RainLab\Translate\Tests\Unit\Behaviors;

use Model;
use Schema;
use PluginTestCase;
use Model;
use RainLab\Translate\Classes\Translator;
use RainLab\Translate\Tests\Fixtures\Models\Country as CountryModel;
use RainLab\Translate\Models\Locale as LocaleModel;
use October\Rain\Database\Relations\Relation;

class TranslatableModelTest extends PluginTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -172,7 +172,7 @@ public function testTranslateOrderBy()

Translator::instance()->setLocale('en');
}

public function testGetTranslationValueEagerLoadingWithMorphMap()
{
Relation::morphMap([
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/behaviors/TranslatablePageTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php namespace RainLab\Translate\Tests\Unit\Behaviors;

use File;
use PluginTestCase;
use October\Rain\Halcyon\Model;
use October\Rain\Filesystem\Filesystem;
use October\Rain\Halcyon\Datasource\FileDatasource;
use October\Rain\Halcyon\Datasource\Resolver;
use RainLab\Translate\Tests\Fixtures\Classes\TranslatablePage;
use PluginTestCase;

class TranslatablePageTest extends PluginTestCase
{
public $themePath;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -31,7 +31,7 @@ public function setUp()
});
}

public function tearDown()
public function tearDown(): void
{
File::deleteDirectory($this->themePath.'/pages');
}
Expand Down

0 comments on commit f6e5450

Please sign in to comment.