Location: PHPKode > scripts > Craur > DracoBlue-Craur-305a42f/php/tests/complex_csv_file_test.php
<?php
$shelf = Craur::createFromCsvFile(dirname(__FILE__) . '/fixtures/books_with_categories.csv', array(
    'book[].name',
    'book[].year',
    'book[].author[].name',
    'book[].author[].age',
    'book[].category[].name',
));

assert(count($shelf->get('book[]')) === 2);

foreach ($shelf->get('book[]') as $book)
{
    if ($book->get('name') === 'My Book')
    {
        assert(count($book->get('author[]')) === 2);
        assert($book->get('author.name') == 'Hans');
        assert($book->get('author.age') == '32');
        foreach ($book->get('author[]') as $author)
        {
            assert(in_array($author->get('age'), array('32', '20')));
            assert(in_array($author->get('name'), array('Hans', 'Paul')));
        }
        assert(count($book->get('category[]')) === 1);
        assert($book->get('category.name') == 'Fantasy');
    }
    elseif ($book->get('name') === 'My second Book')
    {
        assert(count($book->get('author[]')) === 1);
        assert($book->get('author.name') == 'Erwin');
        assert($book->get('author.age') == '10');
        assert(count($book->get('category[]')) === 2);
        foreach ($book->get('category[]') as $category)
        {
            assert(in_array($category->get('name'), array('Fantasy', 'Comedy')));
        }
    }
}
Return current item: Craur