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

[2.4] Fixed flakey meta seo tests #3587

Merged
merged 1 commit into from
May 12, 2019
Merged
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
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