Skip to content

Commit

Permalink
Merge pull request #142 from timber/2.x-fix-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr authored Jul 31, 2023
2 parents 1254c2f + 244d315 commit 186eca6
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gitattributes export-ignore
/.github export-ignore
83 changes: 83 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Timber starter theme tests

on:
push:
branches:
- '1.x'
- '2.x'
pull_request:
types:
- opened
- synchronize
- ready_for_review

# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
phpunit:
runs-on: ubuntu-latest

continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
wp: ['latest']
multisite: ['0', '1']
extensions: ['gd']
experimental: [false]
include:
# WP Trunk
- php: '7.4'
wp: 'trunk'
multisite: '0'
experimental: true
# PHP 8.0
- php: '8.0'
wp: 'latest'
multisite: '0'
experimental: false
# PHP 8.1
- php: '8.1'
wp: 'latest'
multisite: '0'
experimental: false
# PHP 8.1 / experimental
- php: '8.1'
wp: 'trunk'
multisite: '0'
experimental: true
# PHP 8.2 / experimental
- php: '8.2'
wp: 'trunk'
multisite: '0'
experimental: true

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
extensions: curl, date, dom, iconv, json, libxml, gd

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- uses: ramsey/composer-install@v2

- name: Run tests
run: composer run test
env:
WP_MULTISITE: ${{ matrix.multisite }}
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"description": "Starter theme to build a Timber theme",
"type":"wordpress-theme",
"license": "MIT",
"minimum-stability" : "dev",
"authors": [
{
"email": "[email protected]",
Expand All @@ -20,9 +19,8 @@
"timber/timber": "2.x-dev"
},
"require-dev": {
"phpunit/phpunit": "7.*",
"roots/wordpress": "^5.4",
"automattic/wordbless": "^0.1.0"
"automattic/wordbless": "^0.4.2",
"yoast/wp-test-utils": "^1.0"
},
"extra": {
"installer-paths": {
Expand All @@ -31,5 +29,14 @@
]
},
"wordpress-install-dir": "wordpress"
},
"config": {
"allow-plugins": {
"roots/wordpress-core-installer": true,
"composer/installers": true
}
},
"scripts": {
"test": "phpunit"
}
}
41 changes: 4 additions & 37 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,24 @@
/**
* Timber starter-theme
* https://github.com/timber/starter-theme
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

/**
* If you are installing Timber as a Composer dependency in your theme, you'll need this block
* to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org
* plug-in, you can safely delete this block.
*/
$composer_autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $composer_autoload ) ) {
require_once $composer_autoload;
Timber\Timber::init();
}
// Load Composer dependencies.
require_once __DIR__ . '/vendor/autoload.php';

/**
* This ensures that Timber is loaded and available as a PHP class.
* If not, it gives an error message to help direct developers on where to activate
*/
if ( ! class_exists( 'Timber' ) ) {

add_action(
'admin_notices',
function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
}
);

add_filter(
'template_include',
function( $template ) {
return get_stylesheet_directory() . '/static/no-timber.html';
}
);
return;
}
Timber\Timber::init();

/**
* Sets the directories (inside your theme) to find .twig files
*/
Timber::$dirname = array( '../views' );
Timber::$dirname = [ 'templates', 'views' ];

/**
* By default, Timber does NOT autoescape values. Want to enable Twig's autoescape?
* No prob! Just set this value to true
*/
Timber::$autoescape = false;


/**
* We're going to configure our theme inside of a subclass of Timber\Site
* You can move this to its own file and include here via php's include("MySite.php")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
<?php

class TestTimberStarterTheme extends \WorDBless\BaseTestCase {
use Timber\Timber;
use WorDBless\BaseTestCase;

function setUp() {
self::_setupStarterTheme();
class TestTimberStarterTheme extends BaseTestCase {

public function set_up() {
switch_theme( basename( dirname( __DIR__ ) ) . '/theme' );
require_once dirname( __DIR__ ) . '/functions.php';

require dirname( __DIR__ ) . '/functions.php';

Timber::$dirname = array_merge( (array) Timber::$dirname, [ '../views' ] );
Timber::$dirname = array_unique( Timber::$dirname );

// WorDBless includes wp-settings.php
do_action( 'after_setup_theme' );

parent::set_up();
}

function tearDown() {
switch_theme('twentythirteen');
function tear_down() {
parent::tear_down();
switch_theme('twentytwenty');
}

function testTimberExists() {
Expand All @@ -36,21 +46,11 @@ function testLoading() {
* Helper test to output current twig version
*/
function testTwigVersion() {
$str = Timber::compile_string("{{ constant('Twig_Environment::VERSION') }}");
//error_log('Twig version = '.$str);
// $version = Timber::compile_string("{{ version }}", [ 'version', Twig\Environment::VERSION ]);
}

function testTwigFilter() {
$str = Timber::compile_string('{{ "foo" | myfoo }}');
$str = Timber::compile_string('{{ "foo"|myfoo }}');
$this->assertEquals('foo bar!', $str);
}

static function _setupStarterTheme(){
$baseName = basename( dirname( __DIR__ ) );
$src = realpath( dirname( dirname( __DIR__ ) ) . '/' . $baseName );
$dest = WP_CONTENT_DIR . '/themes/' . $baseName;
if ( is_dir($src) && ! file_exists($dest) ) {
symlink($src, $dest);
}
}
}
20 changes: 19 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
<?php

use WorDBless\Load;

if (! file_exists( dirname(__DIR__) . '/wordpress/wp-content')) {
mkdir(dirname(__DIR__) . '/wordpress/wp-content');
}

if (! file_exists(dirname(__DIR__) . '/wordpress/wp-content/themes')) {
mkdir(dirname(__DIR__) . '/wordpress/wp-content/themes');
}

copy(
dirname( __DIR__ ) . '/vendor/automattic/wordbless/src/dbless-wpdb.php',
dirname( __DIR__ ) . '/wordpress/wp-content/db.php'
);

$theme_base_name = basename( dirname( __DIR__ ) );
$src = realpath( dirname( dirname( __DIR__ ) ) . '/' . $theme_base_name );
$dest = dirname( __DIR__ ) . '/wordpress/wp-content/themes/' . $theme_base_name;

if ( is_dir($src) && ! file_exists($dest) ) {
symlink($src, $dest);
}

require_once dirname( __DIR__ ) . '/vendor/autoload.php';

\WorDBless\Load::load();
Load::load();

0 comments on commit 186eca6

Please sign in to comment.