Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jflearn committed Sep 28, 2024
2 parents eefa134 + 16d0e85 commit 43f65a4
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 99 deletions.
78 changes: 71 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
name: "Continuous Integration"

on:
on:
push:
branches:
- "hotfix/**"
- "release/**"
- "develop"
- "master"
pull_request:
branches:
- "hotfix/**"
- "release/**"
- "develop"
- "master"

jobs:

tests:
latest:
name: "Build & Verify"
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
with:
command: update
--with silverstripe/framework:^5.0
php_version: 8.1
php_extensions: xdebug intl
- name: Generate Code Coverage
run: |
XDEBUG_MODE=coverage \
./vendor/bin/phpunit -c phpunit.xml.dist \
--coverage-clover ./coverage.xml
- name: Annotate with Metrics
run: |
find src -name "*.php" | xargs -n 1 ./vendor/bin/metrics annotate ./coverage.xml
- name: Refactor with Rector
run: |
./vendor/bin/rector process src
- name: Tidy Source Code
run: |
find tests -name "*.php" | xargs -n 1 ./vendor/bin/phptidy.php replace
find src -name "*.php" | xargs -n 1 ./vendor/bin/phptidy.php replace
- name: Push Back Changes
run: |
git diff --exit-code src || ( \
git config user.name github-actions && \
git config user.email github-actions@github.com && \
git add src && \
git commit -m "tidy" && \
git fetch --unshallow origin ${{ github.head_ref || github.ref_name }} && \
git push origin HEAD:${{ github.head_ref || github.ref_name }} \
)
matrix:
strategy:
fail-fast: false
matrix:
Expand All @@ -19,16 +67,32 @@ jobs:
- operating-system: 'ubuntu-latest'
silverstripe-version: '4.0'
php-version: '7.4'

name: SS ${{ matrix.silverstripe-version }}, PHP ${{ matrix.php-version }}
name: "Matrix: SS ${{ matrix.silverstripe-version }}, PHP ${{ matrix.php-version }}"
runs-on: ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
with:
command: update --with silverstripe/framework:^${{ matrix.silverstripe-version }}
command: update
--with silverstripe/framework:^${{ matrix.silverstripe-version }}
php_version: ${{ matrix.php-version }}
php_extensions: intl
- run: |
./vendor/bin/phpunit -c phpunit.xml.dist \
--coverage-clover ./coverage.xml
./vendor/bin/phpunit -c phpunit.xml.dist
merge:
name: "Merge Changes"
if: github.event_name == 'push'
needs: [latest,matrix]
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- run: |
false || ( \
git config user.name github-actions && \
git config user.email github-actions@github.com && \
git fetch --unshallow origin ${{ github.ref_name }} develop && \
git checkout develop && \
git merge origin/${{ github.ref_name }} && \
git push \
)
41 changes: 0 additions & 41 deletions .github/workflows/t.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/app
/vendor
/resources
/assets
resources
composer.lock
*.cache
*.bak
vendor
*~
coverage.xml
public/assets
.phpunit.result.cache
app
5 changes: 3 additions & 2 deletions .phptidy-config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

$default_package = 'silverstripe-userform-utils';
$add_operator_space = true;
$fix_round_bracket_space = true;
$add_file_docblock = true;
$add_file_docblock = false;
$add_function_docblocks = true;
$add_doctags = true;
$add_doctags = false;
$fix_docblock_format = true;
$fix_docblock_space = true;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"phpunit/phpunit": "^9.5",
"silverstripe/sqlite3": "*",
"logicbrush/metrics": "*",
"cmrcx/phptidy": "*"
"cmrcx/phptidy": "*",
"rector/rector": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions public/_resources/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Block .method file
<Files .method>
Require all denied
</Files>

# Prevent file listings
<IfModule mod_dir.c>
DirectoryIndex disabled
DirectorySlash On
</IfModule>
1 change: 1 addition & 0 deletions public/_resources/.method
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto
1 change: 1 addition & 0 deletions public/_resources/css
1 change: 1 addition & 0 deletions public/_resources/images
1 change: 1 addition & 0 deletions public/_resources/javascript
32 changes: 32 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


declare( strict_types = 1 );

use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function ( RectorConfig $rectorConfig ): void {

$rectorConfig->sets( [
LevelSetList::UP_TO_PHP_74,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
] );

$rectorConfig->skip( [
CompleteDynamicPropertiesRector::class,
ExplicitBoolCompareRector::class,
RemoveParentCallWithoutParentRector::class,
RemoveUnusedPrivatePropertyRector::class,
] );

$rectorConfig->importShortClasses();
$rectorConfig->importNames();

};
2 changes: 2 additions & 0 deletions src/Controllers/RollupPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RollupPageController extends PageController

