Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
test:
name: Test (PHP ${{ matrix.php }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
run: composer install --no-interaction --prefer-dist

- name: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always

- name: Run PHPUnit tests with coverage
if: matrix.php == '8.1'
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov
if: matrix.php == '8.1'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests
name: codecov-php-${{ matrix.php }}
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

lint:
name: Lint (PHP ${{ matrix.php }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer, cs2pr

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install PHP dependencies
run: composer install --no-interaction --prefer-dist

- name: Run PHPCS
run: composer run-script lint
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
bower_components
release
vendor
includes/classes/Dependencies/**/Tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot undo this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the includes/classes/Dependencies/**/Tests pattern from .gitignore in commit 12f5cc8.

.idea
*.log

Expand Down Expand Up @@ -29,3 +30,7 @@ Thumbs.db
Desktop.ini
*.js.map
*.css.map

# PHPUnit
.phpunit.result.cache
coverage.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Powered Cache
=============

![Support Level](https://img.shields.io/badge/support-active-green.svg) [![Release Version](https://img.shields.io/wordpress/plugin/v/powered-cache?label=Release%20Version)](https://github.com/poweredcache/powered-cache/releases) ![WordPress tested up to version](https://img.shields.io/wordpress/plugin/tested/powered-cache?label=WordPress) ![Required PHP Version](https://img.shields.io/wordpress/plugin/required-php/powered-cache?label=PHP)
![Support Level](https://img.shields.io/badge/support-active-green.svg) [![Release Version](https://img.shields.io/wordpress/plugin/v/powered-cache?label=Release%20Version)](https://github.com/poweredcache/powered-cache/releases) ![WordPress tested up to version](https://img.shields.io/wordpress/plugin/tested/powered-cache?label=WordPress) ![Required PHP Version](https://img.shields.io/wordpress/plugin/required-php/powered-cache?label=PHP) [![CI](https://github.com/poweredcache/powered-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/poweredcache/powered-cache/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/poweredcache/powered-cache/branch/master/graph/badge.svg)](https://codecov.io/gh/poweredcache/powered-cache)

The most powerful caching and performance suite for WordPress. Easily Improve PageSpeed & Web Vitals Score.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests;

use PHPUnit\Framework\TestCase;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\CssSelectorConverter;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\Exception\ParseException;

class CssSelectorConverterTest extends TestCase
{
public function testCssToXPath()
{
$converter = new CssSelectorConverter();

$this->assertEquals('descendant-or-self::*', $converter->toXPath(''));
$this->assertEquals('descendant-or-self::h1', $converter->toXPath('h1'));
$this->assertEquals("descendant-or-self::h1[@id = 'foo']", $converter->toXPath('h1#foo'));
$this->assertEquals("descendant-or-self::h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", $converter->toXPath('h1.foo'));
$this->assertEquals('descendant-or-self::foo:h1', $converter->toXPath('foo|h1'));
$this->assertEquals('descendant-or-self::h1', $converter->toXPath('H1'));

// Test the cache layer
$converter = new CssSelectorConverter();
$this->assertEquals('descendant-or-self::h1', $converter->toXPath('H1'));
}

public function testCssToXPathXml()
{
$converter = new CssSelectorConverter(false);

$this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));

$converter = new CssSelectorConverter(false);
// Test the cache layer
$this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));
}

public function testParseExceptions()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Expected identifier, but <eof at 3> found.');
$converter = new CssSelectorConverter();
$converter->toXPath('h1:');
}

/** @dataProvider getCssToXPathWithoutPrefixTestData */
public function testCssToXPathWithoutPrefix($css, $xpath)
{
$converter = new CssSelectorConverter();

$this->assertEquals($xpath, $converter->toXPath($css, ''), '->parse() parses an input string and returns a node');
}

public static function getCssToXPathWithoutPrefixTestData()
{
return [
['h1', 'h1'],
['foo|h1', 'foo:h1'],
['h1, h2, h3', 'h1 | h2 | h3'],
['h1:nth-child(3n+1)', "*/*[(name() = 'h1') and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"],
['h1 > p', 'h1/p'],
['h1#foo', "h1[@id = 'foo']"],
['h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"],
['h1[class*="foo bar"]', "h1[@class and contains(@class, 'foo bar')]"],
['h1[foo|class*="foo bar"]', "h1[@foo:class and contains(@foo:class, 'foo bar')]"],
['h1[class]', 'h1[@class]'],
['h1 .foo', "h1/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"],
['h1 #foo', "h1/descendant-or-self::*/*[@id = 'foo']"],
['h1 [class*=foo]', "h1/descendant-or-self::*/*[@class and contains(@class, 'foo')]"],
['div>.foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"],
['div > .foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests\Node;

use PHPUnit\Framework\TestCase;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\NodeInterface;

abstract class AbstractNodeTestCase extends TestCase
{
/** @dataProvider getToStringConversionTestData */
public function testToStringConversion(NodeInterface $node, $representation)
{
$this->assertEquals($representation, (string) $node);
}

/** @dataProvider getSpecificityValueTestData */
public function testSpecificityValue(NodeInterface $node, $value)
{
$this->assertEquals($value, $node->getSpecificity()->getValue());
}

abstract public static function getToStringConversionTestData();

abstract public static function getSpecificityValueTestData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests\Node;

use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\AttributeNode;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\ElementNode;

class AttributeNodeTest extends AbstractNodeTestCase
{
public static function getToStringConversionTestData()
{
return [
[new AttributeNode(new ElementNode(), null, 'attribute', 'exists', null), 'Powered_Cache_Attribute[Element[*][attribute]]'],
[new AttributeNode(new ElementNode(), null, 'attribute', '$=', 'value'), "Powered_Cache_Attribute[Element[*][attribute $= 'value']]"],
[new AttributeNode(new ElementNode(), 'namespace', 'attribute', '$=', 'value'), "Powered_Cache_Attribute[Element[*][namespace|attribute $= 'value']]"],
];
}

public static function getSpecificityValueTestData()
{
return [
[new AttributeNode(new ElementNode(), null, 'attribute', 'exists', null), 10],
[new AttributeNode(new ElementNode(null, 'element'), null, 'attribute', 'exists', null), 11],
[new AttributeNode(new ElementNode(), null, 'attribute', '$=', 'value'), 10],
[new AttributeNode(new ElementNode(), 'namespace', 'attribute', '$=', 'value'), 10],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests\Node;

use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\ClassNode;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\ElementNode;

class ClassNodeTest extends AbstractNodeTestCase
{
public static function getToStringConversionTestData()
{
return [
[new ClassNode(new ElementNode(), 'class'), 'Class[Element[*].class]'],
];
}

public static function getSpecificityValueTestData()
{
return [
[new ClassNode(new ElementNode(), 'class'), 10],
[new ClassNode(new ElementNode(null, 'element'), 'class'), 11],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests\Node;

use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\CombinedSelectorNode;
use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\ElementNode;

class CombinedSelectorNodeTest extends AbstractNodeTestCase
{
public static function getToStringConversionTestData()
{
return [
[new CombinedSelectorNode(new ElementNode(), '>', new ElementNode()), 'CombinedSelector[Element[*] > Element[*]]'],
[new CombinedSelectorNode(new ElementNode(), ' ', new ElementNode()), 'CombinedSelector[Element[*] <followed> Element[*]]'],
];
}

public static function getSpecificityValueTestData()
{
return [
[new CombinedSelectorNode(new ElementNode(), '>', new ElementNode()), 0],
[new CombinedSelectorNode(new ElementNode(null, 'element'), '>', new ElementNode()), 1],
[new CombinedSelectorNode(new ElementNode(null, 'element'), '>', new ElementNode(null, 'element')), 2],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PoweredCache\Dependencies\Symfony\Component\CssSelector\Tests\Node;

use PoweredCache\Dependencies\Symfony\Component\CssSelector\Node\ElementNode;

class ElementNodeTest extends AbstractNodeTestCase
{
public static function getToStringConversionTestData()
{
return [
[new ElementNode(), 'Element[*]'],
[new ElementNode(null, 'element'), 'Element[element]'],
[new ElementNode('namespace', 'element'), 'Element[namespace|element]'],
];
}

public static function getSpecificityValueTestData()
{
return [
[new ElementNode(), 0],
[new ElementNode(null, 'element'), 1],
[new ElementNode('namespace', 'element'), 1],
];
}
}
Loading
Loading