Skip to content

Commit

Permalink
Merge branch 'hotfix/1.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
abrain committed Feb 27, 2019
2 parents cf8f10c + 7c67dee commit 5878118
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 6 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
- WP_VERSION=4.8.8 WP_MULTISITE=0
- WP_VERSION=4.9.9 WP_MULTISITE=0
- WP_VERSION=5.0.3 WP_MULTISITE=0
- WP_VERSION=5.1 WP_MULTISITE=0
- WP_VERSION=nightly WP_MULTISITE=0

stages:
Expand Down Expand Up @@ -46,7 +47,7 @@ jobs:
script: ./vendor/bin/phpunit --no-coverage --exclude-group unittests
- stage: validate
name: 'Latest versions'
env: WP_VERSION=5.0.3 WP_MULTISITE=0
env: WP_VERSION=5.1 WP_MULTISITE=0
php: '7.3'
before_install: composer require phpunit/phpunit:5.7.* --dev
before_script:
Expand All @@ -57,6 +58,14 @@ jobs:
script: ./vendor/bin/phpunit
after_script:
- ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT
- stage: test
name: 'Latest versions, pretty permalinks'
env: WP_VERSION=5.1 WP_MULTISITE=0 WP_TESTS_PERMALINK=PRETTY
php: '7.3'
- stage: test
name: 'Latest versions, PATHINFO permalinks'
env: WP_VERSION=5.1 WP_MULTISITE=0 WP_TESTS_PERMALINK=PATHINFO
php: '7.3'

matrix:
exclude:
Expand Down
17 changes: 17 additions & 0 deletions src/Admin/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use abrain\Einsatzverwaltung\Options;
use abrain\Einsatzverwaltung\PermalinkController;
use abrain\Einsatzverwaltung\Settings\MainPage;
use abrain\Einsatzverwaltung\Types\Report;
use abrain\Einsatzverwaltung\Utilities;

/**
Expand All @@ -34,6 +35,7 @@ public function __construct(Data $data, Options $options, Utilities $utilities,
add_filter('dashboard_glance_items', array($this, 'addReportsToDashboard'));
add_filter('plugin_row_meta', array($this, 'pluginMetaLinks'), 10, 2);
add_filter("plugin_action_links_{$pluginBasename}", array($this,'addActionLinks'));
add_filter('use_block_editor_for_post_type', array($this, 'useBlockEditorForReports'), 10, 2);

$reportListTable = new ReportListTable();
add_filter('manage_edit-einsatz_columns', array($reportListTable, 'filterColumnsEinsatz'));
Expand Down Expand Up @@ -216,4 +218,19 @@ public function displayAdminNotices()
echo '<a href="' . $url . '" class="button button-primary">Anpassung durchf&uuml;hren</a></p></div>';
}
}

/**
* @param bool $useBlockEditor
* @param string $postType
*
* @return bool
*/
public function useBlockEditorForReports($useBlockEditor, $postType)
{
if ($postType === Report::SLUG && get_option('einsatz_disable_blockeditor', '0') === '1') {
return false;
}

return $useBlockEditor;
}
}
2 changes: 1 addition & 1 deletion src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class Core
{
const VERSION = '1.5.0';
const VERSION = '1.5.1';
const DB_VERSION = 40;

/**
Expand Down
13 changes: 11 additions & 2 deletions src/PermalinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function addRewriteRules(Report $report)
$this->reportRewriteSlug = $report->rewriteSlug;

// add rules for paginated year archive
$base = ltrim($wp_rewrite->front, '/') . $this->reportRewriteSlug;
$base = $this->getRewriteBase();
add_rewrite_rule(
$base . '/(\d{4})/page/(\d{1,})/?$',
'index.php?post_type=einsatz&year=$matches[1]&paged=$matches[2]',
Expand Down Expand Up @@ -140,6 +140,15 @@ public function filterRequest($queryvars)
return $this->modifyQueryVars($queryvars, $this->reportPermalink);
}

/**
* @return string
*/
public function getRewriteBase()
{
global $wp_rewrite;
return ltrim($wp_rewrite->front, '/') . $this->reportRewriteSlug;
}

/**
* Returns the regular expression necessary to disassemble the selector (part of the URL specifying a single report)
*
Expand All @@ -160,7 +169,7 @@ public function getSelectorRegEx($permalink)
*/
public function getPermalink($selector)
{
$path = sprintf('%s/%s', $this->reportRewriteSlug, $selector);
$path = sprintf('%s/%s', $this->getRewriteBase(), $selector);
return home_url(user_trailingslashit($path));
}

Expand Down
20 changes: 20 additions & 0 deletions src/Settings/Pages/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public function addSettingsFields()
$this->settingsApiPage,
'einsatzvw_settings_advreport'
);
add_settings_field(
'einsatzvw_advreport_gutenberg',
'Gutenberg',
array($this, 'echoFieldGutenberg'),
$this->settingsApiPage,
'einsatzvw_settings_advreport'
);
}

