Skip to content

Commit

Permalink
Merge branch 'bucket/plugin-consolidation' into fix/app-shop
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni authored Jun 8, 2024
2 parents 9b6e444 + ac9f3ba commit 4b8187c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
= [TBD] TBD =

* Fix - The Decorated repository was not returning values from `save()` and other methods. Now they return as expected. [BTRIA-2310]
* Fix - Resolved an issue where transient notices would disappear given a certain order of operations. [ECP-1804]

= [5.2.7] 2024-05-14 =

Expand Down
2 changes: 2 additions & 0 deletions src/Tribe/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ protected function get_nonce_action( string $slug ): string {
protected function set_transients( $notices ) {
$transient = self::$transient_notices_name;
set_transient( $transient, $notices, MONTH_IN_SECONDS );
// Manually memoize the value so we don't have to fetch it again.
tribe( 'cache' )['transient_admin_notices'] = $notices;
}

/**
Expand Down
74 changes: 74 additions & 0 deletions tests/wpunit/Tribe/Notices/NoticesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

class NoticesTest extends \Codeception\TestCase\WPTestCase {
/**
* Take the Admin Notice instance and verify the notice registered is memoized in the Cache.
*
* @test
*/
public function should_memoize_notice() {
// Verify the notice is not memoized in the Cache.
$cache = tribe( 'cache' );
$cache_key = 'transient_admin_notices';
$this->assertEmpty( $cache[ $cache_key ] );

// Register a notice.
$notice = Tribe__Admin__Notices::instance();
$message = '<p>test</p>';
$message_slug = 'test';
$notice->register_transient( $message_slug, $message );

// The memoized notice should be in the Cache.
$this->assertEquals( $message, $cache[ $cache_key ][ $message_slug ][0] );
}

/**
* Take the Admin Notice instance and verify the notice cache busts.
*
* @test
*/
public function should_clear_memoize_notice() {
// Verify the notice is not memoized in the Cache.
$cache = tribe( 'cache' );
$cache_key = 'transient_admin_notices';
$this->assertEmpty( $cache[ $cache_key ] );

// Register a notice.
$notice = Tribe__Admin__Notices::instance();
$message = '<p>test</p>';
$message_slug = 'test';
$notice->register_transient( $message_slug, $message );
$notice->remove_transient( $message_slug );

// The memoized notice should not be in the Cache.
$this->assertFalse( isset( $cache[ $cache_key ][ $message_slug ] ) );
}

/**
* Take the Admin Notice instance and verify the notice updates.
*
* @test
*/
public function should_update_memoize_notice() {
// Verify the notice is not memoized in the Cache.
$cache = tribe( 'cache' );
$cache_key = 'transient_admin_notices';
$this->assertEmpty( $cache[ $cache_key ] );

// Register a notice.
$notice = Tribe__Admin__Notices::instance();
$message = '<p>test</p>';
$message_slug = 'test';
$notice->register_transient( $message_slug, $message );

// Register another notice.
$message2 = '<p>test 2</p>';
$message_slug2 = 'test 2';
$notice->register_transient( $message_slug2, $message2 );

// The Notice store should be updated with both.
$this->assertTrue( $notice->showing_transient_notice( $message_slug ) );
$this->assertTrue( $notice->showing_transient_notice( $message_slug2 ) );
$this->assertFalse( $notice->showing_transient_notice( 'nonsense-faux-slug' ) );
}
}

0 comments on commit 4b8187c

Please sign in to comment.