Skip to content

Commit

Permalink
Add base_language for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
rowasc committed May 21, 2020
1 parent fb4fd18 commit 3dcc21e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
25 changes: 25 additions & 0 deletions migrations/20200521014822_add_base_language_to_categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddBaseLanguageToCategories extends AbstractMigration
{
public function up()
{

$result = $this->fetchRow(
"SELECT config_value FROM config WHERE group_name='site' and config_key='language' "
);
// get two letter lang code
$language = str_before(json_decode($result['config_value']), '-');
$this->table('tags')
->addColumn('base_language', 'string', ['null' => false, 'default' => $language]) //es/en
->update();
}


public function down()
{
$this->table('tags')->removeColumn('base_language');
}
}
42 changes: 40 additions & 2 deletions tests/integration/v4/tags.v4.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@tagsFixture @rolesEnabled
Feature: Testing the Categories API
Scenario: Creating a new Tag
Scenario: Creating a new Tag with a base language
Given that I want to make a new "Category"
And that the oauth token is "testadminuser"
And that the api_url is "api/v4"
Expand All @@ -14,6 +14,7 @@ Feature: Testing the Categories API
"type":"category",
"priority":1,
"color":"00ff00",
"base_language": "en",
"role": ["admin", "user"]
}
"""
Expand All @@ -27,10 +28,47 @@ Feature: Testing the Categories API
And the "result.color" property equals "#00ff00"
And the "result.priority" property equals "1"
And the "result.type" property equals "category"
And the "result.enabled_languages.default" property equals "en"
And the response has a "result.role" property
And the "result.parent.id" property equals "1"
Then the guzzle status code should be 201
Scenario: Creating a new Tag with a base language and translation
Given that I want to make a new "Category"
And that the oauth token is "testadminuser"
And that the api_url is "api/v4"
And that the request "data" is:
"""
{
"parent_id":1,
"tag":"Boxes with a translation",
"description":"Is this a box? Awesome",
"type":"category",
"priority":1,
"color":"00ff00",
"base_language": "en",
"role": ["admin", "user"],
"translations": {
"es": {
"tag": "Cajas"
}
}
}
"""
When I request "/categories"
Then the response is JSON
And the response has a "result.id" property
And the type of the "result.id" property is "numeric"
And the "result.tag" property equals "Boxes with a translation"
And the "result.slug" property equals "boxes-with-a-translation"
And the "result.description" property equals "Is this a box? Awesome"
And the "result.color" property equals "#00ff00"
And the "result.priority" property equals "1"
And the "result.type" property equals "category"
And the "result.enabled_languages.default" property equals "en"
And the "result.enabled_languages.available.0" property equals "es"
And the response has a "result.role" property
And the "result.parent.id" property equals "1"
Then the guzzle status code should be 201

Scenario: Creating a duplicate tag
Given that I want to make a new "Category"
And that the oauth token is "testadminuser"
Expand Down
4 changes: 4 additions & 0 deletions v4/Http/Resources/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function toArray($request)
'children' => $this->children,
'parent' => $this->parent,
'translations' => new TranslationCollection($this->translations),
'enabled_languages' => [
'default'=> $this->base_language,
'available' => $this->translations->groupBy('language')->keys()
]
];
}
}
3 changes: 2 additions & 1 deletion v4/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Category extends Model
'icon',
'description',
'role',
'priority'
'priority',
'base_language'
];

/**
Expand Down

0 comments on commit 3dcc21e

Please sign in to comment.