added client web page test

pull/49/head
A1Gard 4 months ago
parent 1b47932a06
commit b7665af600

@ -816,25 +816,48 @@ function getGroupBySetting($key)
}
/**
* get group by setting key
* get menu by setting key
* @param $key
* @return Menu
*/
function getMenuBySetting($key)
{
if (Menu::count() == 0) {
return [];
}
return Menu::where('id', getSetting($key) ?? 1)->first();
}
/**
* get menu's items by setting key
* @param $key
* @return array
*/
function getMenuBySettingItems($key)
{
if (Menu::count() == 0) {
return [];
}
$r = Menu::where('id', getSetting($key) ?? 1)->first();
if ($r == null) {
$r = Menu::first();
}
return $r->items;
}
/**
* get group's posts by setting key
* @param $key
* @param integer $limit
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C|array
*/
function getGroupPostsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC")
{
return Group::where('id', getSetting($key) ?? 1)->first()
->posts()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get();
$g = Group::where('id', getSetting($key) ?? 1)->first();
if ($g == null) {
return [];
}
return $g->posts()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get();
}
/**
@ -857,12 +880,15 @@ function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "D
* @param integer $limit
* @param string $order
* @param string $dir
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C | array
*/
function getCategorySubCatsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC")
{
return Category::where('id', getSetting($key) ?? 1)->first()
->children()->orderBy($order, $dir)->limit($limit)->get();
$c = Category::where('id', getSetting($key) ?? 1)->first();
if ($c == null) {
return [];
}
return $c->children()->orderBy($order, $dir)->limit($limit)->get();
}
/**
@ -994,6 +1020,7 @@ function postsUrl()
{
return fixUrlLang(\route('client.posts'));
}
/**
* products url to best experience for multi lang shops
* @return string
@ -1002,6 +1029,7 @@ function productsUrl()
{
return fixUrlLang(\route('client.products'));
}
/**
* clips url to best experience for multi lang shops
* @return string
@ -1010,6 +1038,7 @@ function clipsUrl()
{
return fixUrlLang(\route('client.clips'));
}
/**
* galleries url to best experience for multi lang shops
* @return string
@ -1018,6 +1047,7 @@ function gallariesUrl()
{
return fixUrlLang(\route('client.galleries'));
}
/**
* attachments url to best experience for multi lang shops
* @return string
@ -1101,11 +1131,11 @@ function transports()
*/
function defTrannsport()
{
if (\App\Models\Transport::where('is_default',1)->count() == 0){
if (\App\Models\Transport::where('is_default', 1)->count() == 0) {
return null;
}
return \App\Models\Transport::where('is_default',1)->first()->id;
return \App\Models\Transport::where('is_default', 1)->first()->id;
}
@ -1114,7 +1144,8 @@ function defTrannsport()
* @param $array
* @return false|string
*/
function vueTranslate($array){
function vueTranslate($array)
{
return json_encode($array);
}
@ -1137,7 +1168,7 @@ function markUpBreadcrumbList($items)
"name" => $index,
];
if ($item != '' || $item != null) {
$json[$i-1]['item'] = $item;
$json[$i - 1]['item'] = $item;
}
}
@ -1166,9 +1197,9 @@ RESULT;
*/
function fixUrlLang($url)
{
if ( config('app.xlang.active') && app()->getLocale() != config('app.xlang.main')){
if (config('app.xlang.active') && app()->getLocale() != config('app.xlang.main')) {
$welcome = \route('client.welcome');
return str_replace($welcome,$welcome .'/'.app()->getLocale(),$url);
return str_replace($welcome, $welcome . '/' . app()->getLocale(), $url);
}
return $url;
}

@ -20,8 +20,6 @@ class AreaController extends Controller
public function desgin(Area $area)
{
$valids = [];
foreach ($area->segment as $seg) {
if (File::exists(resource_path() . '/views/segments/' . $seg)) {

@ -87,7 +87,7 @@ class PartSeeder extends Seeder
$part = new Part();
$part->segment = 'menu';
$part->part = 'AplMenu';
$part->area_id = Area::where('name', 'index')->first()->id;
$part->area_id = Area::where('name', 'default_header')->first()->id;
$part->sort = 0;
$part->save();

@ -7,7 +7,7 @@
</a>
</li>
@foreach(getMenuBySetting($data->area->name.'_'.$data->part.'_menu')->items as $item)
@foreach(getMenuBySettingItems($data->area->name.'_'.$data->part.'_menu') as $item)
<li>
@if($item->meta == null)
<a href="{{$item->webUrl()}}">

@ -146,4 +146,8 @@
}
}
}
~header{
margin-top: 44px;
}
}