public function addSettingsSections()
Expand Down Expand Up @@ -144,6 +151,14 @@ public function echoFieldCoreFeatures()
echo '</fieldset>';
}

public function echoFieldGutenberg()
{
echo '<fieldset>';
$this->echoSettingsCheckbox('einsatz_disable_blockeditor', 'Block-Editor f&uuml;r Einsatzberichte deaktivieren');
echo '<p class="description">Diese Einstellung betrifft nur WordPress 5.0 und neuer.</p>';
echo '</fieldset>';
}

public function echoFieldUrlStructure()
{
echo '<fieldset>';
Expand Down Expand Up @@ -228,5 +243,10 @@ public function registerSettings()
'einsatz_support_posttag',
array('\abrain\Einsatzverwaltung\Utilities', 'sanitizeCheckbox')
);
register_setting(
'einsatzvw_settings_advanced',
'einsatz_disable_blockeditor',
array('\abrain\Einsatzverwaltung\Utilities', 'sanitizeCheckbox')
);
}
}
2 changes: 1 addition & 1 deletion src/einsatzverwaltung.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Einsatzverwaltung
Plugin URI: https://einsatzverwaltung.abrain.de
Description: Verwaltung und Darstellung von Einsatzberichten der Feuerwehr und anderer Hilfsorganisationen
Version: 1.5.0
Version: 1.5.1
Author: Andreas Brain
Author URI: https://www.abrain.de
License: GPLv2
Expand Down
6 changes: 5 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: Feuerwehr, Hilfsorganisation, Öffentlichkeitsarbeit
Requires at least: 4.7.0
Tested up to: 5.1
Requires PHP: 5.3.0
Stable tag: 1.5.0
Stable tag: 1.5.1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -55,6 +55,10 @@ Nein, mehr gibt es [hier](https://einsatzverwaltung.abrain.de/faq/).

== Changelog ==

= 1.5.1 =
* URLs für PATHINFO-Permalinks (beginnen mit /index.php/) repariert
* Block-Editor kann für Einsatzberichte deaktiviert werden

= 1.5.0 =
* Grundlegende Unterstützung für den neuen Blockeditor
* API teilweise aktiviert
Expand Down
44 changes: 44 additions & 0 deletions tests/PermalinkControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ public function testBuildSelector()
$this->assertEquals("prefix/$report->post_name/suffix", $controller->buildSelector($report, 'prefix/%postname%/suffix'));
}

/**
* @group unittests
* It's not completely a unit test, but that way this test is skipped for the old PHP/PHPUnit version which doesn't
* support createMock().
*/
public function testGetPermalink()
{
$controller = new PermalinkController();
$report = $this->createMock('abrain\Einsatzverwaltung\Types\Report');
$report->rewriteSlug = 'customrewriteslug';
$controller->addRewriteRules($report);

if (getenv('WP_TESTS_PERMALINK') === 'PRETTY') {
$this->assertEquals(
'http://example.org/customrewriteslug/some-unique-selector/',
$controller->getPermalink('some-unique-selector')
);
} elseif (getenv('WP_TESTS_PERMALINK') === 'PATHINFO') {
$this->assertEquals(
'http://example.org/index.php/customrewriteslug/some-unique-selector/',
$controller->getPermalink('some-unique-selector')
);
}
}

/**
* @group unittests
*/
public function testGetRewriteBase()
{
$controller = new PermalinkController();
$report = $this->createMock('abrain\Einsatzverwaltung\Types\Report');
$report->rewriteSlug = 'customrewriteslug';
$controller->addRewriteRules($report);

if (getenv('WP_TESTS_PERMALINK') === 'PRETTY') {
$this->assertEquals('customrewriteslug', $controller->getRewriteBase());
} elseif (getenv('WP_TESTS_PERMALINK') === 'PATHINFO') {
$this->assertEquals('index.php/customrewriteslug', $controller->getRewriteBase());
} else {
$this->assertEquals('', $controller->getRewriteBase());
}
}

/**
* @dataProvider queryVarTests
* @param string $input
Expand Down
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
// Zeitzone setzen
update_option('timezone_string', 'Europe/Berlin');
date_default_timezone_set('Europe/Berlin');

if (getenv('WP_TESTS_PERMALINK') === 'PRETTY') {
update_option('permalink_structure', '/%year%/%monthnum%/%postname%/');
} elseif (getenv('WP_TESTS_PERMALINK') === 'PATHINFO') {
update_option('permalink_structure', '/index.php/%year%/%monthnum%/%postname%/');
}
});

require $_tests_dir . '/includes/bootstrap.php';
Expand Down

0 comments on commit 5878118

Please sign in to comment.