Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f9df769
Update SimpleSharing plugin for Craft CMS 5.x compatibility and fix s…
reganlawton Aug 22, 2025
be6ed6d
Add GitHub Actions workflow for Craft 5.x and Craft 4.x tests
reganlawton Aug 22, 2025
7363a72
Refactor test namespaces and add coverage reporting for GitHub Actions
reganlawton Aug 22, 2025
1d80083
Add coverage text report generation for pull requests in GitHub Actions
reganlawton Aug 22, 2025
41ce379
Enhance GitHub Actions coverage reporting by extracting summary metri…
reganlawton Aug 22, 2025
f097d6a
Refactor coverage summary extraction in unit test output
reganlawton Aug 22, 2025
c3921b2
Fix regex patterns for coverage summary extraction in unit test output
reganlawton Aug 22, 2025
58ce6e1
Simplify coverage summary extraction in GitHub Actions workflow
reganlawton Aug 22, 2025
9174714
Improve coverage summary extraction in GitHub Actions workflow for re…
reganlawton Aug 22, 2025
c4c4313
Improve reliability of coverage percentage extraction in GitHub Actio…
reganlawton Aug 22, 2025
d96e309
Fix Craft 5 compatibility: Update sections service to entries
Siyabulela Jan 14, 2026
1e93cd5
Merge pull request #24 from Siyabulela/fix/craft5-sections-service
reganlawton Jan 14, 2026
7592ed7
Add integration testing environment with Docker and PostgreSQL; remov…
reganlawton Jan 14, 2026
cdba0c6
Update CI workflow: Add missing directories for Craft storage and output
reganlawton Jan 14, 2026
e874a08
Update README: Add version matrix, improve testing instructions, and …
reganlawton Jan 14, 2026
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
194 changes: 194 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
name: Tests

on:
pull_request:
branches: [ master, v2 ]
push:
branches: [ master, v2 ]

jobs:
# Craft 5.x tests (master branch) - PHP 8.2+
craft5-tests:
if: github.ref == 'refs/heads/master' || github.base_ref == 'master'
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

strategy:
matrix:
php: [8.2, 8.3]

name: Craft 5.x - PHP ${{ matrix.php }} Tests

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, pdo_pgsql, bcmath, soap, intl, gd, exif, iconv
coverage: xdebug

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: craft5-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
craft5-${{ runner.os }}-php-${{ matrix.php }}-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --dev

- name: Setup test environment
run: |
cp tests/.env.example tests/.env
sed -i 's/host=postgres/host=localhost/' tests/.env
mkdir -p tests/_craft/storage/runtime
mkdir -p tests/_craft/storage/logs
mkdir -p tests/_craft/storage/config-deltas
mkdir -p tests/_craft/migrations
mkdir -p tests/_craft/translations
mkdir -p tests/_output

- name: Build Codeception
run: vendor/bin/codecept build

- name: Run all tests
run: vendor/bin/codecept run --coverage --coverage-xml
env:
CRAFT_DB_DSN: "pgsql:host=localhost;port=5432;dbname=postgres"
CRAFT_DB_USER: postgres
CRAFT_DB_PASSWORD: postgres
CRAFT_DB_SCHEMA: public
CRAFT_DB_TABLE_PREFIX: craft
CRAFT_SECURITY_KEY: test-security-key-for-github-actions

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.php == '8.2'
with:
files: ./tests/_output/coverage.xml
fail_ci_if_error: false
verbose: true

- name: Generate coverage text report
if: github.event_name == 'pull_request' && matrix.php == '8.2'
id: coverage
run: |
raw_output=$(vendor/bin/codecept run unit --coverage-text --no-ansi 2>&1)

classes=$(echo "$raw_output" | grep "Classes:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A")
methods=$(echo "$raw_output" | grep "Methods:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A")
lines=$(echo "$raw_output" | grep "Lines:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A")

test_result=$(echo "$raw_output" | grep "OK (" || echo "Tests completed")

echo "classes=${classes:-N/A}" >> "$GITHUB_OUTPUT"
echo "methods=${methods:-N/A}" >> "$GITHUB_OUTPUT"
echo "lines=${lines:-N/A}" >> "$GITHUB_OUTPUT"
echo "test-result=${test_result:-Tests completed}" >> "$GITHUB_OUTPUT"
env:
CRAFT_DB_DSN: "pgsql:host=localhost;port=5432;dbname=postgres"
CRAFT_DB_USER: postgres
CRAFT_DB_PASSWORD: postgres
CRAFT_DB_SCHEMA: public
CRAFT_DB_TABLE_PREFIX: craft
CRAFT_SECURITY_KEY: test-security-key-for-github-actions

