Skip to content

Commit

Permalink
Add missing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bytehead committed Aug 6, 2023
1 parent 41a3ad4 commit a476727
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 20 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on: push

jobs:
check-codestyle:
name: Check codestyle
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: bcmath, dom, fileinfo, filter, gd, hash, intl, json, mbstring, mysqli, pcre, pdo_mysql, zip, zlib
coverage: none

env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install PHP dependencies
run: composer install --no-interaction --no-progress

- name: Check PHP codestyle
run: |
vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run -vvv --ansi
- name: Run static analysis
run: vendor-bin/phpstan/vendor/bin/phpstan analyze src/ --level max --memory-limit=-1 --ansi

unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: bcmath, dom, fileinfo, filter, gd, hash, intl, json, mbstring, mysqli, pcre, pdo_mysql, zip, zlib
coverage: none

env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install the dependencies
run: composer install --no-interaction --no-progress

- name: Run unit tests
run: vendor-bin/phpunit/vendor/bin/phpunit --colors=always

check-composer-requirements:
name: Check Composer requirements
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: bcmath, dom, fileinfo, filter, gd, hash, intl, json, mbstring, mysqli, pcre, pdo_mysql, zip, zlib
coverage: none

env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install the dependencies
run: composer install --no-interaction --no-progress

- name: Check the dependencies
run: tools/require-checker/vendor/bin/composer-require-checker check --config-file=tools/require-checker/config.json composer.json --ansi

security-check:
name: PHP Security Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup cache
uses: actions/cache@v2
id: cache-db
with:
path: ~/.symfony/cache
key: db

- name: Run security check
uses: symfonycorp/security-checker-action@v3
18 changes: 4 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# OS
.DS_Store
Thumbs.db

# IDEs
.buildpath
.project
.settings/
.build/
.idea/

# Composer
vendor/
/vendor-bin/**/vendor
/vendor/
/vendor-bin/*/vendor
/vendor-bin/*/composer.lock
.phpunit.result.cache
composer.lock
composer.phar
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$finder = PhpCsFixer\Finder::create()
->exclude('Resources')
->exclude('Fixtures')
->in([__DIR__ . '/src', __DIR__ . '/contao', __DIR__ . '/config'])
->in([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests'])
;

$config = new PhpCsFixer\Config();
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contao-backend-limited-width
============================
Simply because https://github.com/contao/contao/pull/4552.
22 changes: 22 additions & 0 deletions assets/limited-width.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
:root {
--body-bg: #cfcfd3;
--main-bg: #eaeaec;
}

html[data-color-scheme="dark"] {

}

body {
background: var(--body-bg) !important;
}

#main {
background: var(--main-bg) !important;
}

#container,
#header {
max-width:1440px;
margin:0 auto;
}
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
],
"require": {
"php": "^8.1",
"contao/core-bundle": "^5.0"
"contao/core-bundle": "^5.0",
"doctrine/dbal": "^3.3",
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/security-bundle": "^6.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4",
Expand Down Expand Up @@ -55,7 +60,8 @@
"contao-components/installer": true,
"contao/manager-plugin": true,
"php-http/discovery": true
}
},
"sort-packages": true
},
"scripts": {
"post-install-cmd": [
Expand All @@ -70,14 +76,17 @@
"phpstan": [
"@php vendor-bin/phpstan/vendor/bin/phpstan analyze src/ --level max --memory-limit=-1 --ansi"
],
"phpunit": [
"@php vendor-bin/phpunit/vendor/bin/phpunit --colors=always"
],
"rector": [
"@php vendor-bin/rector/vendor/bin/rector process --clear-cache --dry-run"
],
"rector-fix": [
"@php vendor-bin/rector/vendor/bin/rector --clear-cache process"
],
"require-checker": [
"@php vendor-bin/require-checker/vendor/bin/composer-require-checker check --config-file=tools/require-checker/config.json composer.json --ansi"
"@php vendor-bin/require-checker/vendor/bin/composer-require-checker check --config-file=vendor-bin/require-checker/config.json composer.json --ansi"
]
}
}
7 changes: 7 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
Oneup\ContaoBackendLimitedWidthBundle\EventListener\ParseTemplateListener:
arguments:
- '@security.helper'
- '@contao.framework'
tags:
- { name: contao.hook, hook: parseTemplate }
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- tools/phpstan/vendor/phpstan/phpstan-symfony/extension.neon
- vendor-bin/phpstan/vendor/phpstan/phpstan-symfony/extension.neon

