From b7ad0b3978354e8e52f405327b3508f3ea08615f Mon Sep 17 00:00:00 2001 From: tellyworth Date: Mon, 8 Aug 2022 18:19:50 +1000 Subject: [PATCH 1/2] Add some crude smoke tests using phpunit --- tests/phpunit/smokeTest.php | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/phpunit/smokeTest.php diff --git a/tests/phpunit/smokeTest.php b/tests/phpunit/smokeTest.php new file mode 100644 index 00000000..02ed1b90 --- /dev/null +++ b/tests/phpunit/smokeTest.php @@ -0,0 +1,84 @@ +curl_body = curl_exec( $ch ); + $this->curl_error = curl_error( $ch ) ?: null; + + curl_close( $ch ); + + return $this->curl_body; + } + + public function urls() { + return array( + ['http://localhost:8888/'], + ['http://localhost:8888/download/'], + ); + } + + /** + * @dataProvider urls + */ + public function testHasBodyTag( $url ): void + { + $this->fetch_url( $url ); + + $this->assertStringContainsString( 'curl_body ); + $this->assertStringContainsString( '', $this->curl_body ); + } + + /** + * @dataProvider urls + */ + public function testClosingHtml( $url ): void + { + $this->fetch_url( $url ); + + $this->assertStringEndsWith( '', rtrim( $this->curl_body ) ); + } + + /** + * @dataProvider urls + */ + public function testHasTitle( $url ): void + { + $this->fetch_url( $url ); + + $this->assertRegExp( '#[^<>]+ WordPress.org#', $this->curl_body ); + } + + /** + * @dataProvider urls + */ + public function testHasMetaDescription( $url ): void + { + $this->fetch_url( $url ); + + $this->assertRegExp( '#]+" />#', $this->curl_body ); + $this->assertRegExp( '#]+" />#', $this->curl_body ); + } + + /** + * @dataProvider urls + */ + public function testHasHrefLang( $url ): void + { + $this->markTestSkipped( 'Requires https://github.com/WordPress/wporg-main-2022/pull/54' ); + $this->fetch_url( $url ); + + $this->assertRegExp( '##', $this->curl_body ); + } + +} From 19152f887dd488dbc1404b38e348403c7d07f9c7 Mon Sep 17 00:00:00 2001 From: tellyworth Date: Mon, 8 Aug 2022 18:20:03 +1000 Subject: [PATCH 2/2] Make it easy to run `yarn test` --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index de1fe518..838198a2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "backstop:test": "npm exec backstop test", "lighthouse": "lighthouse-ci http://localhost:8888/ --accessibility=100 --best-practices=100 --seo=100", "lighthouse:desktop": "lighthouse http://localhost:8888/ --view --preset=desktop --output-path=lighthouse.html", - "lighthouse:mobile": "lighthouse http://localhost:8888/ --view --screenEmulation.mobile --output-path=lighthouse.html" + "lighthouse:mobile": "lighthouse http://localhost:8888/ --view --screenEmulation.mobile --output-path=lighthouse.html", + "test": "./vendor/phpunit/phpunit/phpunit tests/phpunit" }, "workspaces": [ "source/wp-content/themes/wporg-main-2022"