Make WordPress Core


Ignore:
Timestamp:
03/12/2026 07:54:50 AM (7 months ago)
Author:
gziolo
Message:

Connectors: Remove redundant helper and improve PHPDoc

Remove _wp_connectors_get_connector_settings() and inline ksort()
into _wp_connectors_get_connector_script_module_data(). Expand
@return and @phpstan-return array shapes for wp_get_connector()
and wp_get_connectors(). Make logo_url and credentials_url truly
optional. Rename test class to wpGetConnectors.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11227.

Follow-up to [61943].

Props gziolo, westonruter.
Fixes #64791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/connectors/wpConnectorsGetConnectorSettings.php

    r61943 r61983  
    44
    55/**
    6  * Tests for _wp_connectors_get_connector_settings().
     6 * Tests for wp_get_connectors().
    77 *
    88 * @group connectors
    9  * @covers ::_wp_connectors_get_connector_settings
     9 * @covers ::wp_get_connectors
    1010 */
    11 class Tests_Connectors_WpConnectorsGetConnectorSettings extends WP_UnitTestCase {
     11class Tests_Connectors_WpGetConnectors extends WP_UnitTestCase {
    1212
    1313        use WP_AI_Client_Mock_Provider_Trait;
    … …  
    1616         * Registers the mock provider once before any tests in this class run.
    1717         */
    18         public static function set_up_before_class() {
     18        public static function set_up_before_class(): void {
    1919                parent::set_up_before_class();
    2020                self::register_mock_connectors_provider();
    … …  
    2424         * Unregisters the mock provider setting added by `init`.
    2525         */
    26         public static function tear_down_after_class() {
     26        public static function tear_down_after_class(): void {
    2727                self::unregister_mock_connector_setting();
    2828                parent::tear_down_after_class();
    … …  
    3232         * @ticket 64730
    3333         */
    34         public function test_returns_expected_connector_keys() {
    35                 $connectors = _wp_connectors_get_connector_settings();
     34        public function test_returns_expected_connector_keys(): void {
     35                $connectors = wp_get_connectors();
    3636
    3737                $this->assertArrayHasKey( 'google', $connectors );
    … …  
    4545         * @ticket 64730
    4646         */
    47         public function test_each_connector_has_required_fields() {
    48                 $connectors = _wp_connectors_get_connector_settings();
     47        public function test_each_connector_has_required_fields(): void {
     48                $connectors = wp_get_connectors();
    4949
    5050                $this->assertNotEmpty( $connectors, 'Connector settings should not be empty.' );
    … …  
    6868         * @ticket 64730
    6969         */
    70         public function test_api_key_connectors_have_setting_name_and_credentials_url() {
    71                 $connectors    = _wp_connectors_get_connector_settings();
     70        public function test_api_key_connectors_have_setting_name_and_credentials_url(): void {
     71                $connectors    = wp_get_connectors();
    7272                $api_key_count = 0;
    7373
    … …  
    8282                        $this->assertSame(
    8383                                "connectors_ai_{$connector_id}_api_key",
    84                                 $connector_data['authentication']['setting_name'],
     84                                $connector_data['authentication']['setting_name'] ?? null,
    8585                                "Connector '{$connector_id}' setting_name does not match expected format."
    8686                        );
    87                         $this->assertArrayHasKey( 'credentials_url', $connector_data['authentication'], "Connector '{$connector_id}' authentication is missing 'credentials_url'." );
    8887                }
    8988
    … …  
    9493         * @ticket 64730
    9594         */
    96         public function test_featured_provider_names_match_expected() {
    97                 $connectors = _wp_connectors_get_connector_settings();
     95        public function test_featured_provider_names_match_expected(): void {
     96                $connectors = wp_get_connectors();
    9897
    9998                $this->assertSame( 'Google', $connectors['google']['name'] );
    … …  
    105104         * @ticket 64730
    106105         */
    107         public function test_includes_registered_provider_from_registry() {
    108                 $connectors = _wp_connectors_get_connector_settings();
     106        public function test_includes_registered_provider_from_registry(): void {
     107                $connectors = wp_get_connectors();
    109108                $mock       = $connectors['mock_connectors_test'];
    110109
    … …  
    113112                $this->assertSame( 'ai_provider', $mock['type'] );
    114113                $this->assertSame( 'api_key', $mock['authentication']['method'] );
    115                 $this->assertNull( $mock['authentication']['credentials_url'] );
    116                 $this->assertSame( 'connectors_ai_mock_connectors_test_api_key', $mock['authentication']['setting_name'] );
    117         }
    118 
    119         /**
    120          * @ticket 64730
    121          */
    122         public function test_connectors_are_sorted_alphabetically() {
    123                 $connectors = _wp_connectors_get_connector_settings();
    124                 $keys       = array_keys( $connectors );
    125                 $sorted     = $keys;
    126                 sort( $sorted );
    127 
    128                 $this->assertSame( $sorted, $keys, 'Connectors should be sorted alphabetically by ID.' );
     114                $this->assertNull( $mock['authentication']['credentials_url'] ?? null );
     115                $this->assertSame( 'connectors_ai_mock_connectors_test_api_key', $mock['authentication']['setting_name'] ?? null );
    129116        }
    130117}
Note: See TracChangeset for help on using the changeset viewer.