Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lucatume/idlikethis
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	composer.lock
#	tests/_data/dump.sql
#	tests/_support/_generated/AcceptanceTesterActions.php
#	tests/_support/_generated/FunctionalTesterActions.php
#	tests/_support/_generated/IntegrationTesterActions.php
#	tests/_support/_generated/UnitTesterActions.php
#	tests/integration/idlikethis/MetaBoxes/VotesDisplayMetaBoxTest.php
  • Loading branch information
lucatume committed Nov 10, 2016
2 parents c10e7be + 4c9b1a4 commit a029b7d
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 86 deletions.
72 changes: 72 additions & 0 deletions .travis.yml
@@ -0,0 +1,72 @@
sudo: required

language: php

notifications:
email: false

php:
- '5.6'
- '7.0'

services:
- mysql

cache:
directories:
- vendor
- $HOME/.composer/cache

env:
- wpDbName=test wpLoaderDbName=wploader wpDbPrefix=wp_ wpUrl=wordpress.dev wpAdminUsername=admin wpAdminPassword=admin

before_install:
- mysql -e "create database IF NOT EXISTS $wpDbName;" -uroot
- mysql -e "create database IF NOT EXISTS $wpLoaderDbName;" -uroot

install:
- composer update --prefer-dist

before_script:
# set up folders
- mkdir -p $HOME/tools /tmp/wordpress

# install wp-cli
- wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -P /tmp/tools/
- chmod +x /tmp/tools/wp-cli.phar && mv /tmp/tools/wp-cli.phar /tmp/tools/wp
- export PATH=$PATH:/tmp/tools:vendor/bin

# install Apache and WordPress setup scripts
- git clone https://github.com/lucatume/travis-apache-setup.git /tmp/tools/travis-apache-setup
- chmod +x /tmp/tools/travis-apache-setup/apache-setup.sh
- chmod +x /tmp/tools/travis-apache-setup/wp-install.sh
- ln -s /tmp/tools/travis-apache-setup/apache-setup.sh /tmp/tools/apache-setup
- ln -s /tmp/tools/travis-apache-setup/wp-install.sh /tmp/tools/wp-install

# download and install WordPress
- wp-install --dir=/tmp/wordpress --dbname="$wpDbName" --dbuser="root" --dbpass="" --dbprefix=wp_ --domain="wordpress.dev" --title="Test" --admin_user=admin --admin_password=admin --admin_email=admin@wordpress.dev --theme=twentysixteen --empty
- cd /tmp/wordpress

# move the plugin into WordPress folder
- mv $TRAVIS_BUILD_DIR /tmp/wordpress/wp-content/plugins/idlikethis
- export PLUGIN_DIR="/tmp/wordpress/wp-content/plugins/idlikethis"

# activate the plugin in WordPress
- wp plugin activate idlikethis

# flush rewrite rules
- printf "apache_modules:\n\t- mod_rewrite" > /tmp/wordpress/wp-cli.yml
- wp rewrite structure '/%postname%/' --hard

# export a dump of the just installed database to the _data folder
- cd /tmp/wordpress
- wp db export $PLUGIN_DIR/tests/_data/dump.sql

# set up Apache virtual host
- sudo env "PATH=$PATH" apache-setup --host="127.0.0.1" --url="$wpUrl" --dir="/tmp/wordpress"

# Get back to the plugin dir
- cd $PLUGIN_DIR

script:
- codecept run -vvv
2 changes: 2 additions & 0 deletions README.md
@@ -1,5 +1,7 @@
# I'd like this

