diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 605bed8b1..bb66f6aad 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -101,7 +101,7 @@ jobs: run: npm run copy-htaccess - name: Test - run: npm run cypress:run + run: npm run cypress:run --config-file tests/cypress/config.js - name: Upload artifacts uses: actions/upload-artifact@v2 diff --git a/assets/css/gutenberg-syndicated-post.scss b/assets/css/gutenberg-syndicated-post.scss index bf109217d..d040d3ab5 100644 --- a/assets/css/gutenberg-syndicated-post.scss +++ b/assets/css/gutenberg-syndicated-post.scss @@ -19,6 +19,7 @@ body.dt-linked-post { cursor: default; } + .edit-post-welcome-guide, .edit-post-header__settings, .components-time-picker, .react-datepicker, diff --git a/package-lock.json b/package-lock.json index ccce9ccd3..ff9a9d084 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ }, "node_modules/@10up/cypress-wp-utils": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/10up/cypress-wp-utils.git#0323741d6cecc8efe2ab5f1c7e2298b4d120a4ff", + "resolved": "git+ssh://git@github.com/10up/cypress-wp-utils.git#52d9387f9e70530abfec1d2b4549a8a9225b0817", "dev": true, "license": "MIT", "engines": { @@ -18393,7 +18393,7 @@ }, "dependencies": { "@10up/cypress-wp-utils": { - "version": "git+ssh://git@github.com/10up/cypress-wp-utils.git#0323741d6cecc8efe2ab5f1c7e2298b4d120a4ff", + "version": "git+ssh://git@github.com/10up/cypress-wp-utils.git#52d9387f9e70530abfec1d2b4549a8a9225b0817", "dev": true, "from": "@10up/cypress-wp-utils@github:10up/cypress-wp-utils#build" }, diff --git a/run-wpacceptance.sh b/run-wpacceptance.sh deleted file mode 100644 index 13635600e..000000000 --- a/run-wpacceptance.sh +++ /dev/null @@ -1,14 +0,0 @@ -for i in 1 2 3; do - echo -e "\033[32mRunning wp-acceptance with snapshot $1\033[0m" - ./vendor/bin/wpacceptance run --snapshot_id=$1 - EXIT_CODE=$? - - if [ $EXIT_CODE -gt 1 ]; then - echo "Retrying..." - sleep 3 - else - break - fi -done - -exit $EXIT_CODE diff --git a/tests/wpacceptance/img/browser-frame.jpg b/tests/cypress/assets/img/browser-frame.jpg similarity index 100% rename from tests/wpacceptance/img/browser-frame.jpg rename to tests/cypress/assets/img/browser-frame.jpg diff --git a/tests/cypress/e2e/distributed-post.test.js b/tests/cypress/e2e/distributed-post.test.js new file mode 100644 index 000000000..bf8720715 --- /dev/null +++ b/tests/cypress/e2e/distributed-post.test.js @@ -0,0 +1,107 @@ +const { randomName } = require( '../support/functions' ); + +describe( 'Distributed Post Tests', () => { + let externalConnectionName = ''; + + before( () => { + cy.login(); + cy.networkActivatePlugin( 'distributor' ); + cy.networkActivatePlugin( 'json-basic-authentication' ); + + externalConnectionName = 'Connection ' + randomName(); + cy.createExternalConnection( + externalConnectionName, + 'http://localhost/second/wp-json' + ); + } ); + + it( 'Counter should increase after distributing a post', () => { + const postTitle = 'Post to push ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( post ) => { + cy.distributorPushPost( post.id, 'second', '', 'publish' ); + // Return the the post edit screen. + cy.visit( '/wp-admin/post.php?post=' + post.id + '&action=edit' ); + // Ensure the settings panel is open. + cy.get( 'button[aria-label="Settings"]' ).then( ( $settings ) => { + if ( $settings.attr( 'aria-expanded' ) === 'false' ) { + $settings.trigger( 'click' ); + } + cy.openDocumentSettingsSidebar( 'Post' ); + cy.openDocumentSettingsPanel( 'Distributor' ); + cy.get( '#distributed-to' ).should( + 'contain.text', + 'Distributed to 1 connection' + ); + } ); + + cy.distributorPushPost( + post.id, + externalConnectionName, + '', + 'publish' + ); + // Return the the post edit screen. + cy.visit( '/wp-admin/post.php?post=' + post.id + '&action=edit' ); + // Ensure the settings panel is open. + cy.get( 'button[aria-label="Settings"]' ).then( ( $settings ) => { + if ( $settings.attr( 'aria-expanded' ) === 'false' ) { + $settings.trigger( 'click' ); + } + cy.openDocumentSettingsSidebar( 'Post' ); + cy.openDocumentSettingsPanel( 'Distributor' ); + cy.get( '#distributed-to' ).should( + 'contain.text', + 'Distributed to 2 connections' + ); + } ); + } ); + } ); + + it( 'Should display source information in distributed copies of content', () => { + const postTitle = 'Post to push ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPushPost( + sourcePost.id, + 'second', + '', + 'publish' + ).then( ( distributedPost ) => { + cy.visit( distributedPost.distributedFrontUrl ); + cy.get( '#wp-admin-bar-distributor .syndicated-notice' ) + .should( 'contain.text', 'This post was distributed from' ) + .should( 'contain.text', 'View the origin post.' ); + cy.get( 'link[rel=canonical]' ).should( + 'have.attr', + 'href', + sourcePost.link + ); + + cy.visit( distributedPost.distributedEditUrl ); + cy.closeWelcomeGuide(); + cy.get( '.components-notice__content' ) + .should( 'contain.text', 'Distributed from' ) + .should( + 'contain.text', + 'This post is linked to the origin post. Edits to the origin post will update this remote version.' + ); + + // Ensure the settings panel is open. + cy.get( 'button[aria-label="Settings"]' ).then( + ( $settings ) => { + if ( $settings.attr( 'aria-expanded' ) === 'false' ) { + $settings.trigger( 'click' ); + } + cy.openDocumentSettingsSidebar( 'Post' ); + cy.openDocumentSettingsPanel( 'Distributor' ); + cy.get( '#distributed-from' ).should( + 'contain.text', + 'Distributed on' + ); + } + ); + } ); + } ); + } ); +} ); diff --git a/tests/cypress/e2e/editor-blocks.test.js b/tests/cypress/e2e/editor-blocks.test.js new file mode 100644 index 000000000..32befceed --- /dev/null +++ b/tests/cypress/e2e/editor-blocks.test.js @@ -0,0 +1,116 @@ +const { randomName } = require( '../support/functions' ); + +describe( 'Distributed content block tests', () => { + let externalConnectionOneToTwo, externalConnectionTwoToOne; + + before( () => { + cy.login(); + cy.networkActivatePlugin( 'distributor' ); + cy.networkActivatePlugin( 'json-basic-authentication' ); + + externalConnectionOneToTwo = 'Site Two ' + randomName(); + cy.createExternalConnection( + externalConnectionOneToTwo, + 'http://localhost/second/wp-json' + ); + + externalConnectionTwoToOne = 'Site One ' + randomName(); + cy.createExternalConnection( + externalConnectionTwoToOne, + 'http://localhost/wp-json', + 'admin', + 'password', + 'second' + ); + } ); + + it( 'Should distribute blocks when pushing to network connections.', () => { + const postTitle = 'Post to push ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPushPost( + sourcePost.id, + 'second', + '', + 'publish' + ).then( ( distributedPost ) => { + cy.postContains( + distributedPost.distributedPostId, + '', + 'http://localhost/second/' + ); + } ); + } ); + } ); + + it( 'Should distribute blocks when pulling from network connections.', () => { + const postTitle = 'Post to pull ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPullPost( + sourcePost.id, + 'second', + '', + 'localhost' + ).then( ( distributedPost ) => { + cy.closeWelcomeGuide(); + const matches = + distributedPost.distributedEditUrl.match( /post=(\d+)/ ); + let distributedPostId; + if ( matches ) { + distributedPostId = matches[ 1 ]; + } + cy.postContains( + distributedPostId, + '', + 'http://localhost/second/' + ); + } ); + } ); + } ); + + it( 'Should distribute blocks when pushing to external connections.', () => { + const postTitle = 'Post to push ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPushPost( + sourcePost.id, + externalConnectionOneToTwo, + '', + 'publish' + ).then( ( distributedPost ) => { + cy.postContains( + distributedPost.distributedPostId, + '', + 'http://localhost/second/' + ); + } ); + } ); + } ); + + it( 'Should distribute blocks when pulling from external connections.', () => { + const postTitle = 'Post to pull ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPullPost( + sourcePost.id, + '/second/', // Pull to second site. + '', // From primary site. + externalConnectionTwoToOne + ).then( ( distributedPost ) => { + cy.closeWelcomeGuide(); + const matches = + distributedPost.distributedEditUrl.match( /post=(\d+)/ ); + let distributedPostId; + if ( matches ) { + distributedPostId = matches[ 1 ]; + } + cy.postContains( + distributedPostId, + '', + 'http://localhost/second/' + ); + } ); + } ); + } ); +} ); diff --git a/tests/cypress/e2e/external-connection.test.js b/tests/cypress/e2e/external-connection.test.js index d074ca6de..54948bbe2 100644 --- a/tests/cypress/e2e/external-connection.test.js +++ b/tests/cypress/e2e/external-connection.test.js @@ -95,4 +95,23 @@ describe( 'Admin can add a new external connection', () => { .find( '.connection-status' ) .should( 'have.class', 'error' ); } ); + + it( 'Should display limited connection warning', () => { + cy.visit( '/wp-admin/admin.php?page=distributor' ); + cy.get( '.page-title-action' ).contains( 'Add New' ).click(); + + const name = randomName(); + cy.get( '#title' ).click().type( name ); + + cy.get( '.manual-setup-button' ).click(); + cy.get( '#dt_username' ).type( 'invalid_username' ); + cy.get( '#dt_password' ).type( 'invalid_password' ); + cy.get( '#dt_external_connection_url' ).type( + 'http://localhost/second/wp-json' + ); + cy.get( '.description.endpoint-result' ).should( + 'contain.text', + 'Limited connection established.' + ); + } ); } ); diff --git a/tests/cypress/e2e/internal-push.test.js b/tests/cypress/e2e/internal-push.test.js index 66b9b27ac..b3169fdd6 100644 --- a/tests/cypress/e2e/internal-push.test.js +++ b/tests/cypress/e2e/internal-push.test.js @@ -57,6 +57,10 @@ describe( 'Internal Push', () => { ); // Set Featured Image + // This test is temporarily disabled due to failures in GitHub actions that are not reproducible locally. + // On GitHub the success message expected within the cy.distributorPushPost command is not found as the + // distribution fails with an undefined error. + // cy.uploadMedia( 'assets/img/banner-772x250.png' ).then( // ( media ) => { // if ( media && media.mediaId ) { diff --git a/tests/cypress/e2e/link-unlink.test.js b/tests/cypress/e2e/link-unlink.test.js new file mode 100644 index 000000000..6559852dd --- /dev/null +++ b/tests/cypress/e2e/link-unlink.test.js @@ -0,0 +1,95 @@ +const { randomName } = require( '../support/functions' ); + +describe( 'Linking and unlinking tests', () => { + before( () => { + cy.login(); + cy.networkActivatePlugin( 'distributor' ); + } ); + + it( 'Should show the unlinking option for linked posts', () => { + const postTitle = 'Post to distribute ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + // Push the post to the second network site. + cy.distributorPushPost( + sourcePost.id, + 'second', + '', + 'publish' + ).then( ( distributedPost ) => { + // Open the distributed post in the second network site. + cy.visit( distributedPost.distributedEditUrl ); + cy.closeWelcomeGuide(); + + // Ensure the post shows link to original post. + cy.get( '.components-notice__content' ) + .should( 'contain.text', 'Distributed from' ) + .should( + 'contain.text', + 'This post is linked to the origin post.' + ); + cy.get( + '.components-notice__content .components-notice__action:eq(0)' + ) + .should( 'contain.text', 'Unlink from the origin post' ) + .should( 'have.attr', 'href' ) + .and( 'match', /&action=unlink&/ ); + cy.get( + '.components-notice__content .components-notice__action:eq(1)' + ) + .should( 'contain.text', 'View the origin post' ) + .should( 'have.attr', 'href', sourcePost.link ); + + // Ensure the post is not editable + cy.get( '.edit-post-visual-editor' ).should( + 'have.css', + 'pointer-events', + 'none' + ); + } ); + } ); + } ); + + it( 'Should show the linking option for unlinked posts', () => { + const postTitle = 'Post to distribute ' + randomName(); + + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + // Push the post to the second network site. + cy.distributorPushPost( + sourcePost.id, + 'second', + '', + 'publish' + ).then( ( distributedPost ) => { + // Open the distributed post in the second network site. + cy.visit( distributedPost.distributedEditUrl ); + cy.closeWelcomeGuide(); + + // Unlink the post. + cy.get( + '.components-notice__content .components-notice__action:eq(0)' + ) + .should( 'contain.text', 'Unlink from the origin post' ) + .click(); + + // Ensure the post shows link to original post. + cy.get( '.components-notice__content' ) + .should( + 'contain.text', + 'This post has been unlinked from the origin post' + ) + .should( + 'contain.text', + 'Edits to the origin post will not update this remote version' + ); + + // Ensure the post is editable + cy.get( '.edit-post-visual-editor' ).should( + 'not.have.css', + 'pointer-events', + 'none' + ); + } ); + } ); + } ); +} ); diff --git a/tests/cypress/e2e/push-menu.test.js b/tests/cypress/e2e/push-menu.test.js new file mode 100644 index 000000000..f84f4a530 --- /dev/null +++ b/tests/cypress/e2e/push-menu.test.js @@ -0,0 +1,130 @@ +const { randomName } = require( '../support/functions' ); + +describe( 'Push menu test', () => { + let externalConnectionName; + + before( () => { + cy.login(); + cy.networkActivatePlugin( 'distributor' ); + cy.networkActivatePlugin( 'json-basic-authentication' ); + + externalConnectionName = 'Connection ' + randomName(); + cy.createExternalConnection( + externalConnectionName, + 'http://localhost/second/wp-json' + ); + } ); + + it( 'Push menu should not be visible on new post', () => { + cy.visit( '/wp-admin/post-new.php' ); + cy.disableFullscreenEditor(); + cy.get( '#wp-admin-bar-distributor' ).should( 'not.be.visible' ); + } ); + + it( 'Push menu should be visible', () => { + const postTitle = 'Push menu test ' + randomName(); + cy.createPost( { title: postTitle } ).then( ( post ) => { + cy.visit( '/wp-admin/post.php?post=' + post.id + '&action=edit' ); + cy.disableFullscreenEditor(); + cy.get( '#wp-admin-bar-distributor' ).should( 'be.visible' ); + cy.get( '#wp-admin-bar-distributor > a' ).click(); + cy.get( '#distributor-push-wrapper .new-connections-list' ).should( + 'be.visible' + ); + } ); + } ); + + it( 'Push menu should prevent pushing to the same site', () => { + const postTitle = 'Push menu test ' + randomName(); + const toConnectionName = 'localhost/second'; + cy.createPost( { title: postTitle } ).then( ( sourcePost ) => { + cy.distributorPushPost( + sourcePost.id, + toConnectionName, + '', + 'publish' + ).then( () => { + // Visit the source post in the dashboard. + cy.visit( + '/wp-admin/post.php?post=' + sourcePost.id + '&action=edit' + ); + cy.disableFullscreenEditor(); + cy.get( '#wp-admin-bar-distributor > a' ).click(); + + // Get menu item for site already distributed to. + cy.get( + '#distributor-push-wrapper .new-connections-list .add-connection' + ) + .contains( toConnectionName ) + .parent() + .should( 'be.disabled' ); + } ); + } ); + } ); + + it( 'Should allow selecting and deselecting connections', () => { + const postTitle = 'Push menu test ' + randomName(); + cy.createPost( { title: postTitle } ).then( ( post ) => { + cy.visit( '/wp-admin/post.php?post=' + post.id + '&action=edit' ); + cy.disableFullscreenEditor(); + cy.get( '#wp-admin-bar-distributor' ).should( 'be.visible' ); + cy.get( '#wp-admin-bar-distributor > a' ).click(); + + // Select the network connection `localhost/second`. + cy.get( + '#distributor-push-wrapper .new-connections-list .add-connection' + ) + .contains( 'localhost/second' ) + .click(); + + // Check that the connection is selected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( 'localhost/second' ) + .should( 'be.visible' ); + + // Select the external connection. + cy.get( + '#distributor-push-wrapper .new-connections-list .add-connection' + ) + .contains( externalConnectionName ) + .click(); + + // Check that the connection is selected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( externalConnectionName ) + .should( 'be.visible' ); + + // Deselect the network connection. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( 'localhost/second' ) + .find( '.remove-connection' ) + .click(); + + // Check that the connection is deselected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( 'localhost/second' ) + .should( 'not.exist' ); + + // Check that the external connection is still selected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( externalConnectionName ) + .should( 'be.visible' ); + + // Deselct the external connection. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( externalConnectionName ) + .find( '.remove-connection' ) + .click(); + + // Check that the connection is deselected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .contains( externalConnectionName ) + .should( 'not.exist' ); + + // Check that no other connections are selected. + cy.get( '#distributor-push-wrapper .selected-connections-list' ) + .children() + .should( 'not.exist' ); + } ); + } ); +} ); diff --git a/tests/wpacceptance/DistributedPostTest.php b/tests/wpacceptance/DistributedPostTest.php deleted file mode 100644 index 63c9896b3..000000000 --- a/tests/wpacceptance/DistributedPostTest.php +++ /dev/null @@ -1,105 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - self::assertPostFieldContains( 40, 'post_title', 'Test Post' ); - - return; - - // Distribute post - $post_info = $this->pushPost( $I, 40, 2 ); - - $I->moveTo( $post_info['original_edit_url'] ); - - $I->waitUntilElementVisible( 'body.post-php' );; - - $I->seeText( '1', '#distributed-to strong' ); - - // Distribute post - $post_info = $this->pushPost( $I, 40, 3 ); - - $I->moveTo( $post_info['original_edit_url'] ); - - $I->waitUntilElementVisible( 'body.post-php' );; - - $I->seeText( '2', '#distributed-to strong' ); - } - - /** - * Test UI for a post that has been distributed (not original) - */ - public function testDistributedFrom() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $post_info = $this->pushPost( $I, 40, 2 ); - - // Now let's navigate to the new post - - $I->moveTo( '/two/wp-admin/edit.php' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - // Make sure we see distributed icon for first post - $I->seeElement( '.wp-list-table tbody tr:nth-child(1) .distributor img' ); - - $I->moveTo( $post_info['distributed_edit_url'] ); - - $I->waitUntilElementVisible( 'body.post-php' ); - - $editor_has_blocks = $this->editorHasBlocks( $I ); - // Make sure we see distributed time in publish box - if ( $editor_has_blocks ) { - $I->seeText( 'Distributed on:', '#distributed-from' ); - } else { - $I->seeText( 'Distributed on', '#syndicate-time' ); - } - - // Make sure we see distributed status admin notice and that it shows as linked - if ( $editor_has_blocks ) { - $I->seeText( 'Distributed from Site One. The origin post will update this version unless you unlink from the origin post. View the origin post', '.components-notice__content' ); - $element = $I->getElement( '.components-notice__action' ); - $I->seeText( 'unlink from the origin post.', '.components-notice__action' ); - } else { - $I->seeText( 'Distributed from', '.syndicate-status'); - $I->seeText( 'unlink from the origin post', '.syndicate-status' ); - } - - // Now let's check in the front end - $I->moveTo( $post_info['distributed_front_url'] ); - - $I->waitUntilElementVisible( '#masthead' ); - - $I->moveMouse( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - usleep( 750 ); - - // Make sure the distributed admin bar menu shows the post has been distributed - $I->seeText( 'This post has been distributed', '#distributor-push-wrapper .syndicated-notice'); - - // Make sure canonical link contains the original - $source = $I->getPageSource(); - - $this->assertTrue( ( false !== strpos( $source, 'openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $titles = $I->getElements( '.wp-list-table .page-title' ); - - $I->seeText( 'Test Post', $titles[1] ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull&status=pulled' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeElement( '.wp-list-table tbody tr.no-items' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull&status=skipped' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeElement( '.wp-list-table tbody tr.no-items' ); - } - - /** - * Test pulling a post - */ - public function testPullPost() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $this->pullPost( $I, 40, 'two', '' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $titles = $I->getElements( '.wp-list-table .page-title' ); - - $I->seeText( 'oEmbed Test', '.wp-list-table .page-title' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull&status=pulled' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeText( 'Test Post', '.wp-list-table .page-title' ); - } - - /** - * Test skipping a post - */ - public function testSkipPost() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->selectOptionByValue( '#bulk-action-selector-top', 'bulk-skip' ); - - $I->checkOptions( '.wp-list-table #cb-select-40'); - - $I->click( '#doaction' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull&status=skipped' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeText( 'Test Post', '.wp-list-table .page-title' ); - } - - /** - * Test searching mutilple words. - * - * @link https://github.com/10up/distributor/pull/533 - */ - public function testSearchMultipleWordsDuringPull() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=pull' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->typeInField( '#post-search-input', 'test post' ); - - $I->click( '#search-submit' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->dontSeeText( 'No items found.', 'table.distributor_page_pull' ); - } -} diff --git a/tests/wpacceptance/InternalPushTest.php b/tests/wpacceptance/InternalPushTest.php deleted file mode 100644 index 060b1b3f1..000000000 --- a/tests/wpacceptance/InternalPushTest.php +++ /dev/null @@ -1,169 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $this->pushPost( $I, 40, 2, '', 'draft' ); - - $I->moveTo( '/two/wp-admin/edit.php' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeText( 'Test Post', '.wp-list-table tbody tr:nth-child(1) .row-title' ); - $I->seeText( 'Draft', '.wp-list-table tbody tr:nth-child(1) .post-state' ); - } - - /** - * Test pushing as published - */ - public function testPushPublishPost() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $this->pushPost( $I, 40, 2 ); - - $I->moveTo( '/two/wp-admin/edit.php' ); - - $I->waitUntilElementVisible( '.wp-list-table' ); - - $I->seeText( 'Test Post', '.wp-list-table tbody tr:nth-child(1) .row-title' ); - $I->dontSeeText( 'Draft', '.wp-list-table tbody tr:nth-child(1) .post-state' ); - } - - /** - * Test that all data gets synced on push - */ - public function testPushDataSync() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( '/wp-admin/post.php?post=40&action=edit' ); - - $this->disableFullscreenEditor( $I ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $editor_has_blocks = $this->editorHasBlocks( $I ); - - // Skip this test in Gutenberg for now. - // @todo This needs to be re-written for the Gutenberg UI or easier a prebuilt post added to the docker images we can test push data sync with. - if ( $editor_has_blocks ) { - return; - } - - // Fill out title - $I->fillField( '#title', 'Test Title' ); - - // Add custom meta - $I->click( '#show-settings-link' ); - - $I->checkOptions( '#postcustom-hide' ); - - $I->waitUntilElementVisible( '#enternew' ); - - $I->jsClick( '#enternew' ); - - $I->waitUntilElementVisible( '#metakeyinput' ); - - $I->setElementProperty( '#metakeyinput', 'value', 'custom_meta_key' ); - $I->setElementProperty( '#metavalue', 'value', 'custom_meta_value' ); - - $I->click( '#newmeta-submit' ); - - // Add tag - $I->setElementProperty( '#new-tag-post_tag', 'value', 'tag-one' ); - $I->click( '.tagadd' ); - - // Add category - $I->click( '#category-add-toggle' ); - usleep( 500 ); - $I->setElementProperty( '#newcategory', 'value', 'Test Category' ); - $I->click( '#category-add-submit' ); - - $I->scrollTo( 0, 0 ); - - // Fill in content - $I->click( '#content-html' ); - $I->fillField( '#content', 'The content' ); - - // Set featured image - $I->click( '#set-post-thumbnail' ); - - $I->waitUntilElementVisible( '.media-modal-content' ); - - $I->attachFile( '.media-modal-content input[type="file"]', __DIR__ . '/img/browser-frame.jpg' ); - - $I->waitUntilElementEnabled( '.media-modal-content .media-button-select' ); - - $I->click( '.media-modal-content .media-button-select' ); - - $I->waitUntilElementVisible( '#remove-post-thumbnail' ); - - $I->scrollTo( 0, 0 ); - - $I->click( '#publish' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - // Distribute post - $post_info = $this->pushPost( $I, 40, 2 ); - - $I->moveTo( $post_info['distributed_edit_url'] ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - // Now check everything - - // See title - $I->seeValueInAttribute( '#title', 'value', 'Test Title' ); - - // See tag - $I->seeText( 'tag-one', '.tagchecklist'); - - // See image - $I->seeElement( '#postimagediv img' ); - - // See content - $I->seeFieldValue( '#content', 'The content' ); - - // Check custom meta - $I->click( '#show-settings-link' ); - - $I->checkOptions( '#postcustom-hide' ); - $I->seeTextInSource( 'custom_meta_key' ); - $I->seeTextInSource( 'custom_meta_value' ); - - // Get Element containing category, then check it for checked input - $category_parent = $I->getElementContaining( 'Test Category' ); - - foreach ( $category_parent as $element ) { - if ( 'LABEL' === $I->getElementTagName( $element ) ) { - $category_parent = $element; - break; - } - } - - $checked = $I->getElement( 'input:checked', $category_parent ); - - $this->assertTrue( ! empty( $checked ) ); - } -} diff --git a/tests/wpacceptance/LinkUnlinkTest.php b/tests/wpacceptance/LinkUnlinkTest.php deleted file mode 100644 index 642b6b942..000000000 --- a/tests/wpacceptance/LinkUnlinkTest.php +++ /dev/null @@ -1,64 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $post_info = $this->pushPost( $I, 40, 2 ); - - // Now let's navigate to the new post - - $I->moveTo( $post_info['distributed_edit_url'] ); - - $I->waitUntilElementVisible( 'body.post-php' ); - - $editor_has_blocks = $this->editorHasBlocks( $I ); - - // I see linked link - if ( $editor_has_blocks ) { - $I->seeLink( 'View the origin post' ); - // Unlink post - $I->click( '.components-notice__action' ); - - $I->waitUntilElementVisible( 'body.post-php' );; - - sleep( 1 ); - - // I see unlinked text - $I->seeText( 'Originally distributed from Site One. This Post has been unlinked from the origin post. However, you can always restore it. View the origin post', '.components-notice__content' ); - - // I can interact with title field - $I->canInteractWithField( '#post-title-0' ); - - } else { - $I->seeLink( 'unlink from the origin post' ); - // I cant interact with title field - $I->cannotInteractWithField( '#title' ); - // Unlink post - $I->click( '.syndicate-status span a' ); - - $I->waitUntilElementVisible( 'body.post-php' );; - - // I see unlinked text - $I->seeText( 'This post has been unlinked from the origin post', '.syndicate-status' ); - - // I can interact with title field - $I->canInteractWithField( '#title' ); - } - - } -} diff --git a/tests/wpacceptance/OembedTest.php b/tests/wpacceptance/OembedTest.php deleted file mode 100644 index 2f9ce5e83..000000000 --- a/tests/wpacceptance/OembedTest.php +++ /dev/null @@ -1,152 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - // Push post to connection 2. - $post_info = $this->pushPost( $I, 48, 2 ); - $I->moveTo( $post_info['distributed_edit_url'] ); - $I->waitUntilElementVisible( 'body.post-php' ); - - // Get the source. - $source = $I->getPageSource(); - - // Test the distributed post content. - $this->assertTrue( - (bool) preg_match( '#https://twitter.com/10up/status/1067517868441387008#', stripslashes( $source ) ), - 'oEmbed was not pushed properly over a network connection' - ); - } - - /** - * Test network pulling content with an oEmbed. - */ - public function testOembedNetworkPulledContent() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $post_info = $this->pullPost( $I, 48, 'two', '' ); - $I->moveTo( $post_info['distributed_edit_url'] ); - $I->waitUntilElementVisible( 'body.post-php' ); - - // Get the source. - $source = $I->getPageSource(); - - // Test the distributed post content. - $this->assertTrue( - (bool) preg_match( '#https://twitter.com/10up/status/1067517868441387008#', stripslashes( $source ) ), - 'oEmbed was not pulled properly over a network connection' - ); - } - - /** - * Test external pushing content with an oEmbed. - */ - public function testOembedExternalPushedContent() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'wp-admin/post-new.php?post_type=dt_ext_connection' ); - - $I->click( '.manual-setup-button' ); - - $I->typeInField( '#title', 'Test External Connection' ); - - $I->typeInField( '#dt_username', 'wpsnapshots' ); - - $I->typeInField( '#dt_external_connection_url', $this->getWPHomeUrl() . '/two/wp-json' ); - - $I->typeInField( '#dt_password', 'password' ); - - $I->waitUntilElementContainsText( 'Connection established', '.endpoint-result' ); - - $I->click( '#create-connection' ); - - $I->waitUntilElementVisible( '.notice-success' ); - $url = $I->getCurrentUrl(); - preg_match( '/post=(\d+)/', $url, $matches ); - - $post_info = $this->pushPost( $I, 48, (int) $matches[1], '', 'publish', true ); - $I->moveTo( 'two/wp-admin/edit.php' ); - - // Switch to the distributed post. - $I->waitUntilElementVisible( '#the-list' ); - $I->click( 'a.row-title' ); - $I->waitUntilNavigation(); - - // Use moveTo to prime page object. - $url = $I->getCurrentUrl(); - $I->moveTo( 'two/wp-admin/edit.php' ); - $I->moveTo( $url ); - - $I->waitUntilElementVisible( 'body.post-php' ); - - // Get the source. - $source = $I->getPageSource(); - - // Test the distributed post content. - $this->assertTrue( - (bool) preg_match( '#https://twitter.com/10up/status/1067517868441387008#', stripslashes( $source ) ), - 'oEmbed was not pushed properly over an external connection' - ); - } - - /** - * Test external pulling content with an oEmbed. - */ - public function testOembedExternalPulledContent() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'two/wp-admin/post-new.php?post_type=dt_ext_connection' ); - - $I->click( '.manual-setup-button' ); - - $I->typeInField( '#title', 'Test External Connection' ); - - $I->typeInField( '#dt_username', 'wpsnapshots' ); - - $I->typeInField( '#dt_external_connection_url', $this->getWPHomeUrl() . '/wp-json' ); - - $I->typeInField( '#dt_password', 'password' ); - - $I->waitUntilElementContainsText( 'Connection established', '.endpoint-result' ); - - $I->click( '#create-connection' ); - - $I->waitUntilElementVisible( '.notice-success' ); - - $I->moveTo( 'two/wp-admin/admin.php?page=distributor' ); - - // Pull post from external connection. - $post_info = $this->pullPost( $I, 48, 'two', '', 'Test External Connection' ); - $I->moveTo( $post_info['distributed_edit_url'] ); - - // Get the source. - $source = $I->getPageSource(); - - // Test the distributed post content. - $this->assertTrue( - (bool) preg_match( '#https://twitter.com/10up/status/1067517868441387008#', stripslashes( $source ) ), - 'oEmbed was not pulled properly over an external connection' - ); - } -} diff --git a/tests/wpacceptance/PushMenuTest.php b/tests/wpacceptance/PushMenuTest.php deleted file mode 100644 index a0014fef4..000000000 --- a/tests/wpacceptance/PushMenuTest.php +++ /dev/null @@ -1,130 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'wp-admin/post.php?post=40&action=edit' ); - - $this->disableFullscreenEditor( $I ); - - $I->waitUntilElementVisible( '#wp-admin-bar-distributor a' ); - - $I->moveMouse( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->waitUntilElementVisible( '#distributor-push-wrapper .new-connections-list' ); - - $I->seeElement( '#distributor-push-wrapper .add-connection' ); - } - - /** - * Test connection cross out - */ - public function testConnectionCrossOutOnPush() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'wp-admin/post.php?post=40&action=edit' ); - - $this->disableFullscreenEditor( $I ); - - $I->waitUntilElementVisible( '#wp-admin-bar-distributor a' ); - - $this->dismissNUXTip( $I ); - - $I->moveMouse( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->waitUntilElementVisible( '#distributor-push-wrapper .new-connections-list' ); - - $I->click( '#distributor-push-wrapper .new-connections-list .add-connection[data-connection-id="2"]' ); - - usleep( 500 ); - - // Distribute post (as draft) - $I->click( '#distributor-push-wrapper .syndicate-button' ); - $I->waitUntilElementVisible( '#distributor-push-wrapper .dt-success' ); - - // See crossed out element - $I->seeElement( '#distributor-push-wrapper .new-connections-list .add-connection.syndicated[data-connection-id="2"]' ); - $I->seeText( 'View', '#distributor-push-wrapper .new-connections-list .add-connection.syndicated[data-connection-id="2"]' ); - } - - /** - * Test that we can select connections properly - */ - public function testSelectConnection() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'wp-admin/post.php?post=40&action=edit' ); - - $this->disableFullscreenEditor( $I ); - - $I->waitUntilElementVisible( '#wp-admin-bar-distributor a' ); - - $this->dismissNUXTip( $I ); - - $I->moveMouse( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->click( '#wp-admin-bar-distributor a' ); - - $I->waitUntilElementVisible( '#distributor-push-wrapper .new-connections-list' ); - - $I->click( '#distributor-push-wrapper .new-connections-list .add-connection[data-connection-id="2"]' ); - - usleep( 500 ); - - // Make sure added connection is visible - $I->seeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="2"]' ); - - // Make sure there is only one added connection - $elements = $I->getElements( '#distributor-push-wrapper .selected-connections-list .added-connection' ); - - $this->assertEquals( 1, count( $elements ) ); - - $I->click( '#distributor-push-wrapper .new-connections-list .add-connection[data-connection-id="3"]' ); - - // Make sure TWO added connections are visible - $I->seeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="2"]' ); - $I->seeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="3"]' ); - - // Remove 2nd connection - $I->click( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="3"] .remove-connection' ); - - // Make sure 2nd connection is gone and 1st connection is still there - $I->dontSeeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="3"]' ); - $I->seeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="2"]' ); - - // Remove 1st connection - $I->click( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="2"] .remove-connection' ); - - // Make sure both connections are gone - $I->dontSeeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="3"]' ); - $I->dontSeeElement( '#distributor-push-wrapper .selected-connections-list .added-connection[data-connection-id="2"]' ); - } -} diff --git a/tests/wpacceptance/SettingsTest.php b/tests/wpacceptance/SettingsTest.php deleted file mode 100644 index c5efac678..000000000 --- a/tests/wpacceptance/SettingsTest.php +++ /dev/null @@ -1,95 +0,0 @@ -openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - $I->moveTo( 'wp-admin/admin.php?page=distributor-settings' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - // Round one options edit/save - - $I->checkOptions( '.form-table input[type="checkbox"]' ); - $I->checkOptions( '.form-table input[type="radio"][value="featured"]' ); - - $I->click( '#submit' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $I->seeCheckboxIsChecked( '.form-table input[type="checkbox"]' ); - $I->seeCheckboxIsChecked( '.form-table input[type="radio"][value="featured"]' ); - - // Round two options edit/save - - $I->uncheckOptions( '.form-table input[type="checkbox"]' ); - $I->checkOptions( '.form-table input[type="radio"][value="attached"]' ); - - $I->click( '#submit' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $I->dontSeeCheckboxIsChecked( '.form-table input[type="checkbox"]' ); - $I->seeCheckboxIsChecked( '.form-table input[type="radio"][value="attached"]' ); - } - - /** - * Test author bylines - */ - public function testAuthorBylineSetting() { - $I = $this->openBrowserPage(); - - $I->loginAs( 'wpsnapshots' ); - - // First save the setting as checked - $I->moveTo( 'two/wp-admin/admin.php?page=distributor-settings' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $I->checkOptions( '.form-table input[type="checkbox"]' ); - - $I->click( '#submit' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $post_info = $this->pushPost( $I, 40, 2 ); - - // Check front end - $I->moveTo( $post_info['distributed_front_url'] ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - // Site One byline is shown - $I->seeText( 'Site One', '.byline .author' ); - - // Uncheck the setting - $I->moveTo( 'two/wp-admin/admin.php?page=distributor-settings' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - $I->uncheckOptions( '.form-table input[type="checkbox"]' ); - - $I->click( '#submit' ); - - $I->waitUntilElementVisible( '#wpadminbar' ); - - // Verify byline is normal - $I->moveTo( $post_info['distributed_front_url'] ); - - $I->seeText( 'admin', '.byline .author' ); - } -} diff --git a/tests/wpacceptance/bootstrap.php b/tests/wpacceptance/bootstrap.php deleted file mode 100644 index 21660bee2..000000000 --- a/tests/wpacceptance/bootstrap.php +++ /dev/null @@ -1,8 +0,0 @@ - $from_blog_slug . '/wp-admin/post.php?post=' . $post_id . '&action=edit', - ]; - - // Now distribute a published post - $I->moveTo( $info['original_edit_url'] ); - - try { - $info['original_front_url'] = $I->getElementAttribute( '#wp-admin-bar-view a', 'href' ); - } catch ( \Exception $e ) { - $info['original_front_url'] = $I->getElementAttribute( '#wp-admin-bar-preview a', 'href' ); - } - - $this->disableFullscreenEditor( $I ); - - $I->waitUntilElementVisible( '#wp-admin-bar-distributor a' ); - - $this->dismissNUXTip( $I ); - - $I->hover( '#wp-admin-bar-distributor a' ); - - $I->waitUntilElementVisible( '#distributor-push-wrapper .new-connections-list' ); - - // Distribute post - - $I->click( '#distributor-push-wrapper .new-connections-list .add-connection[data-connection-id="' . $to_connection_id . '"]' ); - - usleep( 500 ); - - if ( 'publish' === $post_status ) { - $I->click( '#dt-as-draft' ); // Uncheck for publish, draft is checked by default - } - - $I->waitUntilElementEnabled( '#distributor-push-wrapper .syndicate-button' ); - - $I->click( '#distributor-push-wrapper .syndicate-button' ); - - $I->waitUntilElementVisible( '#distributor-push-wrapper .dt-success' ); - - // Now let's navigate to the new post - only works for network connections. - if ( ! $external ) { - - $I->click( '#distributor-push-wrapper .new-connections-list .add-connection[data-connection-id="' . $to_connection_id . '"] a' ); - - $I->waitUntilNavigation(); - - $info['distributed_front_url'] = $I->getCurrentUrl(); - - try { - $link = $I->getElementAttribute( '#wp-admin-bar-edit a', 'href' ); - $info['distributed_edit_url'] = $link; - preg_match( '/post=(\d+)/', $link, $matches ); - if ( $matches ) { - $info['distributed_post_id'] = (int) $matches[1]; - } - } catch ( \Exception $e ) {} - } - - return $info; - } - - /** - * Pull a post - * - * @param \WPAcceptance\PHPUnit\Actor $actor WP Acceptance actor - * @param int $original_post_id Original post id - * @param int $to_blog_slug Blog slug where post is being pulled in - * @param string $from_blog_slug Blog we are pulling from. Empty string is main blog - * @param string $use_connection The full connection name to use on the pull screen. - * - * @return array - */ - protected function pullPost( \WPAcceptance\PHPUnit\Actor $I, $original_post_id, $to_blog_slug, $from_blog_slug = '', $use_connection = false ) { - if ( ! empty( $to_blog_slug ) ) { - $to_blog_slug .= '/'; - } - - if ( ! empty( $from_blog_slug ) ) { - $from_blog_slug .= '/'; - } - - $info = [ - 'original_edit_url' => $from_blog_slug . '/wp-admin/post.php?post=' . $original_post_id . '&action=edit', - ]; - - $I->moveTo( $to_blog_slug . 'wp-admin/admin.php?page=pull' ); - - if ( $use_connection ) { - $I->checkOptions( '#pull_connections', $use_connection ); - $I->waitUntilElementVisible( '.wp-list-table #cb-select-' . $original_post_id ); - } - - $I->checkOptions( '.wp-list-table #cb-select-' . $original_post_id ); - - $I->click( '#doaction' ); - - $I->waitUntilNavigation(); - - $I->click( '.pulled > a' ); - $I->waitUntilNavigation(); - - $I->moveMouse( '.wp-list-table tbody tr:nth-child(1) .page-title' ); - $I->click( '.wp-list-table tbody tr:nth-child(1) .page-title .view a' ); - - $I->waitUntilNavigation(); - - $info['distributed_view_url'] = $I->getCurrentUrl(); - - $I->click( '#wp-admin-bar-edit a' ); - - $I->waitUntilNavigation(); - - $info['distributed_edit_url'] = $I->getCurrentUrl(); - - return $info; - } - - /** - * Check if the editor is the block editor. - * - * Must be called from the edit page. - * - * @param \WPAcceptance\PHPUnit\Actor $actor The actor. - */ - protected function editorHasBlocks ( $actor ) { - $body = $actor->getElement( 'body' ); - $msg = $actor->elementToString( $body ); - return ( strpos( $msg, 'block-editor-page' ) ); - } - - /** - * Dismiss the Gutenberg NUX tooltip. - * - * @param \WPAcceptance\PHPUnit\Actor $actor The actor. - */ - protected function dismissNUXTip( $actor ) { - try { - if ( $actor->getElement( '.nux-dot-tip__disable' ) ) { - $actor->click( '.nux-dot-tip__disable' ); - } - } catch ( \Exception $e ) {} - } - - /** - * Disable new default fullscreen mode in WP 5.4. - * - * @param \WPAcceptance\PHPUnit\Actor $actor The actor. - */ - protected function disableFullscreenEditor( $actor ) { - $script = "if ( !! wp.data && wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ) ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); }"; - - $actor->executeJavascript( $script ); - } -} diff --git a/wpacceptance.json b/wpacceptance.json deleted file mode 100644 index 5a855e8f9..000000000 --- a/wpacceptance.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "distributor", - "exclude": [ - ".\/node_modules" - ], - "tests": [ - "tests\/wpacceptance\/*Test.php" - ], - "enforce_clean_db": true, - "bootstrap": "tests\/wpacceptance\/bootstrap.php", - "repository": "10up" -}