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

feat: news data array adjusted for component loop, and test updated #768

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function index(Request $request): View
$promos['components'] = $modularComponents['modularComponents'];
}

$articles = $this->article->listing($request->data['base']['site']['news']['application_id']);
$articles['data'] = $this->article->listing($request->data['base']['site']['news']['application_id']);

$events = $this->event->getEvents($request->data['base']['site']['id']);

Expand Down
3 changes: 2 additions & 1 deletion app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public function configureComponents(array $components, array $promos, array $dat
} else {
$articles = $this->article->listing($components['components'][$name]['id'], $limit, 1, $component['topics'] ?? []);
}
$modularComponents[$name]['data'] = $articles['articles'] ?? [];
$modularComponents[$name]['data'] = $articles['articles']['data'] ?? [];
$modularComponents[$name]['meta'] = $articles['articles']['meta'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
} elseif (Str::startsWith($name, 'page-content') || Str::startsWith($name, 'heading')) {
// If there's JSON but no news, events or promo data, assign the component array as data
Expand Down
160 changes: 160 additions & 0 deletions factories/ArticleComponent.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed? It isn't referenced anywhere.

Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace Factories;

use Contracts\Factories\FactoryContract;
use Faker\Factory;

class ArticleComponent implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function create($limit = 1, $flatten = false, $options = [])
{
$hero = [
'featured' => 0,
'url' => '/styleguide/image/1600x580',
'caption' => $this->faker->sentence(rand(5, 10)),
'alt_text' => $this->faker->sentence(rand(5, 10)),
'type' => 'Hero Image',
];

$social = [
'featured' => 0,
'url' => '/styleguide/image/1600x580',
'caption' => $this->faker->sentence(rand(5, 10)),
'alt_text' => $this->faker->sentence(rand(5, 10)),
'type' => 'Social Image',
];

$featured = [
'featured' => 1,
'url' => '/styleguide/image/770x434',
'caption' => $this->faker->sentence(rand(5, 10)),
'alt_text' => $this->faker->sentence(rand(5, 10)),
'type' => 'Embeddable',
];

$faculty = [];
for ($i = 0; $i < 3; $i++) {
$faculty[] = [
'id' => $this->faker->randomDigit(),
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName(),
'accessid' => $this->faker->randomLetter().$this->faker->randomLetter().$this->faker->randomNumber(4, true),
];
}

$programs = [];
for ($i = 0; $i < 3; $i++) {
$programs[] = [
'name' => $this->faker->randomElement(['Accounting (BS)', 'Art Education (BA)', 'Biological Sciences (BA)', 'Chemical Engineering (MS)']),
'url' => 'https://wayne.edu',
];
}

$assets = [];
for ($i = 0; $i < 3; $i++) {
$assets[] = [
'id' => $this->faker->randomDigit(),
'url' => 'https://wayne.edu',
'caption' => $this->faker->sentence(),
'filename' => substr(md5($this->faker->sentence()), 0, 10).'.pdf',
];
}

for ($i = 1; $i <= $limit; $i++) {
$data[$i] = [
'id' => $i,
'user_id' => $this->faker->randomDigit(),
'application_id' => $this->faker->randomDigit(),
'favicon_id' => null,
'title' => $this->faker->sentence(rand(6, 10)),
'short_title' => $this->faker->sentence(rand(3, 6)),
'sub_title' => null,
'permalink' => $this->faker->slug(),
'meta_description' => $this->faker->sentence(),
'body' => '<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<figure class="figure" style="padding-bottom:10px; float:right">
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Figure%20float%20right" style="padding:10px" width="300">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph().'</p>
<blockquote class="blockquote1">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<blockquote class="blockquote2">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<p>&nbsp;</p>
<h2>'.$this->faker->paragraph(1).'</h2>
<figure class="figure" style="padding-bottom:10px; float:left">
<img alt="Placeholder" height="600" src="/styleguide/image/800x600?text=Figure%20float%20left" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<blockquote class="blockquote3">
<p>'.$this->faker->paragraph(5).'</p>
</blockquote>
<p>'.$this->faker->paragraph(15).'</p>
<div style="text-align:center">
<figure class="figure" style="display:inline-block">
<img alt="Placeholder" height="450" src="/styleguide/image/800x450?text=Figure%20centered" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
</div>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Image%20float%20right" style="padding:10px; float:right" width="300">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="300" src="/styleguide/image/400x300?text=Image%20float%20left" style="padding:10px; float:left" width="400">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<p style="text-align:center">
<img alt="Placeholder" height="350" src="/styleguide/image/800x350?text=Image%20centered" style="padding:10px" width="800">
</p>
<p>'.$this->faker->paragraph(8).'</p>
',
'article_date' => $this->faker->date(),
'status' => 'Published',
'link' => '/styleguide/'.config('base.news_view_route').'/item-1',
'hero_image' => $hero,
'social_image' => $social,
'featured' => $featured,
'files' => [
0 => $hero,
1 => $featured,
],
'assets' => $this->faker->randomElements($assets, rand(1, 3)),
'faculty' => $this->faker->randomElements($faculty, rand(1, 3)),
'programs' => $this->faker->randomElements($programs, rand(1, 3)),
'favicon' => null,
'user' => null,
'applications' => null,
];

$data[$i] = array_replace_recursive($data[$i], $options);
}

if ($limit === 1 && $flatten === true) {
$data = current($data);
}

return $data;
}
}
34 changes: 34 additions & 0 deletions factories/ArticleMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Factories;

