|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\EndToEnd; |
| 4 | + |
| 5 | +use Tests\Support\EndToEndTester; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests for the Settings > Kit > Tools > Import sections for third party Form plugins, |
| 9 | + * such as MC4WP. |
| 10 | + * |
| 11 | + * @since 3.1.0 |
| 12 | + */ |
| 13 | +class PluginSettingsToolsImporterMC4WPCest |
| 14 | +{ |
| 15 | + /** |
| 16 | + * Run common actions before running the test functions in this class. |
| 17 | + * |
| 18 | + * @since 3.1.0 |
| 19 | + * |
| 20 | + * @param EndToEndTester $I Tester. |
| 21 | + */ |
| 22 | + public function _before(EndToEndTester $I) |
| 23 | + { |
| 24 | + // Activate Plugins. |
| 25 | + $I->activateKitPlugin($I); |
| 26 | + $I->activateThirdPartyPlugin($I, 'mailchimp-for-wp'); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Test that Mailchimp Forms are replaced with Kit Forms when the Tools > MC4WP: Migrate Configuration is configured. |
| 31 | + * |
| 32 | + * @since 3.1.0 |
| 33 | + * |
| 34 | + * @param EndToEndTester $I Tester. |
| 35 | + */ |
| 36 | + public function testMC4WPImport(EndToEndTester $I) |
| 37 | + { |
| 38 | + // Setup Plugin. |
| 39 | + $I->setupKitPlugin($I); |
| 40 | + $I->setupKitPluginResources($I); |
| 41 | + |
| 42 | + // Create Mailchimp Forms. |
| 43 | + $mailchimpFormIDs = $this->_createMailchimpForms($I); |
| 44 | + |
| 45 | + // Insert Mailchimp Form Shortcodes into Pages. |
| 46 | + $pageIDs = $this->_createPagesWithMailchimpFormShortcodes($I, $mailchimpFormIDs); |
| 47 | + |
| 48 | + // Navigate to the Tools screen. |
| 49 | + $I->loadKitSettingsToolsScreen($I); |
| 50 | + |
| 51 | + // Select the Kit Forms to replace the Mailchimp Forms. |
| 52 | + foreach ($mailchimpFormIDs as $mailchimpFormID) { |
| 53 | + $I->selectOption('_wp_convertkit_integration_mc4wp_settings[' . $mailchimpFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']); |
| 54 | + } |
| 55 | + |
| 56 | + // Click the Migrate button. |
| 57 | + $I->click('Migrate'); |
| 58 | + |
| 59 | + // Confirm success message displays. |
| 60 | + $I->waitForElementVisible('.notice-success'); |
| 61 | + $I->see('MC4WP forms migrated successfully.'); |
| 62 | + |
| 63 | + // View the Pages, to confirm Kit Forms now display. |
| 64 | + foreach ($pageIDs as $pageID) { |
| 65 | + $I->amOnPage('?p=' . $pageID); |
| 66 | + $I->seeElementInDOM('form[data-sv-form]'); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Test that the MC4WP: Migrate Configuration section is not displayed when no Mailchimp Forms exist. |
| 72 | + * |
| 73 | + * @since 3.1.0 |
| 74 | + * |
| 75 | + * @param EndToEndTester $I Tester. |
| 76 | + */ |
| 77 | + public function testMC4WPImportWhenNoMailchimpForms(EndToEndTester $I) |
| 78 | + { |
| 79 | + // Setup Plugin. |
| 80 | + $I->setupKitPlugin($I); |
| 81 | + $I->setupKitPluginResources($I); |
| 82 | + |
| 83 | + // Navigate to the Tools screen. |
| 84 | + $I->loadKitSettingsToolsScreen($I); |
| 85 | + |
| 86 | + // Confirm no MC4WP: Migrate Configuration section is displayed. |
| 87 | + $I->dontSeeElementInDOM('#import-mc4wp'); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Test that the MC4WP: Migrate Configuration section is not displayed when Mailchimp Forms exist, |
| 92 | + * but no Pages, Posts or Custom Posts contain Mailchimp Form Shortcodes. |
| 93 | + * |
| 94 | + * @since 3.1.0 |
| 95 | + * |
| 96 | + * @param EndToEndTester $I Tester. |
| 97 | + */ |
| 98 | + public function testMC4WPImportWhenNoMailchimpShortcodesInContent(EndToEndTester $I) |
| 99 | + { |
| 100 | + // Setup Plugin. |
| 101 | + $I->setupKitPlugin($I); |
| 102 | + $I->setupKitPluginResources($I); |
| 103 | + |
| 104 | + // Create Mailchimp Forms. |
| 105 | + $mailchimpFormIDs = $this->_createMailchimpForms($I); |
| 106 | + |
| 107 | + // Navigate to the Tools screen. |
| 108 | + $I->loadKitSettingsToolsScreen($I); |
| 109 | + |
| 110 | + // Confirm no MC4WP: Migrate Configuration section is displayed, as there are no |
| 111 | + // Mailchimp Form Shortcodes in the content. |
| 112 | + $I->dontSeeElementInDOM('#import-mc4wp'); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Test that the MC4WP: Migrate Configuration section is not displayed when no Kit Forms exist. |
| 117 | + * |
| 118 | + * @since 3.1.0 |
| 119 | + * |
| 120 | + * @param EndToEndTester $I Tester. |
| 121 | + */ |
| 122 | + public function testMC4WPImportWhenNoKitForms(EndToEndTester $I) |
| 123 | + { |
| 124 | + // Setup Plugin. |
| 125 | + $I->setupKitPluginCredentialsNoData($I); |
| 126 | + $I->setupKitPluginResourcesNoData($I); |
| 127 | + |
| 128 | + // Navigate to the Tools screen. |
| 129 | + $I->loadKitSettingsToolsScreen($I); |
| 130 | + |
| 131 | + // Confirm no MC4WP: Migrate Configuration section is displayed, as there are no |
| 132 | + // Mailchimp Form Shortcodes in the content. |
| 133 | + $I->dontSeeElementInDOM('#import-mc4wp'); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Create Mailchimp Forms. |
| 138 | + * |
| 139 | + * @since 3.1.0 |
| 140 | + * |
| 141 | + * @param EndToEndTester $I Tester. |
| 142 | + * @return array |
| 143 | + */ |
| 144 | + private function _createMailchimpForms(EndToEndTester $I) |
| 145 | + { |
| 146 | + return array( |
| 147 | + $I->havePostInDatabase( |
| 148 | + [ |
| 149 | + 'post_type' => 'mc4wp-form', |
| 150 | + 'post_status' => 'publish', |
| 151 | + 'post_title' => 'Mailchimp Form #1', |
| 152 | + 'post_content' => '<p><label>Email address:<input type="email" name="EMAIL" placeholder="Your email address" required /></label></p><p><input type="submit" value="Sign up" /></p>', |
| 153 | + ] |
| 154 | + ), |
| 155 | + $I->havePostInDatabase( |
| 156 | + [ |
| 157 | + 'post_type' => 'mc4wp-form', |
| 158 | + 'post_status' => 'publish', |
| 159 | + 'post_title' => 'Mailchimp Form #2', |
| 160 | + 'post_content' => '<p><label>Email address:<input type="email" name="EMAIL" placeholder="Your email address" required /></label></p><p><input type="submit" value="Sign up" /></p>', |
| 161 | + ] |
| 162 | + ), |
| 163 | + ); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Create Pages with Mailchimp Form Shortcodes. |
| 168 | + * |
| 169 | + * @since 3.1.0 |
| 170 | + * |
| 171 | + * @param EndToEndTester $I Tester. |
| 172 | + * @param array $mailchimpFormIDs Mailchimp Form IDs. |
| 173 | + * @return array |
| 174 | + */ |
| 175 | + private function _createPagesWithMailchimpFormShortcodes(EndToEndTester $I, $mailchimpFormIDs) |
| 176 | + { |
| 177 | + $pageIDs = array(); |
| 178 | + |
| 179 | + foreach ($mailchimpFormIDs as $mailchimpFormID) { |
| 180 | + $pageIDs[] = $I->havePostInDatabase( |
| 181 | + [ |
| 182 | + 'post_type' => 'page', |
| 183 | + 'post_status' => 'publish', |
| 184 | + 'post_title' => 'Page with Mailchimp Form #' . $mailchimpFormID, |
| 185 | + 'post_content' => '[mc4wp_form id="' . $mailchimpFormID . '"]', |
| 186 | + 'meta_input' => [ |
| 187 | + '_wp_convertkit_post_meta' => [ |
| 188 | + 'form' => '0', |
| 189 | + 'landing_page' => '', |
| 190 | + 'tag' => '', |
| 191 | + ], |
| 192 | + ], |
| 193 | + ] |
| 194 | + ); |
| 195 | + } |
| 196 | + |
| 197 | + return $pageIDs; |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Deactivate and reset Plugin(s) after each test, if the test passes. |
| 202 | + * We don't use _after, as this would provide a screenshot of the Plugin |
| 203 | + * deactivation and not the true test error. |
| 204 | + * |
| 205 | + * @since 3.1.0 |
| 206 | + * |
| 207 | + * @param EndToEndTester $I Tester. |
| 208 | + */ |
| 209 | + public function _passed(EndToEndTester $I) |
| 210 | + { |
| 211 | + $I->deactivateThirdPartyPlugin($I, 'mailchimp-for-wp'); |
| 212 | + $I->deactivateKitPlugin($I); |
| 213 | + $I->resetKitPlugin($I); |
| 214 | + } |
| 215 | +} |
0 commit comments