@ -5,7 +5,7 @@
<i class="ri-menu-line"></i>
</a>
</li>
@foreach(getMenuBySetting($data->area->name.'_'.$data->part.'_menu')->items as $item)
@foreach(getMenuBySettingItems($data->area->name.'_'.$data->part.'_menu') as $item)
<li>
<a href="{{$item->webUrl()}}">
{{$item->title}}

@ -1,12 +1,12 @@
<section class='PostIndexImage'>
<div class="{{gfx()['container']}}">
<h1>
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')->webUrl()}}">
{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')->name}}
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')?->webUrl()}}">
{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')?->name}}
</a>
</h1>
<p class="text-muted">
{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')->description}}
{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')?->description}}
</p>
<div class="row">
@foreach( getGroupPostsBySetting($data->area->name.'_'.$data->part.'_group',4) as $post )
@ -28,7 +28,7 @@
@endforeach
</div>
<div class="py-5 text-center">
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')->webUrl()}}" class="btn btn-outline-primary">
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part.'_group')?->webUrl()}}" class="btn btn-outline-primary">
{{getSetting($data->area->name.'_'.$data->part.'_btn')}}
</a>
</div>

@ -1,12 +1,12 @@
<section class='PostsIconSimple py-4'>
<div class="{{gfx()['container']}}">
<h1>
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part)->webUrl()}}">
{{getGroupBySetting($data->area->name.'_'.$data->part)->name}}
<a href="{{getGroupBySetting($data->area->name.'_'.$data->part)?->webUrl()}}">
{{getGroupBySetting($data->area->name.'_'.$data->part)?->name}}
</a>
</h1>
<p>
{{getGroupBySetting($data->area->name.'_'.$data->part)->description}}
{{getGroupBySetting($data->area->name.'_'.$data->part)?->description}}
</p>
<div class="row">
@foreach(getGroupPostsBySetting($data->area->name.'_'.$data->part, getSetting($data->area->name.'_'.$data->part.'_limit')) as $post)
@ -20,7 +20,7 @@
{{$post->subtitle}}
</p>
<a href="{{$post->webUrl()}}" class="btn btn-outline-primary w-100">
<a href="{{$post?->webUrl()}}" class="btn btn-outline-primary w-100">
{{__("Read more")}}
</a>
</div>

@ -0,0 +1,75 @@
<?php
namespace Tests\Feature;
use App\Models\Category;
use App\Models\Group;
use App\Models\Post;
use App\Models\Product;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class ClientWebPagesTest extends TestCase
{
public function test_web_client_index(): void
{
$response = $this->get(route('client.welcome'));
$response->assertStatus(200);
}
public function test_web_client_posts(): void
{
$response = $this->get(route('client.posts'));
$response->assertStatus(200);
}
public function test_web_client_products(): void
{
$response = $this->get(route('client.products'));
$response->assertStatus(200);
}
public function test_web_client_product(): void
{
if (Product::count() == 0) {
Product::factory(1)->create();
}
$response = $this->get(Product::first()->webUrl());
$response->assertStatus(200);
}
public function test_web_client_post(): void
{
if (Post::count() == 0) {
Post::factory(1)->create();
}
$response = $this->get(Post::first()->webUrl());
$response->assertStatus(200);
}
public function test_web_client_group(): void
{
if (Group::count() == 0) {
Group::factory(1)->create();
}
$response = $this->get(Group::first()->webUrl());
$response->assertStatus(200);
}
public function test_web_client_category(): void
{
if (Category::count() == 0) {
Category::factory(1)->create();
}
$response = $this->get(Category::first()->webUrl());
$response->assertStatus(200);
}
}

@ -3,17 +3,22 @@
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Log;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response = $this->get(route('client.welcome'));
$response->assertStatus(200);
}
}

@ -1,16 +0,0 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}
Loading…
Cancel
Save