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
162 changes: 162 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
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

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, 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: Build Codeception
run: vendor/bin/codecept build

- name: Run unit tests
run: vendor/bin/codecept run unit --coverage --coverage-xml

- 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: |
# Run coverage and strip ANSI color codes
raw_output=$(vendor/bin/codecept run unit --coverage-text --no-ansi 2>&1)

# Debug: show the actual lines
echo "Raw coverage lines:"
echo "$raw_output" | grep -E "(Classes|Methods|Lines):"

# Extract coverage percentages more reliably
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")

# Get test results
test_result=$(echo "$raw_output" | grep "OK (" || echo "Tests failed")

# Use simple variable assignment
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 failed}" >> "$GITHUB_OUTPUT"

- 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 {} \;
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Simple Sharing Changelog

## 3.0.0 - 2024-XX-XX
### 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

## 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
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ 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.
Current Version: 3.0.0\
This plugin requires Craft CMS ^5.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)
If you are looking for CraftCMS 4.x support, use [Version 2.1.0](https://github.com/wrav/SimpleSharing/tree/master)

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 3.x support, use [Version 1.0.8](https://github.com/wrav/SimpleSharing/tree/1.0.8)

If you are looking for CraftCMS 2.5 support, use [version 1.1.5](https://github.com/hut6/SimpleSharing/tree/1.1.5)

## Installing

Expand Down Expand Up @@ -40,6 +42,44 @@ 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 for both unit and functional testing.

### Running Tests

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

# Run all tests
vendor/bin/codecept run

# Run only unit tests
vendor/bin/codecept run unit

# Run only functional tests
vendor/bin/codecept run functional

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

### Test Coverage

- **Unit Tests**: URL generation, input validation, platform support
- **Functional Tests**: Controller endpoints, Craft integration
- **Template Tests**: Twig variable availability and output

### Development Setup

For plugin development:

1. Clone the repository
2. Run `composer install --dev`
3. Configure your test environment in `tests/_craft/config/test.php`
4. Run tests with `vendor/bin/codecept run`

## Credits

Original built while at working at [HutSix](https://hutsix.com.au/) I've since been granted permission to continue development here.
Expand Down
21 changes: 21 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace: tests
actor: Tester
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
config:
Codeception\Extension\RunFailed:
file: tests/_output/failed
coverage:
enabled: true
include:
- src/*
exclude:
- src/assetbundles/*
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/simplesharing",
"description": "Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.",
"type": "craft-plugin",
"version": "2.0.0",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -31,8 +31,9 @@
}
],
"require": {
"php": ">=8.0.0",
"craftcms/cms": "^4.0.0"
"php": "^8.2",
"craftcms/cms": "^5.0.0",
"vlucas/phpdotenv": "^5.6"
},
"repositories": [
{
Expand All @@ -56,9 +57,18 @@
"class": "wrav\\simplesharing\\SimpleSharing"
},
"config": {
"platform": {
"php": "8.2"
},
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
},
"require-dev": {
"phpunit/phpunit": "^11.4",
"codeception/module-yii2": "^1.1",
"codeception/module-phpbrowser": "^3.0",
"codeception/module-asserts": "^3.0"
}
}
2 changes: 1 addition & 1 deletion src/SimpleSharing.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 4.x
* SimpleSharing plugin for Craft CMS 5.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/simplesharing/SimpleSharingAsset.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 5.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 4.x
* SimpleSharing plugin for Craft CMS 5.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down Expand Up @@ -55,10 +55,10 @@ public function actionUrl(): string
$links = [
'facebook' => '<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . $encodedUrl . '">Facebook</a>',
'twitter' => '<a target="_blank" href="https://twitter.com/intent/tweet?text=' . $encodedUrl . '">Twitter</a>',
'linkedin' => '<a target="_blank" href="https://www.linkedin.com/sharing/share-offsite/?url=' . $encodedUrl . '">LinkedIn</a>',
'linkedin' => '<a target="_blank" href="https://www.linkedin.com/shareArticle?mini=true&title=&summary=&source=&url=' . $encodedUrl . '">LinkedIn</a>',
//'pinterest' => '<a target="_blank" href="http://pinterest.com/pin/create/link/?media=aaa&url=' . $encodedUrl . '">Pinterest</a>',
'mix' => '<a target="_blank" href="https://mix.com/add?url=' . $encodedUrl . '">Mix</a>',
'tumblr' => '<a target="_blank" href="https://www.tumblr.com/share/link?' . $encodedUrl . '">Tumblr</a>',
'tumblr' => '<a target="_blank" href="https://www.tumblr.com/share/link?url=' . $encodedUrl . '">Tumblr</a>',
'reddit' => '<a target="_blank" href="http://www.reddit.com/submit?url=' . $encodedUrl . '">Reddit</a>',
];

Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 4.x
* SimpleSharing plugin for Craft CMS 5.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down
2 changes: 1 addition & 1 deletion src/templates/settings.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{#
/**
* SimpleSharing plugin for Craft CMS 4.x
* SimpleSharing plugin for Craft CMS 5.x
*
* SimpleSharing Settings.twig
*
Expand Down
2 changes: 1 addition & 1 deletion src/variables/SimpleSharingVariable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 4.x
* SimpleSharing plugin for Craft CMS 5.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use craft\test\TestSetup;

ini_set('date.timezone', 'UTC');

// Use the current installation of Craft
define('CRAFT_TESTS_PATH', __DIR__);
define('CRAFT_STORAGE_PATH', __DIR__ . '/_craft/storage');
define('CRAFT_TEMPLATES_PATH', __DIR__ . '/_craft/templates');
define('CRAFT_CONFIG_PATH', __DIR__ . '/_craft/config');
define('CRAFT_MIGRATIONS_PATH', __DIR__ . '/_craft/migrations');
define('CRAFT_TRANSLATIONS_PATH', __DIR__ . '/_craft/translations');
define('CRAFT_VENDOR_PATH', dirname(__DIR__) . '/vendor');
define('CRAFT_ROOT_PATH', dirname(__DIR__));

$devMode = true;

TestSetup::configureCraft();
2 changes: 2 additions & 0 deletions tests/_craft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config/project/
storage/
5 changes: 5 additions & 0 deletions tests/_craft/config/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use craft\test\TestSetup;

return TestSetup::createTestCraftObjectConfig();
1 change: 1 addition & 0 deletions tests/_craft/templates/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Im a twig template and here's a random number {{ random() }}
Loading