Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ wp i18n make-pot . languages/commonsbooking.pot
```
command in the plugin directory. Make sure that all of your strings use the `__` function with the domain `commonsbooking`. Then you can use `poedit` to open the `commonsbooking-de_DE.po` and update the strings from the `pot` file.

### Linting

The project uses [phpcs/phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) for PHP code style and [Prettier](https://prettier.io/) for JavaScript formatting.

Run all linting checks manually:
```bash
npm run lint
```

Or run them separately:
```bash
npm run lint:php # PHP code style via phpcbf
npm run lint:js # JS formatting check via prettier
```

**Pre-commit hook:** [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) are configured to automatically run linting on staged files before every commit. `phpcbf` will auto-fix staged `.php` files and `prettier` will auto-format staged `.js` files. The hook is installed automatically when you run `npm install`.

### Build plugin zip

To create the plugin zip file for uploading to a development server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ zurückgibt.
* commonsbooking_mail_body
* commonsbooking_mail_attachment
* commonsbooking_disableCache
* commonsbooking_gbfs_feeds

Es gibt auch Filter Hooks, mit denen du zusätzliche Benutzerrollen, die
zusätzlich zum CB Manager Artikel und Standorte administrieren können,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ receives a value, modifies it, and then returns it.
* commonsbooking_mail_body
* commonsbooking_mail_attachment
* commonsbooking_disableCache
* commonsbooking_gbfs_feeds

There are also filter hooks that allow you to add additional user roles
akin to the CB Manager that can manage items and locations.
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
"grunt-contrib-uglify": "^5.2.2",
"grunt-contrib-watch": "^1.1.0",
"grunt-dart-sass": "^2.0.1",
"husky": "^9.0.0",
"lint-staged": "^15.0.0",
"matchdep": "^2.0.0",
"medium-zoom": "^1.1.0",
"sass": "^1.97.3",
"vitepress": "^1.6.4",
"prettier": "^3.3.3"
},
"scripts": {
"prepare": "husky",
"start": "composer install --ignore-platform-reqs && npm install && npm run dist",
"env": "wp-env",
"env:start": "wp-env start",
Expand All @@ -40,9 +43,16 @@
"cypress:open": "cypress open --config-file tests/cypress/cypress.config.js",
"cypress:run": "cypress run --config-file tests/cypress/cypress.config.js",
"dist": "grunt dist",
"docs:dev": "vitepress dev docs",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
"docs:preview": "vitepress preview docs",
"lint:php": "vendor/bin/phpcbf",
"lint:js": "prettier --check 'assets/**/*.js'",
"lint": "npm run lint:php && npm run lint:js"
},
"lint-staged": {
"*.php": "vendor/bin/phpcbf",
"assets/**/*.js": "prettier --write"
},
"dependencies": {
"@commonsbooking/frontend": "^0.1.0-beta.7",
Expand Down
6 changes: 1 addition & 5 deletions src/API/GBFS/BaseRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public function get_items( $request ): WP_REST_Response {
$response->ttl = 60;
$response->version = '3.1-RC2';

if ( WP_DEBUG ) {
$this->validateData( $response );
}

return new WP_REST_Response( $response, 200 );
return $this->respond_with_validation( $response );
}

/**
Expand Down
28 changes: 19 additions & 9 deletions src/API/GBFS/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,24 @@ class Discovery extends \CommonsBooking\API\BaseRoute {
*/
public function get_items( $request ): WP_REST_Response {

$feeds = array();
$feeds[] = $this->get_feed( 'system_information' );
$feeds[] = $this->get_feed( 'station_information' );
$feeds[] = $this->get_feed( 'station_status' );
/**
* The names of the feeds that are available in the GBFS route.
* They will be announced through the gbfs.json.
* The routes still need to be registered using register_rest_route.
*
* @since 2.11
*
* @param String[] $raw_feeds the names of the feeds without a .json suffix
*/
$raw_feeds = apply_filters(
'commonsbooking_gbfs_feeds',
[
'system_information',
'station_information',
'station_status',
]
);
$feeds = array_map( fn( $feed ) => $this->get_feed( $feed ), $raw_feeds );

$response = new stdClass();
$response->data = new stdClass();
Expand All @@ -46,11 +60,7 @@ public function get_items( $request ): WP_REST_Response {
$response->ttl = 86400;
$response->version = '3.1-RC2';

if ( WP_DEBUG ) {
$this->validateData( $response );
}

return new WP_REST_Response( $response, 200 );
return $this->respond_with_validation( $response );
}

private function get_feed( $name ): stdClass {
Expand Down
6 changes: 1 addition & 5 deletions src/API/GBFS/SystemInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public function get_items( $request ): WP_REST_Response {
$response->ttl = 86400;
$response->version = '3.1-RC2';

if ( WP_DEBUG ) {
$this->validateData( $response );
}

return new WP_REST_Response( $response, 200 );
return $this->respond_with_validation( $response );
}
}
2 changes: 1 addition & 1 deletion src/Service/BookingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public static function checkMaxBookingDays( Booking $booking, array $args, $appl
$allowedBookedDays = $args[0];
$periodDays = $args[1];
// split the period in half, when it is an uneven number, the left side will be one day longer
$daysHalf = $periodDays / 2;
$daysHalf = floor( $periodDays / 2 );
if ( $periodDays % 2 ) {
$daysLeft = $daysHalf + 1;
$daysRight = $daysHalf - 1;
Expand Down
52 changes: 52 additions & 0 deletions tests/php/Service/BookingRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,58 @@ public function testCheckMaxBookingDays_earlyCancel() {
$this->assertNull( BookingRule::checkMaxBookingDays( $allowedBooking, array( 4, 30 ) ) );
}

/**
* Regression test for #2158
* @return void
*/
public function testCheckMaxBookingDays_unevenDays() {
ClockMock::freeze( new \DateTime( self::CURRENT_DATE ) );
$testBookingOne = new Booking(
get_post(
$this->createBooking(
$this->locationId,
$this->itemId,
strtotime( '+1 day' ),
strtotime( '+2 days' ),
'8:00 AM',
'12:00 PM',
'confirmed',
$this->subscriberId
)
)
);
$testBookingTwo = new Booking(
get_post(
$this->createBooking(
$this->locationId,
$this->itemId,
strtotime( '+4 day' ),
strtotime( '+5 days' ),
'8:00 AM',
'12:00 PM',
'confirmed',
$this->subscriberId
)
)
);

$testBookingThree = new Booking(
get_post(
$this->createBooking(
$this->locationId,
$this->itemId,
strtotime( '+6 day' ),
strtotime( '+7 days' ),
'8:00 AM',
'12:00 PM',
'unconfirmed',
$this->subscriberId
)
)
);
$this->assertBookingsPresent( array( $testBookingOne, $testBookingTwo ), BookingRule::checkMaxBookingDays( $testBookingThree, array( 2, 25 ) ) );
}

public function testCheckMaxBookingDaysPerWeek() {
// rule settings
$allowedPerWeek = 2;
Expand Down
Loading