- name: Comment PR with coverage
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && matrix.php == '8.2'
with:
recreate: true
message: |
## 📊 Test Coverage Report (PHP ${{ matrix.php }})

| Metric | Coverage |
|--------|----------|
| **Classes** | `${{ steps.coverage.outputs.classes }}` |
| **Methods** | `${{ steps.coverage.outputs.methods }}` |
| **Lines** | `${{ steps.coverage.outputs.lines }}` |

**Test Results:** ${{ steps.coverage.outputs.test-result }}

# Craft 4.x tests (v2 branch) - PHP 8.0+
craft4-tests:
if: github.ref == 'refs/heads/v2' || github.base_ref == 'v2'
runs-on: ubuntu-latest

strategy:
matrix:
php: [8.0, 8.1, 8.2]

name: Craft 4.x - PHP ${{ matrix.php }} Tests

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: xdebug

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: craft4-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
craft4-${{ runner.os }}-php-${{ matrix.php }}-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --dev

- name: Build Codeception (if exists)
run: |
if [ -f "vendor/bin/codecept" ]; then
vendor/bin/codecept build
fi

- name: Run unit tests (if exists)
run: |
if [ -f "vendor/bin/codecept" ]; then
vendor/bin/codecept run unit
else
echo "No tests configured for this branch"
fi

code-quality:
runs-on: ubuntu-latest
name: Code Quality

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv

- name: Install dependencies
run: composer install --prefer-dist --no-progress --dev

- name: Check PHP syntax
run: find src tests -name "*.php" -exec php -l {} \;
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# COMPOSER
/vendor
composer.lock