use Contracts\Factories\FactoryContract;
use Faker\Factory;

class ArticleMeta implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function create($limit = 1, $flatten = false, $options = [])
{
$data = [
'total' => '',
'per_page' => '',
'current_page' => '',
'last_page' => 3,
'next_page_url' => '',
'prev_page_url' => '',
];

return $data;
}
}
4 changes: 2 additions & 2 deletions resources/views/components/news-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
$url => string '/news/'
$link_text => string // 'More news'
--}}
@if(!empty($data['data']))
@if(!empty($data))
<ul>
@foreach($data['data'] as $item)
@foreach($data as $item)
<li class="mb-4">
<a href="{{ $item['link'] }}" class="underline hover:no-underline font-normal">
{{ $item['title'] }}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/news-featured-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
$url => string '/news/'
$link_text => string // 'More news'
--}}
@if(!empty($data['data']))
@if(!empty($data))
<ul>
@foreach($data['data'] as $item)
@foreach($data as $item)
@if($loop->iteration === 1)
<li class="bg-green-800">
<a href="{{ $item['link'] }}" class="relative block mb-6 group">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/news-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
$url => string '/news.php'
$link_text => string // 'More news'
--}}
@if(!empty($data['data']))
@if(!empty($data))
<ul class="grid gap-x-6 gap-y-4 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-{{ !empty($component['limit']) ? $component['limit'] : '4' }}">
@foreach($data['data'] as $item)
@foreach($data as $item)
<li class="group flex items-start md:block">
<a class="group-hover:no-underline flex items-start md:block" href="{{ $item['link'] }}">
@image($item['featured']['url'] ?? 'https://wayne.edu/opengraph/wsu-social-share.png', $item['featured']['alt_text'] ?? 'Wayne State University', 'block lazy w-1/3 shrink-0 mr-2 mb-2 md:w-full md:mr-0 md:shrink')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use Factories\Spotlight;
use Factories\Button;
use Factories\GenericPromo;
use Factories\Article;
use Factories\ArticleMeta;
use Factories\ArticleComponent;
use Factories\Event;
use Factories\Video;

Expand Down Expand Up @@ -102,7 +103,8 @@ public function index(Request $request): View
],

'news-column' => [
'data' => app(Article::class)->create(3, false),
'data' => app(ArticleComponent::class)->create(3, false),
'meta' => app(ArticleMeta::class)->create(),
'component' => [
'filename' => 'news-column',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Illuminate\Http\Request;
use Faker\Factory;
use Factories\Article;
use Factories\ArticleMeta;
use Factories\ArticleComponent;

class ComponentArticleListingController extends Controller
{
Expand Down Expand Up @@ -85,21 +87,24 @@ public function index(Request $request): View
],
],
'news-column-1' => [
'data' => app(Article::class)->create(5, false),
'data' => app(ArticleComponent::class)->create(5, false),
'meta' => app(ArticleMeta::class)->create(),
'component' => [
'heading' => 'News column',
'filename' => 'news-column',
],
],
'news-featured-column-1' => [
'data' => app(Article::class)->create(4, false),
'data' => app(ArticleComponent::class)->create(4, false),
'meta' => app(ArticleMeta::class)->create(),
'component' => [
'heading' => 'Featured news column',
'filename' => 'news-featured-column',
],
],
'news-row-1' => [
'data' => app(Article::class)->create(4, false),
'data' => app(ArticleComponent::class)->create(4, false),
'meta' => app(ArticleMeta::class)->create(),
'component' => [
'heading' => 'News row',
'filename' => 'news-row',
Expand Down
6 changes: 4 additions & 2 deletions styleguide/Http/Controllers/FullWidthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use Factories\Spotlight;
use Factories\Button;
use Factories\GenericPromo;
use Factories\Article;
use Factories\ArticleMeta;
use Factories\ArticleComponent;
use Factories\Event;

class FullWidthController extends Controller
Expand Down Expand Up @@ -123,7 +124,8 @@ public function index(Request $request): View
],

'news_row' => [
'data' => app(Article::class)->create(4, false),
'data' => app(ArticleComponent::class)->create(4, false),
'meta' => app(ArticleMeta::class)->create(),
'component' => [
'heading' => 'Featured news',
'filename' => 'news-row',
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Repositories/ModularPageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function get_modular_page_components_featured_news(): void
// Run the promos through the repository
$modularComponents = app(ModularPageRepository::class, ['wsuApi' => $wsuApi])->getModularComponents($data);

$this->assertCount(count($return['data']), $modularComponents['news-row-1']['data']['data']);
$this->assertCount(count($return['data']), $modularComponents['news-row-1']['data']);
}

#[Test]
Expand Down Expand Up @@ -226,7 +226,7 @@ public function get_modular_page_components_news(): void
// Run the promos through the repository
$modularComponents = app(ModularPageRepository::class, ['wsuApi' => $wsuApi])->getModularComponents($data);

$this->assertCount(count($return['data']), $modularComponents['news-column-1']['data']['data']);
$this->assertCount(count($return['data']), $modularComponents['news-column-1']['data']);
}

#[Test]
Expand Down
Loading