-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run the E2E tests as a user with the author role #11359
Changes from all commits
bd386ab
7edbe39
6e28fe4
b3cfeb2
51f21a9
88b4bd8
536c7b4
6f2a49f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,13 @@ echo -e $(status_message "Installing WordPress...") | |
# prevents permissions errors. See: https://github.com/WordPress/gutenberg/pull/8427#issuecomment-410232369 | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password [email protected] --skip-email --url=http://localhost:$HOST_PORT >/dev/null | ||
|
||
if [ "$E2E_ROLE" = "author" ]; then | ||
# Create an additional author user for testsing. | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI user create author [email protected] --role=author --user_pass=authpass | ||
# Assign the existing Hello World post to the author. | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI post update 1 --post_author=2 | ||
fi | ||
|
||
if [ "$WP_VERSION" == "latest" ]; then | ||
# Check for WordPress updates, to make sure we're running the very latest version. | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI core update >/dev/null | ||
|
@@ -69,3 +76,6 @@ fi | |
# Activate Gutenberg. | ||
echo -e $(status_message "Activating Gutenberg...") | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CLI plugin activate gutenberg >/dev/null | ||
|
||
# Install a dummy favicon to avoid 404 errors. | ||
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER touch /var/www/html/favicon.ico |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,8 @@ cd "$(dirname "$0")/../" | |
# Setup local environement | ||
( ./bin/setup-local-env.sh ) | ||
|
||
# Run the tests | ||
npm run test-e2e | ||
if [ "$E2E_ROLE" = "author" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the role we want to use could be passed to the script rather than hardcoding an "author-or-admin" choice, but if you want to do that as a follow-up it's fine with me 😄 (It would also let you avoid the if/else here, and instead just pass the role we want, with "admin" being the default. 🤷♂️) |
||
WP_PASSWORD=authpass WP_USERNAME=author npm run test-e2e | ||
else | ||
npm run test-e2e | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ import { | |
ToggleControl, | ||
Toolbar, | ||
} from '@wordpress/components'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { dateI18n, format, __experimentalGetSettings } from '@wordpress/date'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
@@ -27,15 +29,46 @@ import { | |
} from '@wordpress/editor'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Module Constants | ||
*/ | ||
const CATEGORIES_LIST_QUERY = { | ||
per_page: 100, | ||
}; | ||
const MAX_POSTS_COLUMNS = 6; | ||
|
||
class LatestPostsEdit extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.state = { | ||
categoriesList: [], | ||
}; | ||
this.toggleDisplayPostDate = this.toggleDisplayPostDate.bind( this ); | ||
} | ||
|
||
componentWillMount() { | ||
this.isStillMounted = true; | ||
this.fetchRequest = apiFetch( { | ||
path: addQueryArgs( `/wp/v2/categories`, CATEGORIES_LIST_QUERY ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this need to iterate the entire list? What if I have 102 categories? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷♀️ this is just how it was in the original code, I was just fixing it so that it didn't break for authors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I'll mention on #10873 and we can resolve with that. |
||
} ).then( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if this request fails? We don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a |
||
( categoriesList ) => { | ||
if ( this.isStillMounted ) { | ||
this.setState( { categoriesList } ); | ||
} | ||
} | ||
).catch( | ||
() => { | ||
if ( this.isStillMounted ) { | ||
this.setState( { categoriesList: [] } ); | ||
} | ||
} | ||
); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.isStillMounted = false; | ||
} | ||
|
||
toggleDisplayPostDate() { | ||
const { displayPostDate } = this.props.attributes; | ||
const { setAttributes } = this.props; | ||
|
@@ -44,7 +77,8 @@ class LatestPostsEdit extends Component { | |
} | ||
|
||
render() { | ||
const { attributes, categoriesList, setAttributes, latestPosts } = this.props; | ||
const { attributes, setAttributes, latestPosts } = this.props; | ||
const { categoriesList } = this.state; | ||
const { displayPostDate, align, postLayout, columns, order, orderBy, categories, postsToShow } = attributes; | ||
|
||
const inspectorControls = ( | ||
|
@@ -163,11 +197,7 @@ export default withSelect( ( select, props ) => { | |
orderby: orderBy, | ||
per_page: postsToShow, | ||
}, ( value ) => ! isUndefined( value ) ); | ||
const categoriesListQuery = { | ||
per_page: 100, | ||
}; | ||
return { | ||
latestPosts: getEntityRecords( 'postType', 'post', latestPostsQuery ), | ||
categoriesList: getEntityRecords( 'taxonomy', 'category', categoriesListQuery ), | ||
}; | ||
} )( LatestPostsEdit ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import { | |
pressWithModifier, | ||
visitAdmin, | ||
clickBlockAppender, | ||
switchToAdminUser, | ||
switchToTestUser, | ||
} from '../support/utils'; | ||
import { activatePlugin, deactivatePlugin } from '../support/plugins'; | ||
|
||
|
@@ -60,12 +62,15 @@ describe( 'templates', () => { | |
const STANDARD_FORMAT_VALUE = '0'; | ||
|
||
async function setPostFormat( format ) { | ||
// To set the post format, we need to be the admin user. | ||
await switchToAdminUser(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switching user will not actually do anything if we're running as the admin user. We'll only switch if we're running as a different user, because the author role cannot manage plugins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's good to know; could you leave a comment explaining that in the code? 😄 |
||
await visitAdmin( 'options-writing.php' ); | ||
await page.select( '#default_post_format', format ); | ||
return Promise.all( [ | ||
notnownikki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await Promise.all( [ | ||
page.waitForNavigation(), | ||
page.click( '#submit' ), | ||
] ); | ||
await switchToTestUser(); | ||
} | ||
|
||
beforeAll( async () => await setPostFormat( 'image' ) ); | ||
|
@@ -93,9 +98,13 @@ describe( 'templates', () => { | |
} ); | ||
|
||
it( 'should not populate new page with default block for format', async () => { | ||
// This test always needs to run as the admin user, because other roles can't create pages. | ||
// It can't be skipped, because then it failed because of not testing the snapshot. | ||
await switchToAdminUser(); | ||
await newPost( { postType: 'page' } ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
await switchToTestUser(); | ||
} ); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,12 @@ function observeConsoleLogging() { | |
return; | ||
} | ||
|
||
// Viewing posts on the front end can result in this error, which | ||
// has nothing to do with Gutenberg. | ||
if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a jQuery thing that happens on the front end, and we sometimes would get hit by it, but sometimes the test assertions would complete quickly enough for it not to make the test fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an issue anywhere that tracks that? I don't quite follow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what causes it yet, it seems to be unrelated to Gutenberg, and happens when you view the published post on the front end. I'll investigate further after this merge. |
||
return; | ||
} | ||
|
||
const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ]; | ||
|
||
// Disable reason: We intentionally bubble up the console message | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume this is run by Travis and thus not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's run as part of the e2e tests. It didn't used to be, but now it is.