# BUILD FILES
/bower_components/*
Expand All @@ -30,3 +31,4 @@
!.vscode/extensions.json
config.codekit3
prepros-6.config

35 changes: 35 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Repository Guidelines

## Project Structure & Module Organization
- `src/`: Plugin source code (controllers, models, asset bundles, templates, variables).
- `tests/`: Codeception suites (`unit/`, `functional/`) plus support data in `_support/` and `_data/`.
- `resources/`: Plugin resources and metadata assets.
- `vendor/`: Composer-managed dependencies (generated).

## Build, Test, and Development Commands
- `composer install --dev`: Install runtime + dev dependencies for local development.
- `composer require wrav/simplesharing`: Install the plugin into a Craft project.
- `vendor/bin/codecept run`: Run all Codeception tests.
- `vendor/bin/codecept run unit`: Run unit tests only.
- `vendor/bin/codecept run functional`: Run functional tests only.
- `vendor/bin/codecept run --coverage`: Generate a coverage report.

## Coding Style & Naming Conventions
- Language: PHP 8.2; Craft CMS plugin conventions.
- Autoloading: PSR-4 namespace `wrav\simplesharing\` mapped to `src/`.
- File naming: Class files match class names (e.g., `SimpleSharing.php`).
- Indentation: 4 spaces; keep files ASCII unless existing content requires Unicode.

## Testing Guidelines
- Framework: Codeception (with PHPUnit under the hood).
- Suites: `unit` and `functional` are defined by `tests/*.suite.yml`.
- Naming: Place unit tests in `tests/unit` and functional tests in `tests/functional`; match Codeception naming conventions (e.g., `*Test.php`).
- Config: Set Craft test environment in `tests/_craft/config/test.php` before running functional tests.

## Commit & Pull Request Guidelines
- Commits: Use short, imperative, sentence-case summaries (e.g., “Fix coverage summary extraction”); no prefix observed in recent history.
- PRs: Include a clear description, linked issue (if any), and test results. Add screenshots or recordings for Control Panel UI changes.

## Security & Configuration Tips
- Do not commit secrets or `.env` files. Use local environment overrides only.
- Validate changes against Craft’s plugin requirements (`composer.json`) before release.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Simple Sharing Changelog

## 3.0.0 - 2026-01-14
### Updated
- Craft5.x Support Added (^3.0.0 is not backward compatible with Craft4.x, use 2.x branch).
- Fixed LinkedIn sharing URL to use correct endpoint
- Updated Tumblr sharing URL format

# Added
- Added support for functional, integration and unit testing

## 2.0.0 - 2022-11-17
### Updated
- Craft4.x Support Added (^2.0.0 is not backward compatible with Craft3.x, use 1.x branch).
Expand Down
65 changes: 65 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Simple Sharing is a Craft CMS 5.x plugin that generates social media share links within the Control Panel, allowing quick sharing of entries to Facebook, Twitter, LinkedIn, Mix, Tumblr, and Reddit.

## Commands

```bash
# Install dependencies
composer install --dev

# Build Codeception (regenerate actor classes)
vendor/bin/codecept build

# Check PHP syntax
find src tests -name "*.php" -exec php -l {} \;
```

### Running Tests (requires Docker)

Tests require a PostgreSQL database. Use Docker Compose:

```bash
# Setup test environment
cp tests/.env.example tests/.env

# Start Docker containers
docker compose up -d

# Access app container and run tests
docker exec -it app sh
vendor/bin/codecept run # All tests
vendor/bin/codecept run unit # Unit tests only
vendor/bin/codecept run integration # Integration tests only
vendor/bin/codecept run --coverage # With coverage
```

## Architecture

**Plugin Structure** (`src/`):
- `SimpleSharing.php` - Main plugin class, registers Twig variable and injects CP JavaScript
- `variables/SimpleSharingVariable.php` - Twig variable providing `craft.simpleSharing.link(url, service)`
- `models/Settings.php` - Plugin settings (allowedSections, allowedPlatforms)
- `controllers/DefaultController.php` - Controller for CP actions (`actionUrl`)
- `assetbundles/simplesharing/` - JavaScript for CP sidebar functionality
- `templates/settings.twig` - Settings page template

**Key Integration Points**:
- Registers `simpleSharing` variable on `CraftVariable::EVENT_INIT`
- Injects JavaScript on `View::EVENT_END_PAGE` for CP requests
- Extends `craft\base\Plugin` with settings model

**Testing** (`tests/`):
- Uses Codeception with `unit`, `integration`, and `functional` suites
- Unit tests: Core functionality without Craft bootstrap
- Integration tests: Full Craft CMS integration with plugin installed
- Test config in `codeception.yml` with `\craft\test\Craft` module
- Database setup: `dbSetup: { clean: true, setupCraft: true }`

## Supported Platforms

facebook, twitter, linkedin, mix, tumblr, reddit
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ Simple Sharing is a CraftCMS plugin that generates social media share links with
the Craft CP page, allowing you to quickly and easily share entries.

## Requirements
Current Version: 2.0.0\
This plugin requires Craft CMS ^4.0.0.

If you are looking for CraftCMS 3.x support, use current project [Version 1.0.8](https://github.com/wrav/SimpleSharing/tree/1.0.8)
| Version | Craft CMS | PHP |
|---------|-----------|-----|
| ^3.0.0 | ^5.0.0 | ^8.2 |
| ^2.0.0 | ^4.0.0 | ^8.0.2 |
| ^1.0.0 | ^3.0.0 | ^7.2.5 |

If you are looking for CraftCMS 2.5 support, use previous project [version 1.1.5](https://github.com/hut6/SimpleSharing/tree/1.1.5)
If you are looking for CraftCMS 4.x support, use [Version 2.x](https://github.com/wrav/SimpleSharing/tree/v2)

If you are looking for CraftCMS 3.x support, use [Version 1.0.8](https://github.com/wrav/SimpleSharing/tree/1.0.8)

## Installing

Expand Down Expand Up @@ -40,6 +44,42 @@ Your able to generate share links on the fly in a template as followed.
{{ craft.simpleSharing.link(url, 'reddit') }}
```

## Testing

The plugin includes a comprehensive test suite using Codeception with unit, integration, and functional tests.

### Running Tests

Tests require Docker with PostgreSQL:

```bash
# Setup test environment
cp tests/.env.example tests/.env

# Start Docker containers
docker compose up -d

# Access app container
docker exec -it app sh

# Run all tests
vendor/bin/codecept run

# Run specific suites
vendor/bin/codecept run unit
vendor/bin/codecept run integration
vendor/bin/codecept run functional

# Run with coverage report
vendor/bin/codecept run --coverage
```

### Test Coverage

- **Unit Tests**: URL generation, input validation, platform support
- **Integration Tests**: Plugin installation, settings rendering, Craft integration
- **Functional Tests**: Template variable availability

## Credits

Original built while at working at [HutSix](https://hutsix.com.au/) I've since been granted permission to continue development here.
Expand Down
Loading