![Travis CI Build Status](https://travis-ci.org/lucatume/idlikethis.svg?branch=master)

*Add an "I'd like this" button anywhere in a WordPress post and get user feedback on your ideas, proposals and plans.*

This plugin was built to give a concrete example of [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection "Dependency injection - Wikipedia, the free encyclopedia") usage in WordPress with [DI52](https://github.com/lucatume/DI52) and test-driven development using [Codeception](http://codeception.com/ "Codeception - BDD-style PHP testing.") and [wp-browser](https://github.com/lucatume/wp-browser "lucatume/wp-browser · GitHub")
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion src/idlikethis/MetaBoxes/VotesDisplayMetaBox.php
Expand Up @@ -27,7 +27,11 @@ class idlikethis_MetaBoxes_VotesDisplayMetaBox implements idlikethis_MetaBoxes_V
*/
protected $template_data;

public function __construct(idlikethis_Repositories_VotesRepositoryInterface $comments_repository, idlikethis_Templates_RenderEngineInterface $render_engine, idlikethis_Texts_VotesMetaBoxTextProviderInterface $texts)
public function __construct(
idlikethis_Repositories_VotesRepositoryInterface $comments_repository,
idlikethis_Templates_RenderEngineInterface $render_engine,
idlikethis_Texts_VotesMetaBoxTextProviderInterface $texts
)
{
$this->comments_repository = $comments_repository;
$this->render_engine = $render_engine;
Expand Down
3 changes: 1 addition & 2 deletions tests/_support/Helper/Integration.php
Expand Up @@ -4,7 +4,6 @@
// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Integration extends \Codeception\Module
{
class Integration extends \Codeception\Module {

}
25 changes: 25 additions & 0 deletions tests/acceptance.suite.dist.yml
@@ -0,0 +1,25 @@
# Codeception Test Suite Configuration

# suite for WordPress acceptance tests.
# perform tests in browser using WPBrowser or WPWebDriver modules.
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- WPBrowser
- WPDb
config:
WPBrowser:
url: 'http://wordpress.dev'
adminUsername: admin
adminPassword: admin
adminUrl: /wp-admin
WPDb:
dsn: 'mysql:host=localhost;dbname=test'
user: root
password: ''
dump: tests/_data/dump.sql
populate: true
cleanup: true
url: 'http://wordpress.dev'
tablePrefix: wp_
17 changes: 0 additions & 17 deletions tests/acceptance.suite.yml

This file was deleted.

31 changes: 31 additions & 0 deletions tests/acceptance/frontend/ShortcodeCest.php
@@ -0,0 +1,31 @@
<?php
namespace acceptance\frontend;

class ShortcodeCest {

/**
* @test
* it should render simple shortcode
*/
public function it_should_render_simple_shortcode(\AcceptanceTester $I) {
$content = 'Lorem ipsum [idlikethis]';
$I->havePostInDatabase(['post_name' => 'foo', 'post_content' => $content]);

$I->amOnPage('/foo');
$text = "I'd like this";
$I->seeElement('.idlikethis-button[data-text="' . $text . '"] button');
}

/**
* @test
* it should render extended shortcode
*/
public function it_should_render_extended_shortcode(\AcceptanceTester $I) {
$content = 'Lorem ipsum [idlikethis]Some idea of mine[/idlikethis]';
$I->havePostInDatabase(['post_name' => 'foo', 'post_content' => $content]);

$I->amOnPage('/foo');
$text = "Some idea of mine";
$I->seeElement('.idlikethis-button[data-text="' . $text . '"] button');
}
}
17 changes: 10 additions & 7 deletions tests/functional.suite.yml → tests/functional.suite.dist.yml
Expand Up @@ -5,18 +5,21 @@
class_name: FunctionalTester
modules:
enabled:
- WPDb:
dsn: 'mysql:host=127.0.0.1;dbname=wp'
- WPDb
- WordPress
- \Helper\Functional
config:
WPDb:
dsn: 'mysql:host=localhost;dbname=test'
user: root
password: root
password: ''
dump: tests/_data/dump.sql
populate: true
cleanup: true
url: 'http://wp.dev'
url: 'http://wordpress.dev'
tablePrefix: wp_
- WordPress:
WordPress:
depends: WPDb
wpRootFolder: "/Users/Luca/Sites/wp"
wpRootFolder: "/tmp/wordpress"
adminUsername: 'admin'
adminPassword: 'admin'
- \Helper\Functional
16 changes: 8 additions & 8 deletions tests/functional/frontend/ShortcodeCest.php
Expand Up @@ -7,25 +7,25 @@ class ShortcodeCest {
* @test
* it should render simple shortcode
*/
public function it_should_render_simple_shortcode( \FunctionalTester $I ) {
public function it_should_render_simple_shortcode(\FunctionalTester $I) {
$content = 'Lorem ipsum [idlikethis]';
$post_id = $I->havePostInDatabase( [ 'post_title' => 'Some title', 'post_content' => $content ] );
$post_id = $I->havePostInDatabase(['post_name' => 'foo', 'post_content' => $content]);

$I->amOnPage( '/' );
$I->amOnPage('/foo');
$text = "I'd like this";
$I->seeElement( '.idlikethis-button[data-post-id="' . $post_id . '"][data-text="' . $text . '"] button' );
$I->seeElement('.idlikethis-button[data-post-id="' . $post_id . '"][data-text="' . $text . '"] button');
}

/**
* @test
* it should render extended shortcode
*/
public function it_should_render_extended_shortcode( \FunctionalTester $I ) {
public function it_should_render_extended_shortcode(\FunctionalTester $I) {
$content = 'Lorem ipsum [idlikethis]Some idea of mine[/idlikethis]';
$post_id = $I->havePostInDatabase( [ 'post_title' => 'Some title', 'post_content' => $content ] );
$post_id = $I->havePostInDatabase(['post_name' => 'foo', 'post_content' => $content]);

$I->amOnPage( '/' );
$I->amOnPage('/foo');
$text = "Some idea of mine";
$I->seeElement( '.idlikethis-button[data-post-id="' . $post_id . '"][data-text="' . $text . '"] button' );
$I->seeElement('.idlikethis-button[data-post-id="' . $post_id . '"][data-text="' . $text . '"] button');
}
}
82 changes: 41 additions & 41 deletions tests/functional/rest/ResetAllPostRequestCest.php
Expand Up @@ -8,87 +8,87 @@ class ResetAllPostRequestCest {
* @test
* it should not reset comments if post id is missing from POST request
*/
public function it_should_not_reset_comments_if_post_id_is_missing_from_post_request( \FunctionalTester $I ) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase( 3, $post_id, [ 'comment_type' => 'idlikethis' ] );
public function it_should_not_reset_comments_if_post_id_is_missing_from_post_request(\FunctionalTester $I) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase(3, $post_id, ['comment_type' => 'idlikethis']);

$I->loginAsAdmin();
$I->amEditingPostWithId( $post_id );
$I->amEditingPostWithId($post_id);

$wp_rest_nonce = $I->grabValueFrom( 'input[name="rest_nonce"]' );
$I->haveHttpHeader( 'X-WP-Nonce', $wp_rest_nonce );
$wp_rest_nonce = $I->grabValueFrom('input[name="rest_nonce"]');
$I->haveHttpHeader('X-WP-Nonce', $wp_rest_nonce);

$I->sendAjaxPostRequest( '/wp-json/idlikethis/v1/admin/reset-all', [
] );
$I->sendAjaxPostRequest('/wp-json/idlikethis/v1/admin/reset-all', [
]);

$I->seeResponseCodeIs( 400 );
foreach ( $comment_ids as $comment_id ) {
$I->seeCommentInDatabase( [ 'comment_ID' => $comment_id, 'comment_post_ID' => $post_id ] );
$I->seeResponseCodeIs(400);
foreach ($comment_ids as $comment_id) {
$I->seeCommentInDatabase(['comment_ID' => $comment_id, 'comment_post_ID' => $post_id]);
}
}

/**
* @test
* it should not reset comments if post id is not valid
*/
public function it_should_not_reset_comments_if_post_id_is_not_valid( \FunctionalTester $I ) {
public function it_should_not_reset_comments_if_post_id_is_not_valid(\FunctionalTester $I) {
$post_id = $I->havePostInDatabase();

$I->loginAsAdmin();
$I->amEditingPostWithId( $post_id );
$I->amEditingPostWithId($post_id);

$wp_rest_nonce = $I->grabValueFrom( 'input[name="rest_nonce"]' );
$I->haveHttpHeader( 'X-WP-Nonce', $wp_rest_nonce );
$wp_rest_nonce = $I->grabValueFrom('input[name="rest_nonce"]');
$I->haveHttpHeader('X-WP-Nonce', $wp_rest_nonce);

$I->sendAjaxPostRequest( '/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => 3344
] );
$I->sendAjaxPostRequest('/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => 3344,
]);

$I->seeResponseCodeIs( 400 );
$I->seeResponseCodeIs(400);
}

/**
* @test
* it should not reset comments if user cannot edit posts
*/
public function it_should_not_reset_comments_if_user_cannot_edit_posts( \FunctionalTester $I ) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase( 3, $post_id, [ 'comment_type' => 'idlikethis' ] );
public function it_should_not_reset_comments_if_user_cannot_edit_posts(\FunctionalTester $I) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase(3, $post_id, ['comment_type' => 'idlikethis']);

$I->loginAsAdmin();
$I->amEditingPostWithId( $post_id );
$I->amEditingPostWithId($post_id);

$I->sendAjaxPostRequest( '/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => $post_id
] );
$I->sendAjaxPostRequest('/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => $post_id,
]);

$I->seeResponseCodeIs( 403 );
foreach ( $comment_ids as $comment_id ) {
$I->seeCommentInDatabase( [ 'comment_ID' => $comment_id, 'comment_post_ID' => $post_id ] );
$I->seeResponseCodeIs(403);
foreach ($comment_ids as $comment_id) {
$I->seeCommentInDatabase(['comment_ID' => $comment_id, 'comment_post_ID' => $post_id]);
}
}

/**
* @test
* it should reset comments when post id is valid
*/
public function it_should_reset_comments_when_post_id_is_valid( \FunctionalTester $I ) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase( 3, $post_id, [ 'comment_type' => 'idlikethis' ] );
public function it_should_reset_comments_when_post_id_is_valid(\FunctionalTester $I) {
$post_id = $I->havePostInDatabase();
$comment_ids = $I->haveManyCommentsInDatabase(3, $post_id, ['comment_type' => 'idlikethis']);

$I->loginAsAdmin();
$I->amEditingPostWithId( $post_id );
$I->amEditingPostWithId($post_id);

$wp_rest_nonce = $I->grabValueFrom( 'input[name="rest_nonce"]' );
$I->haveHttpHeader( 'X-WP-Nonce', $wp_rest_nonce );
$wp_rest_nonce = $I->grabValueFrom('input[name="rest_nonce"]');
$I->haveHttpHeader('X-WP-Nonce', $wp_rest_nonce);

$I->sendAjaxPostRequest( '/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => $post_id
] );
$I->sendAjaxPostRequest('/wp-json/idlikethis/v1/admin/reset-all', [
'post_id' => $post_id,
]);

$I->seeResponseCodeIs( 200 );
foreach ( $comment_ids as $comment_id ) {
$I->dontSeeCommentInDatabase( [ 'comment_ID' => $comment_id, 'comment_post_ID' => $post_id ] );
$I->seeResponseCodeIs(200);
foreach ($comment_ids as $comment_id) {
$I->dontSeeCommentInDatabase(['comment_ID' => $comment_id, 'comment_post_ID' => $post_id]);
}
}
}

0 comments on commit a029b7d

Please sign in to comment.