Skip to content

Commit 4f9aa54

Browse files
authored
Fix save on null error (#313)
* Fix save on null (ie. page with disabled SEO). * Add test coverage.
1 parent 4d1f6ab commit 4f9aa54

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Reporting/Chunk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function generate($ids)
5858
$content = Cache::get($this->report->cacheKey(Report::CONTENT_CACHE_KEY_SUFFIX));
5959

6060
foreach ($ids as $id) {
61-
$this->createPage($content[$id] ?? Data::find($id))->save();
61+
$this->createPage($content[$id] ?? Data::find($id))?->save();
6262
}
6363

6464
File::delete($this->folderPath());

tests/ReportTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,41 @@ public function it_can_generate_a_large_report_with_multiple_chunked_jobs()
140140
$this->assertCount(10, $this->files->allFiles($this->reportsPath('1/pages')));
141141
}
142142

143+
/** @test */
144+
public function it_skips_over_pages_with_disabled_seo()
145+
{
146+
$this
147+
->generateEntries(5)
148+
->generateTerms(5);
149+
150+
$this->assertFileNotExists($this->reportsPath());
151+
152+
Entry::all()->first()->set('seo', false)->save();
153+
154+
Carbon::setTestNow($now = now());
155+
Report::create()->save()->generate();
156+
157+
$expected = <<<"EXPECTED"
158+
date: $now->timestamp
159+
status: fail
160+
score: 76.0
161+
pages_crawled: 9
162+
results:
163+
SiteName: true
164+
UniqueTitleTag: 0
165+
UniqueMetaDescription: 9
166+
NoUnderscoresInUrl: 0
167+
ThreeSegmentUrls: 0
168+
169+
EXPECTED;
170+
171+
$this->assertCount(1, $this->files->files($this->reportsPath('1')));
172+
$this->assertEquals($expected, $this->files->get($this->reportsPath('1/report.yaml')));
173+
174+
$this->assertFileExists($this->reportsPath('1/pages'));
175+
$this->assertCount(9, $this->files->allFiles($this->reportsPath('1/pages')));
176+
}
177+
143178
public function reportsPath($path = null)
144179
{
145180
if ($path) {

0 commit comments

Comments
 (0)