Skip to content

Commit

Permalink
Merge pull request #37 from bigbite/release/0.6.0
Browse files Browse the repository at this point in the history
Release 0.6.0
  • Loading branch information
Liam Defty authored Jul 8, 2020
2 parents 845e005 + 837f27d commit 3fe0504
Show file tree
Hide file tree
Showing 39 changed files with 642 additions and 402 deletions.
33 changes: 0 additions & 33 deletions bin/postinstall.sh

This file was deleted.

15 changes: 15 additions & 0 deletions example-seeds/DefaultSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use WP_Cypress\Seeder\Seeder;
use WP_Cypress\Fixtures;

class DefaultSeeder extends Seeder {
public function run() {
( new Fixtures\Post() )->create( 3 );

$this->call([
'ExampleSeeder',
]);
}
}

31 changes: 31 additions & 0 deletions example-seeds/ExampleCommentFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use WP_Cypress\Fixtures\Fixture;
use WP_Cypress\Utils;

class ExampleCommentFixture extends Fixture {
/**
* Gets default values of the comment.
*
* @return array
*/
public function defaults(): array {
return [
'comment_post_ID' => 1,
'comment_author' => 'admin',
'comment_author_email' => '[email protected]',
'comment_content' => 'This is an example comment fixture',
'user_id' => 1,
'comment_date' => Utils\now(),
];
}

/**
* Generates a comment record.
*
* @return void
*/
public function generate(): void {
$id = (int) wp_insert_comment( array_merge( $this->defaults(), $this->properties ) );
}
}
16 changes: 16 additions & 0 deletions example-seeds/ExampleSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use WP_Cypress\Seeder\Seeder;
use WP_Cypress\Fixtures;

class ExampleSeeder extends Seeder {
public function run() {
( new Fixtures\Post([
'import_id' => 10,
'post_title' => 'Post with Custom Comments',
]) )->create();

( new ExampleCommentFixture( [ 'comment_post_ID' => 10 ] ) )->create( 10 );
}
}

13 changes: 10 additions & 3 deletions lib/cli/modules/configureWordPress.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ const configureWordPress = async (config, logFile) => {
}

await run(
async () => wpcli('seed Init', logFile),
'Seeding database',
'Database seeded',
async () => wpcli('seed DefaultUsers', logFile),
'Creating default users',
'Default users created',
logFile,
);

await run(
async () => wpcli('seed DefaultSeeder', logFile),
'Running default seeder',
'Default seeder successfully ran',
logFile,
);
};
Expand Down
14 changes: 13 additions & 1 deletion lib/cli/modules/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const glob = require('glob');
Expand All @@ -14,6 +15,7 @@ const defaultConfig = {
config: {},
port: false,
timezone: false,
seedsPath: 'cypress/seeds',
};

const createConfig = async (userConfig, dir) => {
Expand All @@ -22,12 +24,22 @@ const createConfig = async (userConfig, dir) => {
...userConfig,
};

const seedsDir = `${process.cwd()}/${config.seedsPath}`;

if (!fs.existsSync(seedsDir)) {
shell.mkdir('-p', seedsDir);

fs.copyFileSync(`${dir}/example-seeds/DefaultSeeder.php`, `${seedsDir}/DefaultSeeder.php`);
fs.copyFileSync(`${dir}/example-seeds/ExampleCommentFixture.php`, `${seedsDir}/ExampleCommentFixture.php`);
fs.copyFileSync(`${dir}/example-seeds/ExampleSeeder.php`, `${seedsDir}/ExampleSeeder.php`);
}

const volumes = [
`${dir}/config.json:/var/www/html/config.json`,
`${dir}/config/php.ini:/usr/local/etc/php/php.ini`,
`${dir}/config/.htaccess:/var/www/html/.htaccess`,
`${dir}/plugin:/var/www/html/wp-content/plugins/wp-cypress`,
`${process.cwd()}/cypress/seeds:/var/www/html/seeds`,
`${seedsDir}:/var/www/html/seeds`,
];

const plugins = [];
Expand Down
7 changes: 7 additions & 0 deletions lib/cypress-support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const commands = {
saveCurrentPost() {
cy.window().then((win) => win.wp.data.dispatch('core/editor').savePost());
},

switchUser(user = 'admin', password = 'password') {
cy.visit('/wp-login.php');
cy.get('#user_login').clear().type(user);
cy.get('#user_pass').clear().type(password);
cy.get('#wp-submit').click();
},
};

Object.keys(commands).forEach((command) => {
Expand Down
4 changes: 4 additions & 0 deletions lib/cypress-support/hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable no-param-reassign */
let fetchPolyfill;

Cypress.Cookies.defaults({
whitelist: /wordpress_.*/,
});

Cypress.wp = {};

before(() => {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigbite/wp-cypress",
"version": "0.5.4",
"version": "0.6.0",
"description": "WordPress end to end testing with Cypress.io",
"repository": "https://github.com/bigbite/wp-cypress",
"author": {
Expand All @@ -16,8 +16,7 @@
"wp-cypress": "./bin/script.js"
},
"scripts": {
"lint:scripts": "eslint \"lib/**/*.js\" \"bin/**/*.js\" \"plugin/**/*.js\"",
"postinstall": "./bin/postinstall.sh"
"lint:scripts": "eslint \"lib/**/*.js\" \"bin/**/*.js\" \"plugin/**/*.js\""
},
"husky": {
"hooks": {
Expand Down
43 changes: 0 additions & 43 deletions plugin/Seeder/Command.php

This file was deleted.

34 changes: 0 additions & 34 deletions plugin/Seeder/Generator.php

This file was deleted.

26 changes: 0 additions & 26 deletions plugin/Seeder/Seeder.php

This file was deleted.

30 changes: 0 additions & 30 deletions plugin/Seeder/Seeds/Comment.php

This file was deleted.

19 changes: 0 additions & 19 deletions plugin/Seeder/Seeds/Seed.php

This file was deleted.

9 changes: 0 additions & 9 deletions plugin/Seeder/Seeds/SeedInterface.php

This file was deleted.

10 changes: 0 additions & 10 deletions plugin/Seeder/Traits/Date.php

This file was deleted.

Loading

0 comments on commit 3fe0504

Please sign in to comment.