Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smoke tests #56

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
84 changes: 84 additions & 0 deletions tests/phpunit/smokeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
use PHPUnit\Framework\TestCase;

class SmokeTest extends TestCase {

private $curl_body;
private $curl_error;

public function fetch_url( $url ) {
$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADER, 0 );

$this->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( '<body', $this->curl_body );
$this->assertStringContainsString( '</body>', $this->curl_body );
}

/**
* @dataProvider urls
*/
public function testClosingHtml( $url ): void
{
$this->fetch_url( $url );

$this->assertStringEndsWith( '</html>', rtrim( $this->curl_body ) );
}

/**
* @dataProvider urls
*/
public function testHasTitle( $url ): void
{
$this->fetch_url( $url );

$this->assertRegExp( '#<title>[^<>]+ WordPress.org</title>#', $this->curl_body );
}

/**
* @dataProvider urls
*/
public function testHasMetaDescription( $url ): void
{
$this->fetch_url( $url );

$this->assertRegExp( '#<meta name="description" content="[^"<>]+" />#', $this->curl_body );
$this->assertRegExp( '#<meta property="og:description" content="[^"<>]+" />#', $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( '#<link rel="alternate" hreflang="\w\w-\w\w" />#', $this->curl_body );
}

}