/**
*
* @Metrics( crap = 3 )
*/
public function init() {
parent::init();
Expand All @@ -35,6 +36,7 @@ public function init() {

/**
*
* @Metrics( crap = 1 )
* @return unknown
*/
public function index() {
Expand Down
6 changes: 2 additions & 4 deletions src/Model/RollupPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ public function getCMSFields() {
* @return unknown
*/
public function Children() {
if ( $this->ShowLinksOnly !== 1 ) {
if ( $this->ShowLinksOnly !== self::DISPLAY_LIST ) {
return ArrayList::create();
}
$children = parent::Children();

return parent::Children()->exclude( ['Content' => ''] );
return parent::Children();
}


Expand Down
12 changes: 5 additions & 7 deletions src/Model/WithRollupSupportExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WithRollupSupportExtension extends DataExtension

/**
*
* @param FieldList $fields
* @Metrics( crap = 1 )
*/
public function updateSettingsFields( FieldList $fields ) {
$fields->insertAfter( 'ShowInSearch', CheckboxField::create( 'NeverRollup', 'Never rollup this page?' ) );
Expand All @@ -31,19 +31,17 @@ public function updateSettingsFields( FieldList $fields ) {

/**
*
* @Metrics( crap = 7 )
* @param unknown $link
* @param unknown $action
* @param unknown $relativeLink
*/
public function updateLink( &$link, &$action, &$relativeLink ) {
if ( $action === null ) {
if ( ! $this->owner->NeverRollup &&
if ( $action === null && ( ! $this->owner->NeverRollup &&
! ( Controller::has_curr() && Controller::curr() instanceof CMSPageEditController ) &&
$this->owner->Parent() instanceof RollupPage &&
$this->owner->Parent()->ShowLinksOnly !== 1
) {
$link = $this->owner->Parent()->Link() . '#' . $this->owner->URLSegment;
}
$this->owner->Parent()->ShowLinksOnly !== 1 ) ) {
$link = $this->owner->Parent()->Link() . '#' . $this->owner->URLSegment;
}
}

Expand Down
46 changes: 15 additions & 31 deletions tests/unit/Model/RollupPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,36 @@ public function testGetCMSFields() {


/**
*
* The list of children for the rollup page can vary depending on the value
* of `ShowLinksOnly`.
*/
public function testChildren() {
public function testChildrenWithShowLinksOnlyOptions() {

$rollupPage = RollupPage::create();
$rollupPage->ShowLinksOnly = 1;
$rollupPage->ShowLinksOnly = RollupPage::DISPLAY_INLINE;
$rollupPage->write();
$rollupPage->publishSingle();

$this->assertEquals( 0, $rollupPage->Children()->count() );

$page1 = Page::create();
$page1->Content = '<p>Page 1</p>';
$page1->ParentID = $rollupPage->ID;
$page1->write();
$page1->publishSingle();
$childPage = Page::create();
$childPage->ParentID = $rollupPage->ID;
$childPage->write();
$childPage->publishSingle();

$page2 = Page::create();
$page2->Content = '';
$page2->ParentID = $rollupPage->ID;
$page2->write();
$page2->publishSingle();
// ShowLinksOnly == DISPLAY_INLINE -> should have no children.
$this->assertEquals( 0, $rollupPage->Children()->count() );

$rollupPage->ShowLinksOnly = RollupPage::DISPLAY_LIST;
$rollupPage->write();
$rollupPage->publishSingle();

// ShowLinksOnly == DISPLAY_LIST -> should have one child.
$this->assertEquals( 1, $rollupPage->Children()->count() );

$page2->Content = '<p>Page 2</p>';
$page2->write();
$page2->publishSingle();

$rollupPage->write();
$rollupPage->publishSingle();

$this->assertEquals( 2, $rollupPage->Children()->count() );

$rollupPage->ShowLinksOnly = 2;
$rollupPage->write();
$rollupPage->publishSingle();

$this->assertEquals( 0, $rollupPage->Children()->count() );

$rollupPage->ShowLinksOnly = 0;
$rollupPage->ShowLinksOnly = RollupPage::DISPLAY_TABS;
$rollupPage->write();
$rollupPage->publishSingle();

// ShowLinksOnly == DISPLAY_TABS -> should have no children.
$this->assertEquals( 0, $rollupPage->Children()->count() );
}

Expand Down

0 comments on commit 43f65a4

Please sign in to comment.