Skip to content

Commit f0fd10e

Browse files
authored
Merge pull request #31 from UseMuffin/slug-associated
Slug associated
2 parents c44c6eb + c3696ed commit f0fd10e

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

.travis.yml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ php:
44
- 5.5
55
- 5.6
66
- 7.0
7+
- 7.1
78

89
sudo: false
910

@@ -23,30 +24,24 @@ matrix:
2324
- php: 7.0
2425
env: PHPCS=1 DEFAULT=0
2526

26-
- php: 7.0
27-
env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test'
28-
2927
before_script:
30-
- sh -c "if [ '$COVERALLS' != '1' ]; then phpenv config-rm xdebug.ini; fi"
28+
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi
29+
30+
- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
31+
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
3132

3233
- composer self-update
3334
- composer install --prefer-dist --no-interaction
3435

35-
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
36-
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
37-
38-
- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"
39-
40-
- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
41-
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"
36+
- if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:"^3.0"; fi
4237

4338
script:
44-
- sh -c "if [ '$DEFAULT' = '1' ]; then phpunit; fi"
45-
46-
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
39+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
40+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
41+
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
4742

48-
- sh -c "if [ '$COVERALLS' = '1' ]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover build/logs/clover.xml || true; fi"
49-
- sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/coveralls -v; fi"
43+
after_success:
44+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi
5045

5146
notifications:
5247
email: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Slug
22

33
[![Build Status](https://img.shields.io/travis/UseMuffin/Slug/master.svg?style=flat-square)](https://travis-ci.org/UseMuffin/Slug)
4-
[![Coverage](https://img.shields.io/coveralls/UseMuffin/Slug/master.svg?style=flat-square)](https://coveralls.io/r/UseMuffin/Slug)
4+
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Slug/master.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Slug)
55
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/slug.svg?style=flat-square)](https://packagist.org/packages/muffin/slug)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
77

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"require-dev": {
3737
"cakephp/cakephp": "^3.2.7",
38-
"phpunit/phpunit": "4.1.*",
38+
"phpunit/phpunit": "<6.0",
3939
"cocur/slugify": "^1.2"
4040
},
4141
"autoload": {

src/Model/Behavior/SlugBehavior.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SlugBehavior extends Behavior
4646
*
4747
* @var array
4848
*/
49-
public $_defaultConfig = [
49+
protected $_defaultConfig = [
5050
'field' => 'slug',
5151
'displayField' => null,
5252
'separator' => '-',
@@ -262,7 +262,7 @@ public function slug($entity, $string = null, $separator = '-')
262262
if ($entity->errors($field)) {
263263
throw new InvalidArgumentException();
264264
}
265-
$string[] = $entity->get($field);
265+
$string[] = $value = Hash::get($entity, $field);
266266
}
267267
$string = implode($separator, $string);
268268
}

tests/TestCase/Model/Behavior/SlugBehaviorTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ public function testSlug()
157157
$this->assertEquals($expected, $result);
158158
}
159159

160+
public function testSlugWithAssociatedTableField()
161+
{
162+
$Articles = TableRegistry::get('Muffin/Slug.Articles', ['table' => 'slug_articles']);
163+
$Authors = TableRegistry::get('Muffin/Slug.Authors', ['table' => 'slug_authors']);
164+
165+
$Articles->belongsTo('Authors', ['className' => 'Muffin/Slug.Authors']);
166+
$Articles->addBehavior('Muffin/Slug.Slug', ['displayField' => ['author.name', 'title']]);
167+
168+
$data = ['title' => 'foo', 'sub_title' => 'unused'];
169+
$article = $Articles->newEntity($data);
170+
$article->author = $Authors->get(1);
171+
172+
$result = $Articles->slug($article);
173+
$expected = 'admad-foo';
174+
$this->assertEquals($expected, $result);
175+
}
176+
160177
public function testBeforeSaveMultiField()
161178
{
162179
$Articles = TableRegistry::get('Muffin/Slug.Articles', ['table' => 'slug_articles']);
@@ -266,7 +283,6 @@ public function testMaxLength()
266283
$this->assertEquals($expected, $result);
267284
}
268285

269-
270286
public function testCustomMaxLength()
271287
{
272288
$this->Tags->removeBehavior('Slug');

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
chdir($root);
2424
if (file_exists($root . '/config/bootstrap.php')) {
2525
require $root . '/config/bootstrap.php';
26+
2627
return;
2728
}
2829

0 commit comments

Comments
 (0)