parameters:
bootstrapFiles:
Expand All @@ -8,5 +8,6 @@ parameters:
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
universalObjectCratesClasses:
- Contao\BackendUser

ignoreErrors:
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 1 addition & 0 deletions public/limited-width.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class OneupContaoBackendLimitedWidthExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
(new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config')))
(new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config')))
->load('services.yaml')
;
}
Expand Down
50 changes: 50 additions & 0 deletions src/EventListener/ParseTemplateListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Oneup\ContaoBackendLimitedWidthBundle\EventListener;

use Contao\BackendTemplate;
use Contao\BackendUser;
use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\Template;
use Symfony\Bundle\SecurityBundle\Security;

final class ParseTemplateListener
{
public function __construct(
private readonly Security $security,
private readonly ContaoFramework $contaoFramework,
) {
}

public function __invoke(Template $template): void
{
if (!$template instanceof BackendTemplate) {
return;
}

if ('be_main' !== $template->getName() && !str_starts_with($template->getName(), 'be_main_')) {
return;
}

$user = $this->security->getUser();

if (!$user instanceof BackendUser) {
return;
}

if (false === (bool) $user->limitedWidth) {
return;
}

/** @var Template $templateAdapter */
$templateAdapter = $this->contaoFramework->getAdapter(Template::class);

/** @var Controller $controllerAdapter */
$controllerAdapter = $this->contaoFramework->getAdapter(Controller::class);

$template->stylesheets .= $templateAdapter->generateStyleTag($controllerAdapter->addStaticUrlTo('bundles/oneupcontaobackendlimitedwidth/limited-width.min.css'), null, null);
}
}
4 changes: 4 additions & 0 deletions src/OneupContaoBackendLimitedWidthBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

class OneupContaoBackendLimitedWidthBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
30 changes: 30 additions & 0 deletions tests/ContaoManager/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Oneup\ContaoBackendLimitedWidthBundle\Tests\ContaoManager;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Oneup\ContaoBackendLimitedWidthBundle\ContaoManager\Plugin;
use Oneup\ContaoBackendLimitedWidthBundle\OneupContaoBackendLimitedWidthBundle;
use PHPUnit\Framework\TestCase;

class PluginTest extends TestCase
{
public function testGetsLoadedAfterCoreBundle(): void
{
$plugin = new Plugin();

$bundles = $plugin->getBundles($this->createMock(ParserInterface::class));

self::assertCount(1, $bundles);

/** @var BundleConfig $config */
$config = $bundles[0];

self::assertSame(OneupContaoBackendLimitedWidthBundle::class, $config->getName());
self::assertSame([ContaoCoreBundle::class], $config->getLoadAfter());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Oneup\ContaoBackendLimitedWidthBundle\Tests\DependencyInjection;

use Oneup\ContaoBackendLimitedWidthBundle\DependencyInjection\OneupContaoBackendLimitedWidthExtension;
use Oneup\ContaoBackendLimitedWidthBundle\EventListener\ParseTemplateListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OneupContaoBackendLimitedWidthExtensionTest extends TestCase
{
public function testLoadsServicesYaml(): void
{
$extension = new OneupContaoBackendLimitedWidthExtension();
$containerBuilder = new ContainerBuilder();

$extension->load([], $containerBuilder);
$definitions = array_keys($containerBuilder->getDefinitions());

self::assertContains(ParseTemplateListener::class, $definitions);
self::assertCount(2, $definitions);
}
}
Loading

0 comments on commit a476727

Please sign in to comment.