Skip to content

Commit

Permalink
Merge pull request #404 from Art4/support-redmine-4.2
Browse files Browse the repository at this point in the history
Support for Redmine 4.2
  • Loading branch information
Art4 authored Jun 27, 2024
2 parents 98e72b1 + 8c29a12 commit 31768d5
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 72 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ like [Guzzle](https://github.com/guzzle/guzzle) for handling http connections

## Supported Redmine versions

We support (and run tests against) the [latest Redmine versions](https://www.redmine.org/projects/redmine/wiki/Download#Latest-releases)
that are actively maintained.
We support (and run tests against) the [latest supported Redmine versions](https://www.redmine.org/projects/redmine/wiki/Download#Versions-status-and-releases-policy)
that receive security updates.

- Redmine 5.1.x
- Redmine 5.0.x
- Redmine 4.2.x

Nevertheless, you can also use this library for all older Redmine versions.
In this case, however, be aware that some features may not yet be supported by your Redmine server.
In this case, however, be aware that some features might not be supported by your Redmine server.

If a new Redmine version enables new features that are not yet supported with this library,
you are welcome to [create an issue](https://github.com/kbsali/php-redmine-api/issues).
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ services:
volumes:
- ./.docker/redmine-50009_data/files:/usr/src/redmine/files
- ./.docker/redmine-50009_data/sqlite:/usr/src/redmine/sqlite

redmine-40210:
# Redmine 4.2.11 is not available on Docker Hub
# @link https://hub.docker.com/_/redmine/tags?page=&page_size=&ordering=&name=4.2.11
image: redmine:4.2.10
user: "1000:1000"
ports:
- "4210:3000"
environment:
REDMINE_SECRET_KEY_BASE: supersecretkey
REDMINE_PLUGINS_MIGRATE: true
volumes:
- ./.docker/redmine-40210_data/files:/usr/src/redmine/files
- ./.docker/redmine-40210_data/sqlite:/usr/src/redmine/sqlite
18 changes: 18 additions & 0 deletions tests/Behat/Bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ public function theReturnedDataPropertyContainsTheFollowingData($property, Table
$this->assertTableNodeIsSameAsArray($table, $returnData);
}

/**
* @Then the returned data :property property contains the following data with Redmine version :versionComparision
*/
public function theReturnedDataPropertyContainsTheFollowingDataWithRedmineVersion($property, string $versionComparision, TableNode $table)
{
$parts = explode(' ', $versionComparision);

$redmineVersion = RedmineVersion::tryFrom($parts[1]);

if ($redmineVersion === null) {
throw new InvalidArgumentException('Comparison with Redmine ' . $versionComparision . ' is not supported.');
}

if (version_compare($this->redmine->getVersionString(), $parts[1], $parts[0])) {
$this->theReturnedDataPropertyContainsTheFollowingData($property, $table);
}
}

/**
* @Then the returned data :property property has only the following properties
*/
Expand Down
133 changes: 133 additions & 0 deletions tests/Behat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Behaviour tests

This folder contains BDD tests using Docker and Behat.

## How to run the tests

Pull the Redmine docker images and start them by running:

```bash
docker compose up -d
```

Now you can run the tests:

```bash
# all tests
docker compose exec php composer behat
# only a specific redmine version
docker compose exec php composer behat -- --suite=redmine_50103
# only specific endpoints
docker compose exec php composer behat -- --tags=issue,group
# only specific endpoints on a specific redmine version
docker compose exec php composer behat -- --suite=redmine_50103 --tags=issue,group
```

## Redmine specific features

Some Redmine features are specific for a Redmine version. There are two ways to handle this situations.

### Modified Rest-API Responses

It is possible that a new Redmine version returns new or changed elements in a response.
This can be handled on the `step` layer:

```
And the returned data "projects.0" property has only the following properties with Redmine version ">= 5.1.0"
"""
id
name
identifier
description
homepage
status
is_public
inherit_members
created_on
updated_on
"""
But the returned data "projects.0" property has only the following properties with Redmine version "< 5.1.0"
"""
id
name
identifier
description
status
is_public
inherit_members
created_on
updated_on
"""
```

### New Rest-API Endpoints

A new Redmine version could be introduce new REST-API endpoints that are missing in the older version.
This can be handled on the `scenario` or `feature` layer.

1. Tag features or scenarios e.g. with `@since50000`.

```
@since50000
Feature: Interacting with the new REST API endpoint
[...]
```

or

```
@since50000
Scenario: Using a new feature
Given I have a "NativeCurlClient" client
And I create a project with name "Test Project" and identifier "test-project"
[...]
```

2. Exclude the tag from the specific suite in the `behat.yml` (note the `~` prefix):

```
default:
suites:
[...]
redmine_40210:
[...]
filters:
tags: "~@since50000"
```

### Removed Rest-API Endpoints

A new Redmine version could remove REST-API endpoints that are missing in the newer versions.
This can be handled on the `scenario` or `feature` layer.

1. Tag features or scenarios e.g. with `@until60000`.

```
@until60000
Feature: Interacting with the a REST API endpoint removed in 6.0.0
[...]
```

or

```
@until60000
Scenario: Using a deprecated feature
Given I have a "NativeCurlClient" client
And I create a project with name "Test Project" and identifier "test-project"
[...]
```

2. Exclude the tag from the specific suite in the `behat.yml` (note the `~` prefix):

```
default:
suites:
[...]
redmine_60000:
[...]
filters:
tags: "~@until60000"
```
8 changes: 8 additions & 0 deletions tests/Behat/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ default:
contexts:
- Redmine\Tests\Behat\Bootstrap\FeatureContext:
redmineVersion: '5.0.9'
redmine_40210:
paths:
- '%paths.base%/features'
contexts:
- Redmine\Tests\Behat\Bootstrap\FeatureContext:
redmineVersion: '4.2.10'
filters:
tags: "~@since50000"
11 changes: 4 additions & 7 deletions tests/Behat/features/attachments.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@attachment
Feature: Interacting with the REST API for attachments
In order to interact with REST API for attachments
As a user
I want to make sure the Redmine server replies with the correct response

@attachment
Scenario: Uploading an attachment
Given I have a "NativeCurlClient" client
When I upload the content of the file "%tests_dir%/Fixtures/testfile_01.txt" with the following data
Expand All @@ -26,7 +26,7 @@ Feature: Interacting with the REST API for attachments
| id | 1 |
| token | 1.7b962f8af22e26802b87abfa0b07b21dbd03b984ec8d6888dabd3f69cff162f8 |

@attachment

Scenario: Updating the details of an attachment
Given I have a "NativeCurlClient" client
And I create a project with name "Test Project" and identifier "test-project"
Expand All @@ -41,7 +41,6 @@ Feature: Interacting with the REST API for attachments
And the response has the content ""
And the returned data is true

@attachment
Scenario: Showing the details of an attachment
Given I have a "NativeCurlClient" client
And I upload the content of the file "%tests_dir%/Fixtures/testfile_01.txt" with the following data
Expand Down Expand Up @@ -80,7 +79,7 @@ Feature: Interacting with the REST API for attachments
| id | 1 |
| name | Redmine Admin |

@attachment @error
@error
Scenario: Try to show details of a non-existing attachment
Given I have a "NativeCurlClient" client
When I show the attachment with the id "1"
Expand All @@ -89,7 +88,6 @@ Feature: Interacting with the REST API for attachments
And the response has the content ""
And the returned data is false

@attachment
Scenario: Downloading an attachment
Given I have a "NativeCurlClient" client
And I upload the content of the file "%tests_dir%/Fixtures/testfile_01.txt" with the following data
Expand All @@ -111,7 +109,7 @@ Feature: Interacting with the REST API for attachments
"""

@attachment @error
@error
Scenario: Try to download a non-existing attachment
Given I have a "NativeCurlClient" client
When I download the attachment with the id "1"
Expand All @@ -121,7 +119,6 @@ Feature: Interacting with the REST API for attachments
# And the response has the content "<!DOCTYPE html><html lang="en">..."
And the returned data is false

@attachment
Scenario: Deleting an attachment
Given I have a "NativeCurlClient" client
And I upload the content of the file "%tests_dir%/Fixtures/testfile_01.txt" with the following data
Expand Down
12 changes: 2 additions & 10 deletions tests/Behat/features/groups.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@group
Feature: Interacting with the REST API for groups
In order to interact with REST API for groups
As a user
I want to make sure the Redmine server replies with the correct response

@group
Scenario: Creating a group with minimal parameters
Given I have a "NativeCurlClient" client
When I create a group with name "Test Group"
Expand All @@ -20,7 +20,6 @@ Feature: Interacting with the REST API for groups
| id | 4 |
| name | Test Group |

@group
Scenario: Listing of zero groups
Given I have a "NativeCurlClient" client
When I list all groups
Expand All @@ -33,7 +32,6 @@ Feature: Interacting with the REST API for groups
And the returned data "groups" property is an array
And the returned data "groups" property contains "0" items

@group
Scenario: Listing of one group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
Expand All @@ -57,7 +55,6 @@ Feature: Interacting with the REST API for groups
| id | 4 |
| name | Test Group |

@group
Scenario: Listing names of all groups
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group 1"
Expand All @@ -78,7 +75,6 @@ Feature: Interacting with the REST API for groups
| 7 | Test Group 4 |
| 8 | Test Group 5 |

@group
Scenario: Showing a specific group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
Expand All @@ -100,7 +96,7 @@ Feature: Interacting with the REST API for groups
| id | 4 |
| name | Test Group |

@group @error
@error
Scenario: Try to show a non-existing group
Given I have a "NativeCurlClient" client
When I show the group with id "40"
Expand All @@ -109,7 +105,6 @@ Feature: Interacting with the REST API for groups
And the response has the content ""
And the returned data is false

@group
Scenario: Updating a group
Given I have a "NativeCurlClient" client
And I create a group with the following data
Expand All @@ -123,7 +118,6 @@ Feature: Interacting with the REST API for groups
And the response has the content ""
And the returned data is exactly ""

@group
Scenario: Adding an user to a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
Expand All @@ -133,7 +127,6 @@ Feature: Interacting with the REST API for groups
And the response has the content ""
And the returned data is exactly ""

@group
Scenario: Removing an user from a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
Expand All @@ -144,7 +137,6 @@ Feature: Interacting with the REST API for groups
And the response has the content ""
And the returned data is exactly ""

@group
Scenario: Deleting a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
Expand Down
Loading

0 comments on commit 31768d5

Please sign in to comment.