Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions admin/class-convertkit-admin-refresh-resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public function refresh_resources( $request ) {
break;

case 'restrict_content':
// Fetch Forms.
$forms = new ConvertKit_Resource_Forms( 'user_refresh_resource' );
$results_forms = $forms->refresh();

// Bail if an error occured.
if ( is_wp_error( $results_forms ) ) {
return rest_ensure_response( $results_forms );
}

// Fetch Tags.
$tags = new ConvertKit_Resource_Tags( 'user_refresh_resource' );
$results_tags = $tags->refresh();
Expand All @@ -126,6 +135,7 @@ public function refresh_resources( $request ) {
// Return resources.
return rest_ensure_response(
array(
'forms' => array_values( $results_forms ),
'tags' => array_values( $results_tags ),
'products' => array_values( $results_products ),
)
Expand Down
21 changes: 20 additions & 1 deletion resources/backend/js/refresh-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,26 @@ function convertKitRefreshResources(button) {
// Depending on the resource we're refreshing, populate the <select> options.
switch (resource) {
case 'restrict_content':
// Populate select `optgroup`` from response data, which comprises of Tags and Products.
// Populate select `optgroup` from response data, which comprises of Forms, Tags and Products.
// Forms.
response.forms.forEach(function (item) {
document
.querySelector(
field + ' optgroup[data-resource=forms]'
)
.appendChild(
new Option(
item.name +
' [' +
(item.format ? item.format : 'inline') +
']',
'form_' + item.id,
false,
selectedOption === 'form_' + item.id
)
);
});

// Tags.
response.tags.forEach(function (item) {
document
Expand Down
20 changes: 20 additions & 0 deletions tests/EndToEnd/general/other/RefreshResourcesButtonCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public function testRefreshResourcesInClassicEditor(EndToEndTester $I)
// Wait for button to change its state from disabled.
$I->waitForElementVisible('button.wp-convertkit-refresh-resources[data-resource="restrict_content"]:not(:disabled)');

// Confirm that the expected Form is within the Forms option group and selectable.
$I->seeElementInDOM('select#wp-convertkit-restrict_content optgroup[data-resource="forms"] option[value="form_' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]');
$I->fillSelect2Field(
$I,
container: '#select2-wp-convertkit-restrict_content-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);

// Confirm that the expected Tag is within the Tags option group and selectable.
$I->seeElementInDOM('select#wp-convertkit-restrict_content optgroup[data-resource="tags"] option[value="tag_' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]');
$I->fillSelect2Field(
Expand Down Expand Up @@ -196,6 +204,10 @@ public function testRefreshResourcesInGutenbergEditor(EndToEndTester $I)
// Wait for button to change its state from disabled.
$I->waitForElementVisible('button.wp-convertkit-refresh-resources[data-resource="restrict_content"]:not(:disabled)');

// Confirm that the expected Form is within the Forms option group and selectable.
$I->seeElementInDOM('#convertkit_plugin_sidebar_restrict_content optgroup[label="Forms"] option[value="form_' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]');
$I->selectOption('#convertkit_plugin_sidebar_restrict_content', $_ENV['CONVERTKIT_API_FORM_NAME']);

// Confirm that the expected Tag is within the Tags option group and selectable.
$I->seeElementInDOM('#convertkit_plugin_sidebar_restrict_content optgroup[label="Tags"] option[value="tag_' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]');
$I->selectOption('#convertkit_plugin_sidebar_restrict_content', $_ENV['CONVERTKIT_API_TAG_NAME']);
Expand Down Expand Up @@ -276,6 +288,10 @@ public function testRefreshResourcesOnQuickEdit(EndToEndTester $I)
// Wait for button to change its state from disabled.
$I->waitForElementVisible('button.wp-convertkit-refresh-resources[data-resource="restrict_content"]:not(:disabled)');

// Confirm that the expected Form is within the Forms option group and selectable.
$I->seeElementInDOM('#wp-convertkit-quick-edit-restrict_content optgroup[data-resource="forms"] option[value="form_' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]');
$I->selectOption('#wp-convertkit-quick-edit-restrict_content', $_ENV['CONVERTKIT_API_FORM_NAME']);

// Confirm that the expected Tag is within the Tags option group and selectable.
$I->seeElementInDOM('#wp-convertkit-quick-edit-restrict_content optgroup[data-resource="tags"] option[value="tag_' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]');
$I->selectOption('#wp-convertkit-quick-edit-restrict_content', $_ENV['CONVERTKIT_API_TAG_NAME']);
Expand Down Expand Up @@ -363,6 +379,10 @@ public function testRefreshResourcesOnBulkEdit(EndToEndTester $I)
// Wait for button to change its state from disabled.
$I->waitForElementVisible('button.wp-convertkit-refresh-resources[data-resource="restrict_content"]:not(:disabled)');

// Confirm that the expected Form is within the Forms option group and selectable.
$I->seeElementInDOM('#wp-convertkit-bulk-edit-restrict_content optgroup[data-resource="forms"] option[value="form_' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]');
$I->selectOption('#wp-convertkit-bulk-edit-restrict_content', $_ENV['CONVERTKIT_API_FORM_NAME']);

// Confirm that the expected Tag is within the Tags option group and selectable.
$I->seeElementInDOM('#wp-convertkit-bulk-edit-restrict_content optgroup[data-resource="tags"] option[value="tag_' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]');
$I->selectOption('#wp-convertkit-bulk-edit-restrict_content', $_ENV['CONVERTKIT_API_TAG_NAME']);
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/RESTAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ public function testRefreshResourcesRestrictContent()
$data = $response->get_data();
$this->assertIsArray( $data );

// Assert forms response data has the expected keys.
$this->assertArrayHasKey( 'forms', $data );
$this->assertIsArray( $data['forms'] );
$this->assertArrayHasKeys( $data['forms'][0], [ 'id', 'name', 'created_at' ] );

// Assert tags response data has the expected keys.
$this->assertArrayHasKey( 'tags', $data );
$this->assertIsArray( $data['tags'] );
Expand Down
Loading