From 279ec6cf40f0b3e809b3fc0693cd4ea2d7ca1be8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 24 Nov 2023 13:54:58 +0100 Subject: [PATCH 1/7] Use `assertObjectHasProperty` in tests --- tests/php/src/Infrastructure/SimpleInjectorTest.php | 4 ++-- tests/php/validation/test-class-amp-validation-manager.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/php/src/Infrastructure/SimpleInjectorTest.php b/tests/php/src/Infrastructure/SimpleInjectorTest.php index faa62a50767..02722935e75 100644 --- a/tests/php/src/Infrastructure/SimpleInjectorTest.php +++ b/tests/php/src/Infrastructure/SimpleInjectorTest.php @@ -127,7 +127,7 @@ static function ( $class ) { $object = $injector->make( Fixture\DummyInterface::class ); $this->assertInstanceOf( stdClass::class, $object ); - $this->assertObjectHasAttribute( 'class_name', $object ); + $this->assertObjectHasProperty( 'class_name', $object ); $this->assertEquals( Fixture\DummyInterface::class, $object->class_name ); } @@ -148,7 +148,7 @@ static function ( $class ) { $object = $injector->make( Fixture\DummyInterface::class ); $this->assertInstanceOf( stdClass::class, $object ); - $this->assertObjectHasAttribute( 'class_name', $object ); + $this->assertObjectHasProperty( 'class_name', $object ); $this->assertEquals( Fixture\DummyClassWithDependency::class, $object->class_name ); } diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index ce931a4a52a..0ee6975bdcb 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -535,7 +535,7 @@ public function test_add_admin_bar_menu_items() { wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); $this->assertTrue( current_user_can( 'manage_options' ) ); AMP_Validation_Manager::add_admin_bar_menu_items( $admin_bar ); - $this->assertObjectHasAttribute( 'href', $admin_bar->get_node( 'amp-settings' ) ); + $this->assertObjectHasProperty( 'href', $admin_bar->get_node( 'amp-settings' ) ); } /** From 3f9fb7f4284639ec07a272e821ce818c6393729d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 24 Nov 2023 13:58:51 +0100 Subject: [PATCH 2/7] Use `setStaticPropertyValue` --- tests/php/src/Helpers/PrivateAccess.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/php/src/Helpers/PrivateAccess.php b/tests/php/src/Helpers/PrivateAccess.php index 4e2ed604fd7..d984b608249 100644 --- a/tests/php/src/Helpers/PrivateAccess.php +++ b/tests/php/src/Helpers/PrivateAccess.php @@ -59,12 +59,11 @@ private function call_private_static_method( $class, $method_name, $args = [] ) * @throws ReflectionException If the object could not be reflected upon. */ private function set_private_property( $object, $property_name, $value ) { - $property = ( new ReflectionClass( $object ) )->getProperty( $property_name ); + $reflection_class = new ReflectionClass( $object ); + $property = $reflection_class->getProperty( $property_name ); $property->setAccessible( true ); - // Note: In PHP 8, `ReflectionProperty::getValue()` now requires that an object be supplied if it's a - // non-static property. - $property->isStatic() ? $property->setValue( $value ) : $property->setValue( $object, $value ); + $property->isStatic() ? $reflection_class->setStaticPropertyValue( $property_name, $value ) : $property->setValue( $object, $value ); } /** From 69493d90a82791f15aec71122d3f3501fdd2304d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 28 Nov 2023 09:12:02 +0100 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Weston Ruter --- tests/php/src/Helpers/PrivateAccess.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/php/src/Helpers/PrivateAccess.php b/tests/php/src/Helpers/PrivateAccess.php index d984b608249..9c26466754f 100644 --- a/tests/php/src/Helpers/PrivateAccess.php +++ b/tests/php/src/Helpers/PrivateAccess.php @@ -60,10 +60,14 @@ private function call_private_static_method( $class, $method_name, $args = [] ) */ private function set_private_property( $object, $property_name, $value ) { $reflection_class = new ReflectionClass( $object ); - $property = $reflection_class->getProperty( $property_name ); + $property = $reflection_class->getProperty( $property_name ); $property->setAccessible( true ); - $property->isStatic() ? $reflection_class->setStaticPropertyValue( $property_name, $value ) : $property->setValue( $object, $value ); + if ( $property->isStatic() ) { + $reflection_class->setStaticPropertyValue( $property_name, $value ); + } else { + $property->setValue( $object, $value ); + } } /** From 52cf373f476c46c107e7d028b7b263f42adb1128 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 28 Nov 2023 22:41:54 +0530 Subject: [PATCH 4/7] Update unit tests after GB plugin update --- tests/php/validation/test-class-amp-validation-manager.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index 0ee6975bdcb..f905d0ad529 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -1438,6 +1438,9 @@ public function test_add_block_source_comments( $content, $expected, $query ) { // Remove class name injected by gutenberg_render_layout_support_flag(). $rendered_block = preg_replace( '/\s*(?<= class=")?wp-container-\w+\s*/', '', $rendered_block ); + // Remove unique layout ID. + $rendered_block = preg_replace( '/\s*(?<= class=")?has-\d+-columns-columns-layout-\d+\s*/', ' has-2-columns', $rendered_block ); + $expected = str_replace( [ '{{post_id}}', From 5a8422334f2d6ab9ac0b6f3221674a1d563f9928 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 28 Nov 2023 22:57:14 +0530 Subject: [PATCH 5/7] Update failing tests due to quote block changes after GB plugin update --- tests/php/validation/test-class-amp-validation-manager.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index f905d0ad529..6fb0708306d 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -1441,6 +1441,13 @@ public function test_add_block_source_comments( $content, $expected, $query ) { // Remove unique layout ID. $rendered_block = preg_replace( '/\s*(?<= class=")?has-\d+-columns-columns-layout-\d+\s*/', ' has-2-columns', $rendered_block ); + // Remove layout class name and ID. + $rendered_block = str_replace( + ' is-layout-flow wp-block-quote-is-layout-flow', + '', + $rendered_block + ); + $expected = str_replace( [ '{{post_id}}', From 23601b38c7b510406f1a29db28fe5da6cfba0b07 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 28 Nov 2023 23:29:33 +0530 Subject: [PATCH 6/7] Update xpath to evaluate notices in WP admin --- tests/e2e/utils/amp-settings-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/amp-settings-utils.js b/tests/e2e/utils/amp-settings-utils.js index 382c43d166c..c1ef7e13c7e 100644 --- a/tests/e2e/utils/amp-settings-utils.js +++ b/tests/e2e/utils/amp-settings-utils.js @@ -131,7 +131,7 @@ export async function cleanUpValidatedUrls() { await page.click('#doaction'); await page.waitForXPath( - '//*[contains(@class, "updated notice")]/p[contains(text(), "forgotten")]' + '//*[contains(@class, "notice") and contains(@class, "updated")]/p[contains(text(), "forgotten")]' ); await switchUserToTest(); } From f138b04512e504bb988ead38e67e8ea19bb386ef Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 28 Nov 2023 23:37:58 +0530 Subject: [PATCH 7/7] Update puppeteer caching step in workflows --- .github/actions/setup-node-npm/action.yml | 9 ++++++++- .github/workflows/build-test-measure.yml | 6 ------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/actions/setup-node-npm/action.yml b/.github/actions/setup-node-npm/action.yml index 8f364bb8bc3..ef80aa8a5d0 100644 --- a/.github/actions/setup-node-npm/action.yml +++ b/.github/actions/setup-node-npm/action.yml @@ -6,7 +6,7 @@ runs: using: 'composite' steps: - name: Configure Node.js cache - uses: actions/cache@v3.3.1 + uses: actions/cache@v3.3.2 id: node-npm-cache env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5' @@ -14,6 +14,13 @@ runs: path: node_modules key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/actions/setup-node-npm/action.yml') }} + # Since it gets downloaded with npm install, we need to cache it instantly. + - name: Setup puppeteer cache + uses: actions/cache@v3.3.2 + with: + path: ~/.cache/puppeteer + key: ${{ runner.os }}-puppeteer + - name: Setup Node.js uses: actions/setup-node@v4 with: diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index 252014cb9ee..08a150ed9dd 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -223,12 +223,6 @@ jobs: path: ~/.jest-cache key: ${{ runner.os }}-jest-e2e-${{ matrix.part }} - - name: Setup puppeteer cache - uses: actions/cache@v3.3.2 - with: - path: ~/.cache/puppeteer - key: ${{ runner.os }}-puppeteer - - name: Start Docker environment run: npm run env:start:ci env: