PHP code example of robuust / craft-fixtures

1. Go to this page and download the library: Download robuust/craft-fixtures library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

robuust / craft-fixtures example snippets




// We need a copy because Asset will move the temp file
copy(__DIR__.'/assets/product.jpg', 'product.jpg');

return [
    [
        'tempFilePath' => 'product.jpg',
        'filename' => 'product.jpg',
        'volumeId' => $this->volumeIds['products'],
        'folderId' => $this->folderIds['clothes'],
    ],
];



return [
    [
        'groupId' => $this->groupIds['categories'],
        'title' => 'Category',
    ],
];



return [
    [
        'sectionId' => $this->sectionIds['home'],
        'typeId' => $this->typeIds['home']['home'],
        'title' => 'Home',
    ],
];



return [
    [
        'handle' => 'contact'
        'contactAddress' => 'foo',
        'contactCity' => 'bar',
    ],
];



return [
    [
        'groupId' => $this->groupIds['tags'],
        'title' => 'Tag',
    ],
];



return [
    [
        'username' => 'User',
        'email' => '[email protected]',
    ],
];



return [
    [
        'typeId' => $this->productTypeIds['clothes'],
        'title' => 'Product',
    ],
];



namespace fixtures;

use fixtures\base\EntryFixture;

/**
 * Contact page Fixture for Entry model.
 */
class ContactPageEntryFixture extends EntryFixture
{
    /**
     * {@inheritdoc}
     */
    public $dataFile = __DIR__.'/data/contact-page-entry.php';

    /**
     * {@inheritdoc}
     */
    public $depends = [
        'fixtures\SomeAssetFixture',
    ];
}



use craft\elements\Asset;

$articleThumbIds = Asset::find()->filename('article-thumb.jpg')->ids();

return [
    [
        'sectionId' => $this->sectionIds['contact'],
        'typeId' => $this->typeIds['contact']['contact'],
        'title' => 'Contact',
        'contactMapTitle' => 'Floorplan',
        'contactMapText' => '
            <p>
              Maecenas faucibus mollis interdum. Fusce dapibus, tellus ac cursus commodo, tortor
              mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio
              dui. Aenean lacinia bibendum nulla sed consectetur. Curabitur blandit tempus porttitor.
            </p>',
        'contactMapImage' => $articleThumbIds,
        'contactMapPDF' => Asset::find()->filename('test.pdf')->ids(),
    ],
];
yaml
modules:
    enabled:
        - \robuust\fixtures\test\Craft:
            part: [init, fixtures]
            configFile: 'config/app.test.php' # based on vendor/craftcms/cms/tests/_craft/config/test.php
            entryUrl: 'http://localhost/index.php'
            cleanup: true