Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularyan committed Mar 21, 2016
1 parent 9c6b566 commit 5c8d2ab
Show file tree
Hide file tree
Showing 27 changed files with 3,762 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
language: php

notifications:
email:
on_success: never
on_failure: change

services:
- mysql

php:
- 5.6

env:
- WP_VERSION=latest WP_MULTISITE=0

# before_install:
# - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
# - openssl aes-256-cbc -K $encrypted_ffa6df0139c0_key -iv $encrypted_ffa6df0139c0_iv -in git_key.txt.enc -out git_key -d

install:
- wget http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar

before_script:
- sudo apt-get update
- sudo apt-get install apache2 libapache2-mod-fastcgi
# enable php-fpm
- sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
- sudo a2enmod rewrite actions fastcgi alias
- echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
# configure apache virtual hosts
- echo "$(curl -fsSL https://gist.github.com/rahularyan/5b179508f63cebbce486/raw/gistfile1.txt)" | sed -e "s,PATH,`pwd`/www,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
- echo "127.0.0.1 wptest.localhost" | sudo tee -a /etc/hosts
- sudo service apache2 restart
- sudo apt-get install git
- wget http://codeception.com/codecept.phar
- sudo curl -LsS http://codeception.com/codecept.phar -o /usr/local/bin/codecept
- sudo chmod a+x /usr/local/bin/codecept
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- java -jar selenium-server-standalone-2.42.2.jar -port 4444 -Djava.security.egd=file:///dev/urandom switch > /dev/null &
- sleep 5
- bash tests/bin/install.sh wptest root '' localhost $WP_VERSION

script: codecept run --steps

after_failure:
- bash tests/bin/upload.sh


27 changes: 27 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
coverage:
enabled: true
exclude:
- tests/*
- node_modules/*
- build/*
2 changes: 2 additions & 0 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// This is global bootstrap for autoloading
1 change: 1 addition & 0 deletions tests/_data/dump.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Replace this file with actual dump of your database */
2 changes: 2 additions & 0 deletions tests/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
110 changes: 110 additions & 0 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php


/**
* Inherited Methods
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;

public $admin_username = 'admin';
public $admin_password = 'admin';
public $users = array( 'user1', 'user2', 'user3', 'user4' );
public $questions = array( 'question1' => 'This is question 1' );
public $answers = array(
'answer1' => 'This is an interesting answer on question 1. Hope this will work.',
'answer2' => 'This is an interesting question again for question 1. Hope this will work as well.',
);
public $comment = array(
'comment1' => 'This is an awesome comment on question1. I like it. Nam hendrerit lacinia vulputate.',
'comment2' => 'This is an awesome comment on answer1. I like it.',
'comment3' => 'This is an awesome comment on answer1 again.. Maann..!! its gonna be super cool.',
);

/**
* Login a user by user login and password.
* @param string $name User login.
* @param string $password User password.
*/
public function login($name, $password) {
$this->amOnPage('/wp-login.php' );
$this->fillField('Username', $name );
$this->fillField('Password', $password );
$this->click('Log In' );
//$this->see('Welcome to WordPress!' );
}

/**
* Login as an admin
*/
public function loginAsAdmin() {
$this->login($this->admin_username, $this->admin_password );
}

/**
* Switch logged in user.
* @param string $name User login.
* @param string $password User password.
*/
public function switch_user( $name, $password ) {
//$this->amOnPage('/wp-admin' );
//$loutput_button = $I->executeJS('return jQuery(".wp-admin-bar-logout").length > 0');
//concept_debug($loutput_button);
/*if ( $loutput_button ) {
$this->click( 'Log Out', '.ab-item' );
}*/
$this->login( $name, $password );
}

public function amOnPluginPage() {
$this->amOnPage('/wp-admin/plugins.php' );
}

public function fillTinyMceEditorById($id, $content) {
$this->fillTinyMceEditor('id', $id, $content );
}

public function fillTinyMceEditorByName($name, $content) {
$this->fillTinyMceEditor('name', $name, $content );
}

private function fillTinyMceEditor($attribute, $value, $content) {
$this->fillRteEditor(
\Facebook\WebDriver\WebDriverBy::xpath(
'//textarea[@' . $attribute . '=\'' . $value . '\']/../div[contains(@class, \'mce-tinymce\')]//iframe'
),
$content
);
}

private function fillRteEditor($selector, $content) {
$this->executeInSelenium(
function (\Facebook\WebDriver\Remote\RemoteWebDriver $webDriver)
use ($selector, $content) {
$webDriver->switchTo()->frame(
$webDriver->findElement($selector )
);

$webDriver->executeScript(
'arguments[0].innerHTML = "' . addslashes($content ) . '"',
[ $webDriver->findElement(\Facebook\WebDriver\WebDriverBy::tagName('body' ) ) ]
);

$webDriver->switchTo()->defaultContent();
});
}
}
26 changes: 26 additions & 0 deletions tests/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;

/**
* Define custom actions here
*/
}
10 changes: 10 additions & 0 deletions tests/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Acceptance extends \Codeception\Module
{

}
10 changes: 10 additions & 0 deletions tests/_support/Helper/Functional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Functional extends \Codeception\Module
{

}
10 changes: 10 additions & 0 deletions tests/_support/Helper/Unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Unit extends \Codeception\Module
{

}
26 changes: 26 additions & 0 deletions tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
}
Loading

0 comments on commit 5c8d2ab

Please sign in to comment.