Permalink
Browse files

Add test for #10418

Show that find(list) does not drop keys with values = 0.

Refs #10418
  • Loading branch information...
markstory committed Mar 15, 2017
1 parent fc28ece commit 9dbeeaa1fa9e23042192eb1a033b526f4fd69003
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -6960,6 +6960,33 @@ public function testFindList() {
$this->assertEquals($expected, $result);
}
/**
* test find('list') method
*
* @return void
*/
public function testFindListZeroId() {
$this->loadFixtures('Article');
$model = new Article();
$model->displayField = 'title';
$model->save(array(
'title' => 'Zeroth Article',
'user_id' => 0,
'published' => 'Y'

This comment has been minimized.

Show comment
Hide comment
@bancer

bancer Mar 15, 2017

Contributor

@markstory That's not exactly the same scenario. 'user_id' is not a primary key. The article record should be:

array(
    'id' => '0',
    'title' => 'Zeroth Article',
    'user_id' => 1, // any user id, not important
    'published' => 'Y'
)
@bancer

bancer Mar 15, 2017

Contributor

@markstory That's not exactly the same scenario. 'user_id' is not a primary key. The article record should be:

array(
    'id' => '0',
    'title' => 'Zeroth Article',
    'user_id' => 1, // any user id, not important
    'published' => 'Y'
)

This comment has been minimized.

Show comment
Hide comment
@bancer

bancer Mar 15, 2017

Contributor

Not sure if that is possible to create it with save(). Perhaps it would be better to add it to $records in ArticleFixture.

@bancer

bancer Mar 15, 2017

Contributor

Not sure if that is possible to create it with save(). Perhaps it would be better to add it to $records in ArticleFixture.

This comment has been minimized.

Show comment
Hide comment
@markstory

markstory Mar 16, 2017

Member

Why does the field have to be a primary key?

@markstory

markstory Mar 16, 2017

Member

Why does the field have to be a primary key?

This comment has been minimized.

Show comment
Hide comment
@bancer

bancer Mar 16, 2017

Contributor

The problem is with primary key value, not a foreign key.

@bancer

bancer Mar 16, 2017

Contributor

The problem is with primary key value, not a foreign key.

This comment has been minimized.

Show comment
Hide comment
@markstory

markstory Mar 16, 2017

Member

Any chance you could send a pull request with a failing test?

@markstory

markstory Mar 16, 2017

Member

Any chance you could send a pull request with a failing test?

));
$result = $model->find('list', array(

This comment has been minimized.

Show comment
Hide comment
@bancer

bancer Mar 15, 2017

Contributor

You would need to have 'fields' => array('title', 'id') to reproduce the problem.

@bancer

bancer Mar 15, 2017

Contributor

You would need to have 'fields' => array('title', 'id') to reproduce the problem.

This comment has been minimized.

Show comment
Hide comment
@markstory

markstory Mar 16, 2017

Member

I'll try that.

@markstory

markstory Mar 16, 2017

Member

I'll try that.

'fields' => array('user_id', 'title')
));
$expected = array(
0 => 'Zeroth Article',
1 => 'Third Article',
3 => 'Second Article'
);
$this->assertEquals($expected, $result);
}
/**
* Test that find(list) works with array conditions that have only one element.
*

0 comments on commit 9dbeeaa

Please sign in to comment.