Skip to content

Commit

Permalink
Fixed flakey meta seo tests (#3587)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed May 12, 2019
1 parent 7dd96f0 commit 5874df2
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions tests/Functional/Incident/MetaSeoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CachetHQ\Cachet\Settings\Repository as SettingsRepository;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Str;

/**
* This is the create incident command test class.
Expand All @@ -38,6 +39,11 @@ class MetaSeoTest extends AbstractTestCase
*/
protected $appName;

/**
* @var array[]|null
*/
protected $incidents;

/**
* CreateIncidentCommandTest constructor.
*
Expand All @@ -60,6 +66,10 @@ public function setUp()
parent::setUp();
$this->app->make(SettingsRepository::class)->set('app_name', $this->appName);
$this->app->config->set('setting.app_name', $this->appName);
$this->incidents = [
['title' => 'Foo '.Str::random(16), 'description' => 'Foo Bar Baz '.Str::random(32)],
['title' => 'Foe '.Str::random(16), 'description' => 'Foe Baz Bar '.Str::random(32)],
];
}

/**
Expand All @@ -68,9 +78,9 @@ public function setUp()
*/
public function testCustomSeoDescriptionOnIncidentPage()
{
$expectedDescription = htmlspecialchars($this->fakerFactory->sentence);
$expectedDescription = $this->incidents[0]['description'];

$incident = $this->createIncidentWithMeta(['seo' => ['description' => $expectedDescription]]);
$incident = $this->createIncidentWithMeta($this->incidents[1], ['seo' => ['description' => $expectedDescription]]);
$page = $this->get(sprintf('/incidents/%d', $incident->id));

$this->assertContains(
Expand All @@ -89,9 +99,9 @@ public function testCustomSeoDescriptionOnIncidentPage()
*/
public function testCustomSeoTitleOnIncidentPage()
{
$title = htmlspecialchars($this->fakerFactory->title);
$title = $this->incidents[0]['title'];

$incident = $this->createIncidentWithMeta(['seo' => ['title' => $title]]);
$incident = $this->createIncidentWithMeta($this->incidents[1], ['seo' => ['title' => $title]]);
$page = $this->get(sprintf('/incidents/%d', $incident->id));

$this->assertContains(
Expand All @@ -110,13 +120,13 @@ public function testCustomSeoTitleOnIncidentPage()
*/
public function testNoCustomSeoDescriptionOnIncidentPage()
{
$incident = $this->createIncidentWithMeta([]);
$incident = $this->createIncidentWithMeta($this->incidents[1]);
$presenter = $this->app->make(IncidentPresenter::class);
$presenter->setWrappedObject($incident);

$expectedDescription = sprintf(
'Details and updates about the %s incident that occurred on %s',
htmlspecialchars($incident->name),
$incident->name,
$presenter->occurred_at_formatted
);

Expand All @@ -138,8 +148,8 @@ public function testNoCustomSeoDescriptionOnIncidentPage()
*/
public function testNoCustomSeoTitleOnIncidentPage()
{
$incident = $this->createIncidentWithMeta([]);
$expectedTitle = sprintf('%s | %s', htmlspecialchars($incident->name), $this->appName);
$incident = $this->createIncidentWithMeta($this->incidents[1]);
$expectedTitle = sprintf('%s | %s', $incident->name, $this->appName);

$page = $this->get(sprintf('/incidents/%d', $incident->id));

Expand All @@ -151,15 +161,16 @@ public function testNoCustomSeoTitleOnIncidentPage()
}

/**
* @param array $incident
* @param array $meta
*
* @return Incident
*/
protected function createIncidentWithMeta(array $meta)
protected function createIncidentWithMeta(array $incident, array $meta = [])
{
$this->signIn();
$name = $this->fakerFactory->name;
$message = $this->fakerFactory->sentence;
$name = $incident['title'];
$message = $incident['description'];

dispatch(new CreateIncidentCommand(
$name,
Expand Down

0 comments on commit 5874df2

Please sign in to comment.