Skip to content

Commit

Permalink
Merge branch 'feature/tests' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Oct 19, 2023
2 parents 169e99a + bbc2d97 commit 40ff1a0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
1 change: 0 additions & 1 deletion .phpunit.cache/test-results

This file was deleted.

3 changes: 1 addition & 2 deletions app/Http/Controllers/ModularPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function index(Request $request)
{
$promos['promos'] = $this->promo->getModularPromos($request->data['base']);

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

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

Expand Down
2 changes: 1 addition & 1 deletion factories/GenericPromo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function create($limit = 1, $flatten = false, $options = [])
'excerpt' => $this->faker->sentence(),
'description' => '<p>' . $this->faker->text(100) . ' <a href="https://wayne.edu">'. $this->faker->sentence(3) .'</a></p>',
'link' => 'https://wayne.edu',
'promo_item_id' => strval($this->faker->randomNumber(5)),
'promo_item_id' => $i,
'promo_group_id' => strval($promo_group_id),
'relative_url' => '/styleguide/image/600x450?text=600x450:'.$i, // 4:3
//'relative_url' => '/styleguide/image/450x600', // 3:4
Expand Down
90 changes: 90 additions & 0 deletions tests/Unit/Repositories/ModularPageRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Tests\Unit\Repositories;

use PHPUnit\Framework\Attributes\Test;
use App\Repositories\ModularPageRepository;
use Factories\Page;
use Factories\GenericPromo;
use Tests\TestCase;
use Mockery as Mockery;
use Waynestate\Api\Connector;

final class ModularPageRepositoryTest extends TestCase
{
#[Test]
public function get_modular_page_promos_with_json_array(): void
{
$page_id = $this->faker->numberbetween(10, 50);
$promo_group_id = $this->faker->numberbetween(1, 3);

// Fake return
$return['promotions'] = app(GenericPromo::class)->create(5, false, [
'promo_group_id' => $promo_group_id,
'page_id' => $page_id,
'group' => [
'promo_group_id' => $promo_group_id,
],
]);

// Create a fake data request
$data = app(Page::class)->create(1, true, [
'page' => [
'controller' => 'ModularPage',
'id' => $page_id,
],
'data' => [
'modular-accordion-1' => '{
"id":'. $promo_group_id .',
"config":"randomize|limit:20|page_id|first",
"columns":"",
"singlePromoView":"true",
"showExcerpt":"true",
"showDescription":"true",
}',
],
]);

// Mock the connector and set the return
$wsuApi = Mockery::mock(Connector::class);
$wsuApi->shouldReceive('sendRequest')->with('cms.promotions.listing', Mockery::type('array'))->once()->andReturn($return);

// Run the promos through the repository
$promos = app(ModularPageRepository::class, ['wsuApi' => $wsuApi])->getModularPromos($data);

$this->assertCount(count($return['promotions']), $promos['accordion-1']);
}

#[Test]
public function get_modular_page_promos_with_promo_id_only(): void
{
$promo_group_id = $this->faker->numberbetween(1, 3);

// Fake return
$return['promotions'] = app(GenericPromo::class)->create(5, false, [
'promo_group_id' => $promo_group_id,
'group' => [
'promo_group_id' => $promo_group_id,
],
]);

// Create a fake data request
$data = app(Page::class)->create(1, true, [
'page' => [
'controller' => 'ModularPage',
],
'data' => [
'modular-accordion-1' => $promo_group_id,
],
]);

// Mock the connector and set the return
$wsuApi = Mockery::mock(Connector::class);
$wsuApi->shouldReceive('sendRequest')->with('cms.promotions.listing', Mockery::type('array'))->once()->andReturn($return);

// Run the promos through the repository
$promos = app(ModularPageRepository::class, ['wsuApi' => $wsuApi])->getModularPromos($data);

$this->assertCount(count($return['promotions']), $promos['accordion-1']);
}
}

0 comments on commit 40ff1a0

Please sign in to comment.