-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9999 from google/enhancement/9955-post-meta-setti…
…ngs-class
- Loading branch information
Showing
5 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
includes/Modules/Reader_Revenue_Manager/Post_Product_ID.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Class Google\Site_Kit\Modules\Reader_Revenue_Manager\Post_Product_ID | ||
* | ||
* @package Google\Site_Kit\Modules\Reader_Revenue_Manager | ||
* @copyright 2025 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Modules\Reader_Revenue_Manager; | ||
|
||
use Google\Site_Kit\Core\Storage\Post_Meta; | ||
use Google\Site_Kit\Core\Storage\Post_Meta_Setting; | ||
|
||
/** | ||
* Class for associating product ID to post meta. | ||
* | ||
* @since n.e.x.t | ||
* @access private | ||
* @ignore | ||
*/ | ||
class Post_Product_ID extends Post_Meta_Setting { | ||
/** | ||
* Publication ID. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @var string | ||
*/ | ||
private string $publication_id; | ||
|
||
/** | ||
* Post_Product_ID constructor. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param Post_Meta $post_meta Post_Meta instance. | ||
* @param string $publication_id Publication ID. | ||
*/ | ||
public function __construct( Post_Meta $post_meta, string $publication_id ) { | ||
parent::__construct( $post_meta ); | ||
|
||
$this->publication_id = $publication_id; | ||
} | ||
|
||
/** | ||
* Gets the meta key for the setting. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return string Meta key. | ||
*/ | ||
protected function get_meta_key(): string { | ||
return 'googlesitekit_rrm_' . $this->publication_id . ':productID'; | ||
} | ||
|
||
/** | ||
* Gets the `show_in_rest` value for this postmeta setting value. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return bool|Array Any valid value for the `show_in_rest` | ||
*/ | ||
protected function get_show_in_rest() { | ||
return true; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/phpunit/integration/Modules/Reader_Revenue_Manager/Post_Product_IDTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Class Google\Site_Kit\Tests\Modules\Reader_Revenue_Manager\Post_Product_ID_Test | ||
* | ||
* @package Google\Site_Kit\Tests\Modules\Reader_Revenue_Manager | ||
* @copyright 2025 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Tests\Modules\Reader_Revenue_Manager; | ||
|
||
use Google\Site_Kit\Core\Storage\Post_Meta; | ||
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Post_Product_ID; | ||
use Google\Site_Kit\Tests\TestCase; | ||
|
||
class Post_Product_ID_Test extends TestCase { | ||
|
||
/** | ||
* @var Post_Product_ID | ||
*/ | ||
private $setting; | ||
|
||
public function set_up(): void { | ||
parent::set_up(); | ||
|
||
$post_meta = new Post_Meta(); | ||
$this->setting = new Post_Product_ID( $post_meta, 'test_publication_id' ); | ||
$this->setting->register(); | ||
} | ||
|
||
public function test_product_id_meta_registered() { | ||
$registered = registered_meta_key_exists( 'post', 'googlesitekit_rrm_test_publication_id:productID' ); | ||
|
||
$this->assertTrue( $registered ); | ||
} | ||
|
||
public function test_show_in_rest() { | ||
$meta_key = 'googlesitekit_rrm_test_publication_id:productID'; | ||
$show_in_rest = get_registered_meta_keys( 'post' )[ $meta_key ]['show_in_rest']; | ||
|
||
$this->assertTrue( $show_in_rest ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters