Write tests for listsNested on tree traits
This commit is contained in:
parent
a596a6babd
commit
4e1d2ca445
|
|
@ -8,6 +8,11 @@ class Category extends Model
|
|||
* @var string The database table used by the model.
|
||||
*/
|
||||
public $table = 'database_tester_categories';
|
||||
|
||||
public function getCustomNameAttribute()
|
||||
{
|
||||
return $this->name.' (#'.$this->id.')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,73 @@ class NestedTreeModelTest extends PluginTestCase
|
|||
$this->assertEquals(2, $items->count());
|
||||
}
|
||||
|
||||
public function testListsNested()
|
||||
{
|
||||
$array = CategoryNested::listsNested('name', 'id');
|
||||
$this->assertEquals([
|
||||
1 => 'Category Orange',
|
||||
2 => ' Autumn Leaves',
|
||||
3 => ' September',
|
||||
4 => ' October',
|
||||
5 => ' November',
|
||||
6 => ' Summer Breeze',
|
||||
7 => 'Category Green',
|
||||
8 => ' Winter Snow',
|
||||
9 => ' Spring Trees'
|
||||
], $array);
|
||||
|
||||
$array = CategoryNested::listsNested('name', 'id', '--');
|
||||
$this->assertEquals([
|
||||
1 => 'Category Orange',
|
||||
2 => '--Autumn Leaves',
|
||||
3 => '----September',
|
||||
4 => '----October',
|
||||
5 => '----November',
|
||||
6 => '--Summer Breeze',
|
||||
7 => 'Category Green',
|
||||
8 => '--Winter Snow',
|
||||
9 => '--Spring Trees'
|
||||
], $array);
|
||||
|
||||
$array = CategoryNested::listsNested('description', 'name', '**');
|
||||
$this->assertEquals([
|
||||
'Category Orange' => 'A root level test category',
|
||||
'Autumn Leaves' => '**Disccusion about the season of falling leaves.',
|
||||
'September' => '****The start of the fall season.',
|
||||
'October' => '****The middle of the fall season.',
|
||||
'November' => '****The end of the fall season.',
|
||||
'Summer Breeze' => '**Disccusion about the wind at the ocean.',
|
||||
'Category Green' => 'A root level test category',
|
||||
'Winter Snow' => '**Disccusion about the frosty snow flakes.',
|
||||
'Spring Trees' => '**Disccusion about the blooming gardens.'
|
||||
], $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage Column mismatch in listsNested method
|
||||
*/
|
||||
public function testListsNestedUnknownColumn()
|
||||
{
|
||||
CategoryNested::listsNested('custom_name', 'id');
|
||||
}
|
||||
|
||||
public function testListsNestedFromCollection()
|
||||
{
|
||||
$array = CategoryNested::get()->listsNested('custom_name', 'id', '...');
|
||||
$this->assertEquals([
|
||||
1 => 'Category Orange (#1)',
|
||||
2 => '...Autumn Leaves (#2)',
|
||||
3 => '......September (#3)',
|
||||
4 => '......October (#4)',
|
||||
5 => '......November (#5)',
|
||||
6 => '...Summer Breeze (#6)',
|
||||
7 => 'Category Green (#7)',
|
||||
8 => '...Winter Snow (#8)',
|
||||
9 => '...Spring Trees (#9)'
|
||||
], $array);
|
||||
}
|
||||
|
||||
public function seedSampleTree()
|
||||
{
|
||||
Model::unguard();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,115 @@ class SimpleTreeModelTest extends PluginTestCase
|
|||
$this->assertEquals(9, $item->getAllChildren()->count());
|
||||
}
|
||||
|
||||
public function testListsNested()
|
||||
{
|
||||
$array = CategorySimple::listsNested('name', 'id');
|
||||
$this->assertEquals([
|
||||
1 => 'Web development',
|
||||
2 => ' HTML5',
|
||||
3 => ' CSS3',
|
||||
4 => ' jQuery',
|
||||
5 => ' Bootstrap',
|
||||
6 => ' Laravel',
|
||||
7 => ' OctoberCMS',
|
||||
8 => ' September',
|
||||
9 => ' October',
|
||||
10 => ' November',
|
||||
11 => 'Mobile development',
|
||||
12 => ' iOS',
|
||||
13 => ' iPhone',
|
||||
14 => ' iPad',
|
||||
15 => ' Android',
|
||||
16 => 'Graphic design',
|
||||
17 => ' Photoshop',
|
||||
18 => ' Illustrator',
|
||||
19 => ' Fireworks'
|
||||
], $array);
|
||||
|
||||
$array = CategorySimple::listsNested('name', 'id', '--');
|
||||
$this->assertEquals([
|
||||
1 => 'Web development',
|
||||
2 => '--HTML5',
|
||||
3 => '--CSS3',
|
||||
4 => '--jQuery',
|
||||
5 => '--Bootstrap',
|
||||
6 => '--Laravel',
|
||||
7 => '--OctoberCMS',
|
||||
8 => '----September',
|
||||
9 => '----October',
|
||||
10 => '----November',
|
||||
11 => 'Mobile development',
|
||||
12 => '--iOS',
|
||||
13 => '--iPhone',
|
||||
14 => '--iPad',
|
||||
15 => '--Android',
|
||||
16 => 'Graphic design',
|
||||
17 => '--Photoshop',
|
||||
18 => '--Illustrator',
|
||||
19 => '--Fireworks'
|
||||
], $array);
|
||||
|
||||
$array = CategorySimple::listsNested('id', 'name', '**');
|
||||
$this->assertEquals([
|
||||
'Web development' => '1',
|
||||
'HTML5' => '**2',
|
||||
'CSS3' => '**3',
|
||||
'jQuery' => '**4',
|
||||
'Bootstrap' => '**5',
|
||||
'Laravel' => '**6',
|
||||
'OctoberCMS' => '**7',
|
||||
'September' => '****8',
|
||||
'October' => '****9',
|
||||
'November' => '****10',
|
||||
'Mobile development' => '11',
|
||||
'iOS' => '**12',
|
||||
'iPhone' => '**13',
|
||||
'iPad' => '**14',
|
||||
'Android' => '**15',
|
||||
'Graphic design' => '16',
|
||||
'Photoshop' => '**17',
|
||||
'Illustrator' => '**18',
|
||||
'Fireworks' => '**19'
|
||||
], $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage Column mismatch in listsNested method
|
||||
*/
|
||||
public function testListsNestedUnknownColumn()
|
||||
{
|
||||
CategorySimple::listsNested('custom_name', 'id');
|
||||
}
|
||||
|
||||
public function testListsNestedFromCollection()
|
||||
{
|
||||
$array = CategorySimple::get()->listsNested('custom_name', 'id', '...');
|
||||
|
||||
$this->assertEquals([
|
||||
1 => 'Web development (#1)',
|
||||
2 => '...HTML5 (#2)',
|
||||
3 => '...CSS3 (#3)',
|
||||
4 => '...jQuery (#4)',
|
||||
5 => '...Bootstrap (#5)',
|
||||
6 => '...Laravel (#6)',
|
||||
7 => '...OctoberCMS (#7)',
|
||||
8 => '......September (#8)',
|
||||
9 => '......October (#9)',
|
||||
10 => '......November (#10)',
|
||||
11 => 'Mobile development (#11)',
|
||||
12 => '...iOS (#12)',
|
||||
13 => '...iPhone (#13)',
|
||||
14 => '...iPad (#14)',
|
||||
15 => '...Android (#15)',
|
||||
16 => 'Graphic design (#16)',
|
||||
17 => '...Photoshop (#17)',
|
||||
18 => '...Illustrator (#18)',
|
||||
19 => '...Fireworks (#19)'
|
||||
], $array);
|
||||
}
|
||||
|
||||
|
||||
public function seedSampleTree()
|
||||
{
|
||||
Model::unguard();
|
||||
|
|
|
|||
Loading…
Reference in New Issue