Skip to content

Commit

Permalink
fix: migration assumes fof/follow-tags is installed (#49)
Browse files Browse the repository at this point in the history
* fix: migration assumes fof/follow-tags is installed, add very basic initial test

* remove phpunit cache

* add phpunit.result.cache

* Apply fixes from StyleCI

* enable testing

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
imorland and StyleCIBot authored Oct 31, 2023
1 parent aaba93a commit abf9b4c
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 99 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: FoF Discussion Language PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true

backend_directory: .
32 changes: 0 additions & 32 deletions .github/workflows/build.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: FoF Discussion Language JS

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ js/dist
js/node_modules
vendor
composer.lock
.phpunit.result.cache
151 changes: 89 additions & 62 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,94 @@
{
"name": "fof/discussion-language",
"description": "Specify the language a discussion is written in & sort by language",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/discussion-language/issues",
"source": "https://github.com/FriendsOfFlarum/discussion-language",
"forum": "https://discuss.flarum.org/d/23702"
},
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
"require": {
"flarum/core": "^1.8.1",
"rinvex/countries": "^6.1.2 || ^7.0.1 || ^8.1.0",
"league/csv": "^9.7",
"ianm/iso-639": "^1.0",
"flarum/tags": "*"
},
"authors": [
{
"name": "David Sevilla Martin",
"email": "[email protected]",
"role": "Developer"
"name": "fof/discussion-language",
"description": "Specify the language a discussion is written in & sort by language",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/discussion-language/issues",
"source": "https://github.com/FriendsOfFlarum/discussion-language",
"forum": "https://discuss.flarum.org/d/23702"
},
{
"name": "IanM",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"FoF\\DiscussionLanguage\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "FoF Discussion Language",
"category": "feature",
"icon": {
"name": "fas fa-language",
"backgroundColor": "#e74c3c",
"color": "#fff"
},
"optional-dependencies": [
"fof/byobu",
"fof/follow-tags"
]
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
"require": {
"flarum/core": "^1.8.1",
"rinvex/countries": "^6.1.2 || ^7.0.1 || ^8.1.0",
"league/csv": "^9.7",
"ianm/iso-639": "^1.0",
"flarum/tags": "*"
},
"authors": [
{
"name": "David Sevilla Martin",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "IanM",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"FoF\\DiscussionLanguage\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "FoF Discussion Language",
"category": "feature",
"icon": {
"name": "fas fa-language",
"backgroundColor": "#e74c3c",
"color": "#fff"
},
"optional-dependencies": [
"fof/byobu",
"fof/follow-tags"
]
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/23702"
},
"flarum-cli": {
"modules": {
"githubActions": true,
"backendTesting": true
}
}
},
"require-dev": {
"fof/byobu": "*",
"fof/follow-tags": "*",
"flarum/testing": "^1.0.0"
},
"autoload-dev": {
"psr-4": {
"FoF\\DiscussionLanguage\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/23702"
"scripts-descriptions": {
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
}
},
"require-dev": {
"fof/byobu": "*",
"fof/follow-tags": "*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

return [
'up' => function (Builder $schema) {
$schema->table('tag_user', function (Blueprint $table) {
$table->integer('dl_language_id')->unsigned()->nullable();
$schema->table('tag_user', function (Blueprint $table) use ($schema) {
if (!$schema->hasColumn('tag_user', 'dl_language_id')) {
$table->integer('dl_language_id')->unsigned()->nullable();

$table->foreign('dl_language_id')->references('id')->on('discussion_languages')->onDelete('set null');
$table->foreign('dl_language_id')->references('id')->on('discussion_languages')->onDelete('set null');
}

$table->index(['user_id', 'subscription', 'dl_language_id']);
$table->index(['user_id', 'dl_language_id']);
$table->index(['dl_language_id']);
});
},
Expand All @@ -29,7 +31,7 @@
$table->dropForeign(['dl_language_id']);

$table->dropIndex(['dl_language_id']);
$table->dropIndex(['user_id', 'subscription', 'dl_language_id']);
$table->dropIndex(['user_id', 'dl_language_id']);

$table->dropColumn('dl_language_id');
});
Expand Down
Empty file added tests/fixtures/.gitkeep
Empty file.
83 changes: 83 additions & 0 deletions tests/integration/api/CreateLanguageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of fof/discussion-language.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FoF\DiscussionLanguage\tests\integration\api;

use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;

class CreateLanguageTest extends TestCase
{
use RetrievesAuthorizedUsers;

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

$this->extension('flarum-tags');
$this->extension('fof-discussion-language');

$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
]);
}

/**
* @test
*/
public function non_admin_cannot_create_language()
{
$response = $this->send(
$this->request('POST', '/api/fof/discussion-language', [
'json' => [
'data' => [
'attributes' => [
'country' => 'Test Country',
'code' => 'test',
],
],
],
'authenticatedAs' => 2,
])
);

$this->assertEquals(403, $response->getStatusCode());
}

/**
* @test
*/
public function admin_can_create_language()
{
$response = $this->send(
$this->request('POST', '/api/fof/discussion-language', [
'json' => [
'data' => [
'attributes' => [
'country' => 'Test Country',
'code' => 'test',
],
],
],
'authenticatedAs' => 1,
])
);

$this->assertEquals(201, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true);

$this->assertEquals('Test Country', $data['data']['attributes']['country']);
$this->assertEquals('test', $data['data']['attributes']['code']);
}
}
18 changes: 18 additions & 0 deletions tests/integration/setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of fof/discussion-language.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Flarum\Testing\integration\Setup\SetupScript;

require __DIR__.'/../../vendor/autoload.php';

$setup = new SetupScript();

$setup->run();
25 changes: 25 additions & 0 deletions tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Flarum Integration Tests">
<directory suffix="Test.php">./integration</directory>
<exclude>./integration/tmp</exclude>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit abf9b4c

Please sign in to comment.