PHP code example of proklung / wordpress-test-build
1. Go to this page and download the library: Download proklung/wordpress-test-build 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/ */
proklung / wordpress-test-build example snippets
protected function setupDatabaseData() : void
{
putenv('MYSQL_HOST=localhost');
putenv('MYSQL_DATABASE=wordpress_ci');
putenv('MYSQL_USER=root');
putenv('MYSQL_PASSWORD=');
}
protected function getDumpPath() : string
{
return $_SERVER['DOCUMENT_ROOT'] . '/Tests/dump/dump.sql';
}
protected function getMigrationsDir() : string
{
return __DIR__ . '/../migrations';
}
protected function makeMigration(string $name, string $template) : void
protected static function getWordpressBaseDir() : string
{
return __DIR__. '/../../files';
}
protected static $pluginSrcDir = __DIR__ . '/files';
// Скопирует ACF плагин из папки __DIR__ . '/files' в папку, где лежит Wordpress.
protected function setUp(): void
{
// Важно задать параметры перед вызовом родителя.
static::$pluginSrcDir = __DIR__ . '/files';
static::$plugins = [
'advanced-custom-fields' => 'advanced-custom-fields/acf.php'
];
parent::setUp();
}
$this->goTo('/?p=26799'); // Url - только так, без ЧПУ
$this->assertTrue(is_single());
use Prokl\WordpressCi\FixtureGenerator\Repository\AttachmentRepository;
use Prokl\WordpressCi\FixtureGenerator\Repository\PostRepository;
use Prokl\WordpressCi\FixtureGenerator\Repository\TermRepository;
use Prokl\WordpressCi\FixtureGenerator\Repository\UserRepository;
public function up()
{
$faker = Helper::getFaker();
AttachmentRepository::create(10); // 10 картинок
TermRepository::create(10, 'category'); // 10 категорий
TermRepository::create(5, 'post_tag'); // 10 тэгов
UserRepository::create(5); // 5 пользователей
// АСF поля. То, что отдает плагин ACF.
acf_add_local_field_group(array(
'key' => 'group_5e12e975546ec',
'title' => 'Видео',
'fields' => array(
array(
'key' => 'field_5e130144fa51a',
'label' => 'Видео элемент',
'name' => 'video_element',
'type' => 'relationship',
'instructions' => '',
' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => array(
0 => 'discussion',
),
'active' => true,
'description' => '',
));
// 10 постов с картинками и acf полями.
PostRepository::create(10, [
'acf' => [
'video_element' => $faker->postId()
]
]);
}