repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
lexxyungcarter/laravel-5-messenger | examples/MessagesController.php | MessagesController.read | public function read($id)
{
$thread = Thread::find($id);
if (!$thread) {
abort(404);
}
$thread->markAsRead(Auth::id());
} | php | public function read($id)
{
$thread = Thread::find($id);
if (!$thread) {
abort(404);
}
$thread->markAsRead(Auth::id());
} | [
"public",
"function",
"read",
"(",
"$",
"id",
")",
"{",
"$",
"thread",
"=",
"Thread",
"::",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"thread",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"$",
"thread",
"->",
"markAsRead",
"(",
"Auth",
"::",
"id",
"(",
")",
")",
";",
"}"
] | Mark a specific thread as read, for ajax use.
@param $id | [
"Mark",
"a",
"specific",
"thread",
"as",
"read",
"for",
"ajax",
"use",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/examples/MessagesController.php#L240-L248 |
lexxyungcarter/laravel-5-messenger | src/Models/Message.php | Message.scopeUnreadForUser | public function scopeUnreadForUser(Builder $query, $userId)
{
return $query->has('thread')
->where('user_id', '!=', $userId)
->whereHas('participants', function (Builder $query) use ($userId) {
$query->where('user_id', $userId)
->whereNull('deleted_at')
->where(function (Builder $q) {
$q->where('last_read', '<', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . $this->getTable() . '.created_at'))
->orWhereNull('last_read');
});
});
} | php | public function scopeUnreadForUser(Builder $query, $userId)
{
return $query->has('thread')
->where('user_id', '!=', $userId)
->whereHas('participants', function (Builder $query) use ($userId) {
$query->where('user_id', $userId)
->whereNull('deleted_at')
->where(function (Builder $q) {
$q->where('last_read', '<', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . $this->getTable() . '.created_at'))
->orWhereNull('last_read');
});
});
} | [
"public",
"function",
"scopeUnreadForUser",
"(",
"Builder",
"$",
"query",
",",
"$",
"userId",
")",
"{",
"return",
"$",
"query",
"->",
"has",
"(",
"'thread'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"'!='",
",",
"$",
"userId",
")",
"->",
"whereHas",
"(",
"'participants'",
",",
"function",
"(",
"Builder",
"$",
"query",
")",
"use",
"(",
"$",
"userId",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"userId",
")",
"->",
"whereNull",
"(",
"'deleted_at'",
")",
"->",
"where",
"(",
"function",
"(",
"Builder",
"$",
"q",
")",
"{",
"$",
"q",
"->",
"where",
"(",
"'last_read'",
",",
"'<'",
",",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"raw",
"(",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getTablePrefix",
"(",
")",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.created_at'",
")",
")",
"->",
"orWhereNull",
"(",
"'last_read'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Returns unread messages given the userId.
@param \Illuminate\Database\Eloquent\Builder $query
@param int $userId
@return \Illuminate\Database\Eloquent\Builder | [
"Returns",
"unread",
"messages",
"given",
"the",
"userId",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/Models/Message.php#L104-L116 |
lexxyungcarter/laravel-5-messenger | src/Traits/Messagable.php | Messagable.threadsWithNewMessages | public function threadsWithNewMessages()
{
return $this->threads()
->where(function (Builder $q) {
$q->whereIn(Models::table('threads') . '.id', $this->unreadMessages()->pluck('thread_id'));
})
->get();
} | php | public function threadsWithNewMessages()
{
return $this->threads()
->where(function (Builder $q) {
$q->whereIn(Models::table('threads') . '.id', $this->unreadMessages()->pluck('thread_id'));
})
->get();
} | [
"public",
"function",
"threadsWithNewMessages",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"threads",
"(",
")",
"->",
"where",
"(",
"function",
"(",
"Builder",
"$",
"q",
")",
"{",
"$",
"q",
"->",
"whereIn",
"(",
"Models",
"::",
"table",
"(",
"'threads'",
")",
".",
"'.id'",
",",
"$",
"this",
"->",
"unreadMessages",
"(",
")",
"->",
"pluck",
"(",
"'thread_id'",
")",
")",
";",
"}",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Returns all threads with new messages.
@return \Illuminate\Database\Eloquent\Collection | [
"Returns",
"all",
"threads",
"with",
"new",
"messages",
"."
] | train | https://github.com/lexxyungcarter/laravel-5-messenger/blob/d98d00b1e9e70b82748beb06f0470b6609ebc9ca/src/Traits/Messagable.php#L89-L96 |
paulgibbs/behat-wordpress-extension | src/Compiler/DriverElementPass.php | DriverElementPass.process | public function process(ContainerBuilder $container)
{
$wordpress = $container->getDefinition('wordpress.wordpress');
if (! $wordpress) {
return;
}
foreach ($container->findTaggedServiceIds('wordpress.element') as $id => $attributes) {
foreach ($attributes as $attribute) {
if (! isset($attribute['alias'], $attribute['driver'])) {
continue;
}
$wordpress->addMethodCall(
'registerDriverElement',
[$attribute['alias'], new Reference($id), $attribute['driver']]
);
}
}
} | php | public function process(ContainerBuilder $container)
{
$wordpress = $container->getDefinition('wordpress.wordpress');
if (! $wordpress) {
return;
}
foreach ($container->findTaggedServiceIds('wordpress.element') as $id => $attributes) {
foreach ($attributes as $attribute) {
if (! isset($attribute['alias'], $attribute['driver'])) {
continue;
}
$wordpress->addMethodCall(
'registerDriverElement',
[$attribute['alias'], new Reference($id), $attribute['driver']]
);
}
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"wordpress",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'wordpress.wordpress'",
")",
";",
"if",
"(",
"!",
"$",
"wordpress",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'wordpress.element'",
")",
"as",
"$",
"id",
"=>",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"attribute",
"[",
"'alias'",
"]",
",",
"$",
"attribute",
"[",
"'driver'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"wordpress",
"->",
"addMethodCall",
"(",
"'registerDriverElement'",
",",
"[",
"$",
"attribute",
"[",
"'alias'",
"]",
",",
"new",
"Reference",
"(",
"$",
"id",
")",
",",
"$",
"attribute",
"[",
"'driver'",
"]",
"]",
")",
";",
"}",
"}",
"}"
] | Modify the container before Symfony compiles it.
@param ContainerBuilder $container | [
"Modify",
"the",
"container",
"before",
"Symfony",
"compiles",
"it",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Compiler/DriverElementPass.php#L19-L38 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/ContentElement.php | ContentElement.create | public function create($args)
{
$meta_args = [];
$tax_args = [];
/*
* Array of taxonomy terms keyed by their taxonomy name, which WP-CLI can't handle.
*
* Values may be delimited by a comma.
*
* See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179
*/
if (isset($args['tax_input'])) {
$tax_args = $args['tax_input'];
unset($args['tax_input']);
}
/*
* Array of post meta values keyed by their post meta key, which WP-CLI can't handle.
*
* See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179
*/
if (isset($args['meta_input'])) {
$meta_args = $args['meta_input'];
unset($args['meta_input']);
}
$wpcli_args = buildCLIArgs(
array(
'ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title',
'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name',
'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type',
'guid', 'post_category', 'page_template',
),
$args
);
array_unshift($wpcli_args, '--porcelain');
$post_id = (int) $this->drivers->getDriver()->wpcli('post', 'create', $wpcli_args)['stdout'];
// Apply taxonomy values.
if ($tax_args) {
foreach ($tax_args as $taxonomy => $terms) {
$split_terms = str_getcsv($terms);
foreach ($split_terms as $split_term) {
$args = [
$post_id,
$taxonomy,
escapeshellarg($split_term),
];
$this->drivers->getDriver()->wpcli('post', 'term add', $args);
}
}
}
// Apply post meta values.
if ($meta_args) {
foreach ($meta_args as $meta_key => $meta_value) {
$args = [
$post_id,
$meta_key,
escapeshellarg($meta_value),
];
$this->drivers->getDriver()->wpcli('post', 'meta update', $args)['stdout'];
}
}
return $this->get($post_id);
} | php | public function create($args)
{
$meta_args = [];
$tax_args = [];
/*
* Array of taxonomy terms keyed by their taxonomy name, which WP-CLI can't handle.
*
* Values may be delimited by a comma.
*
* See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179
*/
if (isset($args['tax_input'])) {
$tax_args = $args['tax_input'];
unset($args['tax_input']);
}
/*
* Array of post meta values keyed by their post meta key, which WP-CLI can't handle.
*
* See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179
*/
if (isset($args['meta_input'])) {
$meta_args = $args['meta_input'];
unset($args['meta_input']);
}
$wpcli_args = buildCLIArgs(
array(
'ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title',
'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name',
'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type',
'guid', 'post_category', 'page_template',
),
$args
);
array_unshift($wpcli_args, '--porcelain');
$post_id = (int) $this->drivers->getDriver()->wpcli('post', 'create', $wpcli_args)['stdout'];
// Apply taxonomy values.
if ($tax_args) {
foreach ($tax_args as $taxonomy => $terms) {
$split_terms = str_getcsv($terms);
foreach ($split_terms as $split_term) {
$args = [
$post_id,
$taxonomy,
escapeshellarg($split_term),
];
$this->drivers->getDriver()->wpcli('post', 'term add', $args);
}
}
}
// Apply post meta values.
if ($meta_args) {
foreach ($meta_args as $meta_key => $meta_value) {
$args = [
$post_id,
$meta_key,
escapeshellarg($meta_value),
];
$this->drivers->getDriver()->wpcli('post', 'meta update', $args)['stdout'];
}
}
return $this->get($post_id);
} | [
"public",
"function",
"create",
"(",
"$",
"args",
")",
"{",
"$",
"meta_args",
"=",
"[",
"]",
";",
"$",
"tax_args",
"=",
"[",
"]",
";",
"/*\n * Array of taxonomy terms keyed by their taxonomy name, which WP-CLI can't handle.\n *\n * Values may be delimited by a comma.\n *\n * See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179\n */",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'tax_input'",
"]",
")",
")",
"{",
"$",
"tax_args",
"=",
"$",
"args",
"[",
"'tax_input'",
"]",
";",
"unset",
"(",
"$",
"args",
"[",
"'tax_input'",
"]",
")",
";",
"}",
"/*\n * Array of post meta values keyed by their post meta key, which WP-CLI can't handle.\n *\n * See https://github.com/wp-cli/entity-command/issues/44#issuecomment-325957179\n */",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'meta_input'",
"]",
")",
")",
"{",
"$",
"meta_args",
"=",
"$",
"args",
"[",
"'meta_input'",
"]",
";",
"unset",
"(",
"$",
"args",
"[",
"'meta_input'",
"]",
")",
";",
"}",
"$",
"wpcli_args",
"=",
"buildCLIArgs",
"(",
"array",
"(",
"'ID'",
",",
"'post_author'",
",",
"'post_date'",
",",
"'post_date_gmt'",
",",
"'post_content'",
",",
"'post_content_filtered'",
",",
"'post_title'",
",",
"'post_excerpt'",
",",
"'post_status'",
",",
"'post_type'",
",",
"'comment_status'",
",",
"'ping_status'",
",",
"'post_password'",
",",
"'post_name'",
",",
"'to_ping'",
",",
"'pinged'",
",",
"'post_modified'",
",",
"'post_modified_gmt'",
",",
"'post_parent'",
",",
"'menu_order'",
",",
"'post_mime_type'",
",",
"'guid'",
",",
"'post_category'",
",",
"'page_template'",
",",
")",
",",
"$",
"args",
")",
";",
"array_unshift",
"(",
"$",
"wpcli_args",
",",
"'--porcelain'",
")",
";",
"$",
"post_id",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'create'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
";",
"// Apply taxonomy values.",
"if",
"(",
"$",
"tax_args",
")",
"{",
"foreach",
"(",
"$",
"tax_args",
"as",
"$",
"taxonomy",
"=>",
"$",
"terms",
")",
"{",
"$",
"split_terms",
"=",
"str_getcsv",
"(",
"$",
"terms",
")",
";",
"foreach",
"(",
"$",
"split_terms",
"as",
"$",
"split_term",
")",
"{",
"$",
"args",
"=",
"[",
"$",
"post_id",
",",
"$",
"taxonomy",
",",
"escapeshellarg",
"(",
"$",
"split_term",
")",
",",
"]",
";",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'term add'",
",",
"$",
"args",
")",
";",
"}",
"}",
"}",
"// Apply post meta values.",
"if",
"(",
"$",
"meta_args",
")",
"{",
"foreach",
"(",
"$",
"meta_args",
"as",
"$",
"meta_key",
"=>",
"$",
"meta_value",
")",
"{",
"$",
"args",
"=",
"[",
"$",
"post_id",
",",
"$",
"meta_key",
",",
"escapeshellarg",
"(",
"$",
"meta_value",
")",
",",
"]",
";",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'meta update'",
",",
"$",
"args",
")",
"[",
"'stdout'",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"post_id",
")",
";",
"}"
] | Create an item for this element.
@param array $args Data used to create an object.
@return mixed The new item. | [
"Create",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/ContentElement.php#L21-L92 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/ContentElement.php | ContentElement.get | public function get($id, $args = [])
{
$url = '';
// Support fetching via arbitrary field.
if (! is_numeric($id)) {
$wpcli_args = ['--fields=ID,url', "--{$args['by']}=" . escapeshellarg($id), '--post_type=any', '--format=json', '--ignore_sticky_posts=true'];
$result = json_decode($this->drivers->getDriver()->wpcli('post', 'list', $wpcli_args)['stdout']);
if (empty($result)) {
throw new UnexpectedValueException(sprintf('[W501] Could not find post with ID %d', $id));
}
$id = (int) $result[0]->ID;
$url = $result[0]->url;
}
// Fetch by ID.
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $id, '--format=json');
$post = $this->drivers->getDriver()->wpcli('post', 'get', $wpcli_args)['stdout'];
$post = json_decode($post);
if (! $post) {
throw new UnexpectedValueException(sprintf('[W501] Could not find post with ID %d', $id));
}
if (! $url) {
$wpcli_args = ['--post__in=' . $post->ID, '--fields=url', '--post_type=any', '--format=json'];
$result = json_decode($this->drivers->getDriver()->wpcli('post', 'list', $wpcli_args)['stdout']);
$url = $result[0]->url;
}
$post->url = $url;
return $post;
} | php | public function get($id, $args = [])
{
$url = '';
// Support fetching via arbitrary field.
if (! is_numeric($id)) {
$wpcli_args = ['--fields=ID,url', "--{$args['by']}=" . escapeshellarg($id), '--post_type=any', '--format=json', '--ignore_sticky_posts=true'];
$result = json_decode($this->drivers->getDriver()->wpcli('post', 'list', $wpcli_args)['stdout']);
if (empty($result)) {
throw new UnexpectedValueException(sprintf('[W501] Could not find post with ID %d', $id));
}
$id = (int) $result[0]->ID;
$url = $result[0]->url;
}
// Fetch by ID.
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $id, '--format=json');
$post = $this->drivers->getDriver()->wpcli('post', 'get', $wpcli_args)['stdout'];
$post = json_decode($post);
if (! $post) {
throw new UnexpectedValueException(sprintf('[W501] Could not find post with ID %d', $id));
}
if (! $url) {
$wpcli_args = ['--post__in=' . $post->ID, '--fields=url', '--post_type=any', '--format=json'];
$result = json_decode($this->drivers->getDriver()->wpcli('post', 'list', $wpcli_args)['stdout']);
$url = $result[0]->url;
}
$post->url = $url;
return $post;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"''",
";",
"// Support fetching via arbitrary field.",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"wpcli_args",
"=",
"[",
"'--fields=ID,url'",
",",
"\"--{$args['by']}=\"",
".",
"escapeshellarg",
"(",
"$",
"id",
")",
",",
"'--post_type=any'",
",",
"'--format=json'",
",",
"'--ignore_sticky_posts=true'",
"]",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'list'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W501] Could not find post with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"result",
"[",
"0",
"]",
"->",
"ID",
";",
"$",
"url",
"=",
"$",
"result",
"[",
"0",
"]",
"->",
"url",
";",
"}",
"// Fetch by ID.",
"$",
"wpcli_args",
"=",
"buildCLIArgs",
"(",
"array",
"(",
"'field'",
",",
"'fields'",
",",
")",
",",
"$",
"args",
")",
";",
"array_unshift",
"(",
"$",
"wpcli_args",
",",
"$",
"id",
",",
"'--format=json'",
")",
";",
"$",
"post",
"=",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'get'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
";",
"$",
"post",
"=",
"json_decode",
"(",
"$",
"post",
")",
";",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W501] Could not find post with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"wpcli_args",
"=",
"[",
"'--post__in='",
".",
"$",
"post",
"->",
"ID",
",",
"'--fields=url'",
",",
"'--post_type=any'",
",",
"'--format=json'",
"]",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'post'",
",",
"'list'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
")",
";",
"$",
"url",
"=",
"$",
"result",
"[",
"0",
"]",
"->",
"url",
";",
"}",
"$",
"post",
"->",
"url",
"=",
"$",
"url",
";",
"return",
"$",
"post",
";",
"}"
] | Retrieve an item for this element.
@param int|string $id Object ID.
@param array $args Optional data used to fetch an object.
@throws \UnexpectedValueException
@return mixed The item. | [
"Retrieve",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/ContentElement.php#L104-L147 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iGoToEditScreenForPostType | public function iGoToEditScreenForPostType(string $post_type, string $title)
{
$post = $this->getContentFromTitle($title, $post_type);
$this->edit_post_page->open(array(
'id' => $post['id'],
));
} | php | public function iGoToEditScreenForPostType(string $post_type, string $title)
{
$post = $this->getContentFromTitle($title, $post_type);
$this->edit_post_page->open(array(
'id' => $post['id'],
));
} | [
"public",
"function",
"iGoToEditScreenForPostType",
"(",
"string",
"$",
"post_type",
",",
"string",
"$",
"title",
")",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getContentFromTitle",
"(",
"$",
"title",
",",
"$",
"post_type",
")",
";",
"$",
"this",
"->",
"edit_post_page",
"->",
"open",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"post",
"[",
"'id'",
"]",
",",
")",
")",
";",
"}"
] | Go to the edit post admin page for the referenced post.
This step allows you to specify the post type to consider.
Example: Given I am on the edit post screen for "Hello World"
Example: Given I am on the edit event screen for "Some Event"
@Given /^I am on the edit ([a-zA-z_-]+) screen for "([^"]*)"$/
@param string $post_type The post type of the referenced 'post' being edited.
@param string $title The name of the 'post' being edited. | [
"Go",
"to",
"the",
"edit",
"post",
"admin",
"page",
"for",
"the",
"referenced",
"post",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L50-L56 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iGoToEditScreenFor | public function iGoToEditScreenFor(string $title)
{
$post = $this->getContentFromTitle($title);
$this->edit_post_page->open(array(
'id' => $post['id'],
));
} | php | public function iGoToEditScreenFor(string $title)
{
$post = $this->getContentFromTitle($title);
$this->edit_post_page->open(array(
'id' => $post['id'],
));
} | [
"public",
"function",
"iGoToEditScreenFor",
"(",
"string",
"$",
"title",
")",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getContentFromTitle",
"(",
"$",
"title",
")",
";",
"$",
"this",
"->",
"edit_post_page",
"->",
"open",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"post",
"[",
"'id'",
"]",
",",
")",
")",
";",
"}"
] | Go to the edit post admin page for the referenced post.
This step works for all post types.
Example: Given I am on the edit screen for "Hello World"
Example: Given I am on the edit screen for "Some Event"
@Given /^I am on the edit screen for "(?P<title>[^"]*)"$/
@param string $title The name of the 'post' being edited. | [
"Go",
"to",
"the",
"edit",
"post",
"admin",
"page",
"for",
"the",
"referenced",
"post",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L70-L76 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iSelectPostContentEditorMode | public function iSelectPostContentEditorMode(string $mode)
{
$content_editor = $this->edit_post_page->getContentEditor();
$content_editor->setMode(strtoupper($mode));
} | php | public function iSelectPostContentEditorMode(string $mode)
{
$content_editor = $this->edit_post_page->getContentEditor();
$content_editor->setMode(strtoupper($mode));
} | [
"public",
"function",
"iSelectPostContentEditorMode",
"(",
"string",
"$",
"mode",
")",
"{",
"$",
"content_editor",
"=",
"$",
"this",
"->",
"edit_post_page",
"->",
"getContentEditor",
"(",
")",
";",
"$",
"content_editor",
"->",
"setMode",
"(",
"strtoupper",
"(",
"$",
"mode",
")",
")",
";",
"}"
] | Switch the mode of the post content editor.
Example: When I switch to the post content editor's Visual mode
Example: When I switch to the post content editor's Text mode
@When /^I switch to the post content editor's (visual|text) mode$/i
@param string $mode The mode (visual or text) to switch to in the editor. | [
"Switch",
"the",
"mode",
"of",
"the",
"post",
"content",
"editor",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L102-L106 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iEnterContentIntoPostContentEditor | public function iEnterContentIntoPostContentEditor(PyStringNode $content)
{
$content_editor = $this->edit_post_page->getContentEditor();
$content_editor->setContent($content->getRaw());
} | php | public function iEnterContentIntoPostContentEditor(PyStringNode $content)
{
$content_editor = $this->edit_post_page->getContentEditor();
$content_editor->setContent($content->getRaw());
} | [
"public",
"function",
"iEnterContentIntoPostContentEditor",
"(",
"PyStringNode",
"$",
"content",
")",
"{",
"$",
"content_editor",
"=",
"$",
"this",
"->",
"edit_post_page",
"->",
"getContentEditor",
"(",
")",
";",
"$",
"content_editor",
"->",
"setContent",
"(",
"$",
"content",
"->",
"getRaw",
"(",
")",
")",
";",
"}"
] | Enter the content into the content editor.
Example: When I enter the following content into the post content editor:
"""
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
"""
@When I enter the following content into the post content editor:
@param PyStringNode $content The content to enter into the editor. | [
"Enter",
"the",
"content",
"into",
"the",
"content",
"editor",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L120-L124 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.postContentEditorIsInMode | public function postContentEditorIsInMode(string $mode)
{
$content_editor = $this->edit_post_page->getContentEditor();
if (strtoupper($mode) !== $content_editor->getMode()) {
throw new ExpectationException(
sprintf('[W808] Content editor is in "%1$s" mode. Expected "%2$s".', $content_editor->getMode(), $mode),
$this->getSession()->getDriver()
);
}
} | php | public function postContentEditorIsInMode(string $mode)
{
$content_editor = $this->edit_post_page->getContentEditor();
if (strtoupper($mode) !== $content_editor->getMode()) {
throw new ExpectationException(
sprintf('[W808] Content editor is in "%1$s" mode. Expected "%2$s".', $content_editor->getMode(), $mode),
$this->getSession()->getDriver()
);
}
} | [
"public",
"function",
"postContentEditorIsInMode",
"(",
"string",
"$",
"mode",
")",
"{",
"$",
"content_editor",
"=",
"$",
"this",
"->",
"edit_post_page",
"->",
"getContentEditor",
"(",
")",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"mode",
")",
"!==",
"$",
"content_editor",
"->",
"getMode",
"(",
")",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'[W808] Content editor is in \"%1$s\" mode. Expected \"%2$s\".'",
",",
"$",
"content_editor",
"->",
"getMode",
"(",
")",
",",
"$",
"mode",
")",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"}"
] | Assert the mode that the content editor is in.
Example: Then The post content editor is in Visual mode
Example: Then The post content editor is in Text mode
@Then /^the post content editor is in (visual|text) mode$/i
@param string $mode Assert that the editor is the specified mode (visual or text).
@throws ExpectationException | [
"Assert",
"the",
"mode",
"that",
"the",
"content",
"editor",
"is",
"in",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L138-L147 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iAmOnEditScreenForPostType | public function iAmOnEditScreenForPostType(string $post_type, string $post_title)
{
$post = $this->getContentFromTitle($post_title, $post_type);
$this->edit_post_page->isOpen(array(
'id' => $post['id'],
));
} | php | public function iAmOnEditScreenForPostType(string $post_type, string $post_title)
{
$post = $this->getContentFromTitle($post_title, $post_type);
$this->edit_post_page->isOpen(array(
'id' => $post['id'],
));
} | [
"public",
"function",
"iAmOnEditScreenForPostType",
"(",
"string",
"$",
"post_type",
",",
"string",
"$",
"post_title",
")",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getContentFromTitle",
"(",
"$",
"post_title",
",",
"$",
"post_type",
")",
";",
"$",
"this",
"->",
"edit_post_page",
"->",
"isOpen",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"post",
"[",
"'id'",
"]",
",",
")",
")",
";",
"}"
] | Assert that the edit screen for the given post and post type is displayed
Example: Then I should be on the edit event screen for "Some Event"
Example: Then I should be on the edit post screen for "Hello World"
@Then I should be on the edit :post_type screen for :post_title
@param string $post_type The post type of the referenced content being edited.
@param string $post_title The name of the content being edited. | [
"Assert",
"that",
"the",
"edit",
"screen",
"for",
"the",
"given",
"post",
"and",
"post",
"type",
"is",
"displayed"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L174-L180 |
paulgibbs/behat-wordpress-extension | src/Context/EditPostContext.php | EditPostContext.iShouldNotSeeTheMetabox | public function iShouldNotSeeTheMetabox(string $title)
{
try {
$this->edit_post_page->getMetaBox($title);
} catch (ExpectationException $e) {
// Expectation fulfilled
return;
}
throw new ExpectationException(
sprintf(
'[W809] Metabox "%s" was found on the page, but it should not be there.',
$title
),
$this->getSession()->getDriver()
);
} | php | public function iShouldNotSeeTheMetabox(string $title)
{
try {
$this->edit_post_page->getMetaBox($title);
} catch (ExpectationException $e) {
// Expectation fulfilled
return;
}
throw new ExpectationException(
sprintf(
'[W809] Metabox "%s" was found on the page, but it should not be there.',
$title
),
$this->getSession()->getDriver()
);
} | [
"public",
"function",
"iShouldNotSeeTheMetabox",
"(",
"string",
"$",
"title",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"edit_post_page",
"->",
"getMetaBox",
"(",
"$",
"title",
")",
";",
"}",
"catch",
"(",
"ExpectationException",
"$",
"e",
")",
"{",
"// Expectation fulfilled",
"return",
";",
"}",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'[W809] Metabox \"%s\" was found on the page, but it should not be there.'",
",",
"$",
"title",
")",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
")",
";",
"}"
] | Assert that the referenced metabox is not visible.
The metabox may still be collapsed.
Example: Then I should not see the "Featured Image" metabox
@Then I should not see the :title metabox
@param string $title The title of the metabox being checked
@throws ExpectationException | [
"Assert",
"that",
"the",
"referenced",
"metabox",
"is",
"not",
"visible",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/EditPostContext.php#L211-L227 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/PluginElement.php | PluginElement.update | public function update($id, $args = [])
{
if ($args['status'] === 'activate') {
activate_plugin($id, '', false, true);
} elseif ($args['status'] === 'deactivate') {
deactivate_plugins($id, true, false);
}
} | php | public function update($id, $args = [])
{
if ($args['status'] === 'activate') {
activate_plugin($id, '', false, true);
} elseif ($args['status'] === 'deactivate') {
deactivate_plugins($id, true, false);
}
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"args",
"[",
"'status'",
"]",
"===",
"'activate'",
")",
"{",
"activate_plugin",
"(",
"$",
"id",
",",
"''",
",",
"false",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"$",
"args",
"[",
"'status'",
"]",
"===",
"'deactivate'",
")",
"{",
"deactivate_plugins",
"(",
"$",
"id",
",",
"true",
",",
"false",
")",
";",
"}",
"}"
] | Activate or deactivate specified plugin.
@param string $id Path to plugin.
@param array $args Optional data used to update an object. | [
"Activate",
"or",
"deactivate",
"specified",
"plugin",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/PluginElement.php#L19-L26 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/PluginElement.php | PluginElement.activate | public function activate($id, $args = [])
{
$plugin = $this->drivers->getDriver()->getPlugin($id);
if (! $plugin) {
throw new UnexpectedValueException("[W608] Cannot find the plugin: {$id}.");
}
$this->update($plugin, ['status' => 'activate']);
} | php | public function activate($id, $args = [])
{
$plugin = $this->drivers->getDriver()->getPlugin($id);
if (! $plugin) {
throw new UnexpectedValueException("[W608] Cannot find the plugin: {$id}.");
}
$this->update($plugin, ['status' => 'activate']);
} | [
"public",
"function",
"activate",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"getPlugin",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"plugin",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"\"[W608] Cannot find the plugin: {$id}.\"",
")",
";",
"}",
"$",
"this",
"->",
"update",
"(",
"$",
"plugin",
",",
"[",
"'status'",
"=>",
"'activate'",
"]",
")",
";",
"}"
] | Alias of update().
@see update()
@param string $id Plugin name to activate.
@param array $args Optional. Not used.
@throws \UnexpectedValueException | [
"Alias",
"of",
"update",
"()",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/PluginElement.php#L43-L52 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/UserElement.php | UserElement.create | public function create($args)
{
$extra_roles = [];
// Store multiple roles; WP can only assign one on user creation.
if (! empty($args['role'])) {
if (! is_array($args['role'])) {
$args['role'] = array_map('trim', explode(',', $args['role']));
}
$extra_roles = $args['role'];
$args['role'] = array_shift($extra_roles);
}
$wpcli_args = buildCLIArgs(
array(
'ID', 'user_pass', 'user_nicename', 'user_url', 'display_name', 'nickname', 'first_name', 'last_name',
'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'user_registered',
'show_admin_bar_front', 'role', 'locale',
),
$args
);
array_unshift($wpcli_args, escapeshellcmd($args['user_login']), $args['user_email'], '--porcelain');
$user_id = (int) $this->drivers->getDriver()->wpcli('user', 'create', $wpcli_args)['stdout'];
// Assign any extra roles.
foreach ($extra_roles as $role) {
$this->drivers->getDriver()->wpcli(
'user',
'add-role',
[
$user_id,
escapeshellcmd($role)
]
);
}
return $this->get($user_id);
} | php | public function create($args)
{
$extra_roles = [];
// Store multiple roles; WP can only assign one on user creation.
if (! empty($args['role'])) {
if (! is_array($args['role'])) {
$args['role'] = array_map('trim', explode(',', $args['role']));
}
$extra_roles = $args['role'];
$args['role'] = array_shift($extra_roles);
}
$wpcli_args = buildCLIArgs(
array(
'ID', 'user_pass', 'user_nicename', 'user_url', 'display_name', 'nickname', 'first_name', 'last_name',
'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'user_registered',
'show_admin_bar_front', 'role', 'locale',
),
$args
);
array_unshift($wpcli_args, escapeshellcmd($args['user_login']), $args['user_email'], '--porcelain');
$user_id = (int) $this->drivers->getDriver()->wpcli('user', 'create', $wpcli_args)['stdout'];
// Assign any extra roles.
foreach ($extra_roles as $role) {
$this->drivers->getDriver()->wpcli(
'user',
'add-role',
[
$user_id,
escapeshellcmd($role)
]
);
}
return $this->get($user_id);
} | [
"public",
"function",
"create",
"(",
"$",
"args",
")",
"{",
"$",
"extra_roles",
"=",
"[",
"]",
";",
"// Store multiple roles; WP can only assign one on user creation.",
"if",
"(",
"!",
"empty",
"(",
"$",
"args",
"[",
"'role'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
"[",
"'role'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'role'",
"]",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"args",
"[",
"'role'",
"]",
")",
")",
";",
"}",
"$",
"extra_roles",
"=",
"$",
"args",
"[",
"'role'",
"]",
";",
"$",
"args",
"[",
"'role'",
"]",
"=",
"array_shift",
"(",
"$",
"extra_roles",
")",
";",
"}",
"$",
"wpcli_args",
"=",
"buildCLIArgs",
"(",
"array",
"(",
"'ID'",
",",
"'user_pass'",
",",
"'user_nicename'",
",",
"'user_url'",
",",
"'display_name'",
",",
"'nickname'",
",",
"'first_name'",
",",
"'last_name'",
",",
"'description'",
",",
"'rich_editing'",
",",
"'comment_shortcuts'",
",",
"'admin_color'",
",",
"'use_ssl'",
",",
"'user_registered'",
",",
"'show_admin_bar_front'",
",",
"'role'",
",",
"'locale'",
",",
")",
",",
"$",
"args",
")",
";",
"array_unshift",
"(",
"$",
"wpcli_args",
",",
"escapeshellcmd",
"(",
"$",
"args",
"[",
"'user_login'",
"]",
")",
",",
"$",
"args",
"[",
"'user_email'",
"]",
",",
"'--porcelain'",
")",
";",
"$",
"user_id",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'user'",
",",
"'create'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
";",
"// Assign any extra roles.",
"foreach",
"(",
"$",
"extra_roles",
"as",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'user'",
",",
"'add-role'",
",",
"[",
"$",
"user_id",
",",
"escapeshellcmd",
"(",
"$",
"role",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"user_id",
")",
";",
"}"
] | Create an item for this element.
@param array $args Data used to create an object.
@return mixed The new item. | [
"Create",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/UserElement.php#L21-L60 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/UserElement.php | UserElement.get | public function get($id, $args = [])
{
// Fetch all the user properties by default, for convenience.
if (! isset($args['field']) && ! isset($args['fields'])) {
$args['fields'] = implode(
',',
array(
'ID',
'user_login',
'display_name',
'user_email',
'user_registered',
'roles',
'user_pass',
'user_nicename',
'user_url',
'user_activation_key',
'user_status',
'url'
)
);
}
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $id, '--format=json');
$user = $this->drivers->getDriver()->wpcli('user', 'get', $wpcli_args)['stdout'];
$user = json_decode($user);
if (! $user) {
throw new UnexpectedValueException(sprintf('[W504] Could not find user with ID %d', $id));
}
// Convert CSVs to arrays for consistency with WP-PHP driver.
if (isset($user->roles) && ! is_array($user->roles)) {
$user->roles = array_map('trim', explode(',', $user->roles));
}
return $user;
} | php | public function get($id, $args = [])
{
// Fetch all the user properties by default, for convenience.
if (! isset($args['field']) && ! isset($args['fields'])) {
$args['fields'] = implode(
',',
array(
'ID',
'user_login',
'display_name',
'user_email',
'user_registered',
'roles',
'user_pass',
'user_nicename',
'user_url',
'user_activation_key',
'user_status',
'url'
)
);
}
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $id, '--format=json');
$user = $this->drivers->getDriver()->wpcli('user', 'get', $wpcli_args)['stdout'];
$user = json_decode($user);
if (! $user) {
throw new UnexpectedValueException(sprintf('[W504] Could not find user with ID %d', $id));
}
// Convert CSVs to arrays for consistency with WP-PHP driver.
if (isset($user->roles) && ! is_array($user->roles)) {
$user->roles = array_map('trim', explode(',', $user->roles));
}
return $user;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"// Fetch all the user properties by default, for convenience.",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'field'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"args",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'fields'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"'ID'",
",",
"'user_login'",
",",
"'display_name'",
",",
"'user_email'",
",",
"'user_registered'",
",",
"'roles'",
",",
"'user_pass'",
",",
"'user_nicename'",
",",
"'user_url'",
",",
"'user_activation_key'",
",",
"'user_status'",
",",
"'url'",
")",
")",
";",
"}",
"$",
"wpcli_args",
"=",
"buildCLIArgs",
"(",
"array",
"(",
"'field'",
",",
"'fields'",
",",
")",
",",
"$",
"args",
")",
";",
"array_unshift",
"(",
"$",
"wpcli_args",
",",
"$",
"id",
",",
"'--format=json'",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'user'",
",",
"'get'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
";",
"$",
"user",
"=",
"json_decode",
"(",
"$",
"user",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W504] Could not find user with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"// Convert CSVs to arrays for consistency with WP-PHP driver.",
"if",
"(",
"isset",
"(",
"$",
"user",
"->",
"roles",
")",
"&&",
"!",
"is_array",
"(",
"$",
"user",
"->",
"roles",
")",
")",
"{",
"$",
"user",
"->",
"roles",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"user",
"->",
"roles",
")",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Retrieve an item for this element.
@param int|string $id Object ID.
@param array $args Optional data used to fetch an object.
@throws \UnexpectedValueException
@return mixed The item. | [
"Retrieve",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/UserElement.php#L72-L117 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/PageObjectAwareContextTrait.php | PageObjectAwareContextTrait.getPage | public function getPage(string $name): Page
{
if ($this->page_object_factory === null) {
throw new RuntimeException('[W406] To create pages you need to pass a factory with setPageObjectFactory()');
}
return $this->page_object_factory->createPage($name);
} | php | public function getPage(string $name): Page
{
if ($this->page_object_factory === null) {
throw new RuntimeException('[W406] To create pages you need to pass a factory with setPageObjectFactory()');
}
return $this->page_object_factory->createPage($name);
} | [
"public",
"function",
"getPage",
"(",
"string",
"$",
"name",
")",
":",
"Page",
"{",
"if",
"(",
"$",
"this",
"->",
"page_object_factory",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'[W406] To create pages you need to pass a factory with setPageObjectFactory()'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"page_object_factory",
"->",
"createPage",
"(",
"$",
"name",
")",
";",
"}"
] | Creates a page object from its name.
@param string $name The name of the page object e.g 'Admin page'.
@throws \RuntimeException
@return Page | [
"Creates",
"a",
"page",
"object",
"from",
"its",
"name",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/PageObjectAwareContextTrait.php#L26-L33 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/PageObjectAwareContextTrait.php | PageObjectAwareContextTrait.getElement | public function getElement(string $name): Element
{
if ($this->page_object_factory === null) {
throw new RuntimeException('[W406] To create elements you need to pass a factory with setPageObjectFactory()');
}
return $this->page_object_factory->createElement($name);
} | php | public function getElement(string $name): Element
{
if ($this->page_object_factory === null) {
throw new RuntimeException('[W406] To create elements you need to pass a factory with setPageObjectFactory()');
}
return $this->page_object_factory->createElement($name);
} | [
"public",
"function",
"getElement",
"(",
"string",
"$",
"name",
")",
":",
"Element",
"{",
"if",
"(",
"$",
"this",
"->",
"page_object_factory",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'[W406] To create elements you need to pass a factory with setPageObjectFactory()'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"page_object_factory",
"->",
"createElement",
"(",
"$",
"name",
")",
";",
"}"
] | Creates a page object element from its name.
@param string $name The name of the page object element e.g 'Toolbar'
@throws \RuntimeException
@return Element | [
"Creates",
"a",
"page",
"object",
"element",
"from",
"its",
"name",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/PageObjectAwareContextTrait.php#L44-L51 |
paulgibbs/behat-wordpress-extension | src/Driver/WpcliDriver.php | WpcliDriver.bootstrap | public function bootstrap()
{
$version = '';
preg_match('#^WP-CLI (.*)$#', $this->wpcli('cli', 'version')['stdout'], $match);
if (! empty($match)) {
$version = array_pop($match);
}
if (! version_compare($version, '1.5.0', '>=')) {
throw new RuntimeException('[W100] Your WP-CLI is too old; version 1.5.0 or newer is required.');
}
$status = $this->wpcli('core', 'is-installed')['exit_code'];
if ($status !== 0) {
throw new RuntimeException('[W101] WordPress does not seem to be installed. Check "path" and/or "alias" settings in behat.yml.');
}
putenv('WP_CLI_STRICT_ARGS_MODE=1');
$this->is_bootstrapped = true;
} | php | public function bootstrap()
{
$version = '';
preg_match('#^WP-CLI (.*)$#', $this->wpcli('cli', 'version')['stdout'], $match);
if (! empty($match)) {
$version = array_pop($match);
}
if (! version_compare($version, '1.5.0', '>=')) {
throw new RuntimeException('[W100] Your WP-CLI is too old; version 1.5.0 or newer is required.');
}
$status = $this->wpcli('core', 'is-installed')['exit_code'];
if ($status !== 0) {
throw new RuntimeException('[W101] WordPress does not seem to be installed. Check "path" and/or "alias" settings in behat.yml.');
}
putenv('WP_CLI_STRICT_ARGS_MODE=1');
$this->is_bootstrapped = true;
} | [
"public",
"function",
"bootstrap",
"(",
")",
"{",
"$",
"version",
"=",
"''",
";",
"preg_match",
"(",
"'#^WP-CLI (.*)$#'",
",",
"$",
"this",
"->",
"wpcli",
"(",
"'cli'",
",",
"'version'",
")",
"[",
"'stdout'",
"]",
",",
"$",
"match",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
")",
")",
"{",
"$",
"version",
"=",
"array_pop",
"(",
"$",
"match",
")",
";",
"}",
"if",
"(",
"!",
"version_compare",
"(",
"$",
"version",
",",
"'1.5.0'",
",",
"'>='",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'[W100] Your WP-CLI is too old; version 1.5.0 or newer is required.'",
")",
";",
"}",
"$",
"status",
"=",
"$",
"this",
"->",
"wpcli",
"(",
"'core'",
",",
"'is-installed'",
")",
"[",
"'exit_code'",
"]",
";",
"if",
"(",
"$",
"status",
"!==",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'[W101] WordPress does not seem to be installed. Check \"path\" and/or \"alias\" settings in behat.yml.'",
")",
";",
"}",
"putenv",
"(",
"'WP_CLI_STRICT_ARGS_MODE=1'",
")",
";",
"$",
"this",
"->",
"is_bootstrapped",
"=",
"true",
";",
"}"
] | Set up anything required for the driver.
Called when the driver is used for the first time.
Checks `core is-installed`, and the version number.
@throws \RuntimeException | [
"Set",
"up",
"anything",
"required",
"for",
"the",
"driver",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/WpcliDriver.php#L67-L88 |
paulgibbs/behat-wordpress-extension | src/Driver/WpcliDriver.php | WpcliDriver.wpcli | public function wpcli(string $command, string $subcommand, array $raw_arguments = []): array
{
$arguments = implode(' ', $raw_arguments);
$config = sprintf('--url=%s', escapeshellarg($this->url));
if ($this->path) {
$config .= sprintf(' --path=%s', escapeshellarg($this->path));
}
// Support WP-CLI environment aliases.
if ($this->alias) {
$config = "@{$this->alias}";
}
$command = "{$this->binary} {$config} --no-color {$command} {$subcommand} {$arguments}";
// Query WP-CLI.
$proc = proc_open(
$command,
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
if ($exit_code === 255 && ! $stdout) {
$stdout = 'Unable to connect to server via SSH. Is it on?';
}
throw new UnexpectedValueException(
sprintf(
"[W102] WP-CLI driver failure in method %1\$s():\n\n%2\$s.\n\nTried to run: %3\$s\n(%4\$s)",
debug_backtrace()[1]['function'],
$stdout,
$command,
$exit_code
)
);
}
return compact('stdout', 'exit_code');
} | php | public function wpcli(string $command, string $subcommand, array $raw_arguments = []): array
{
$arguments = implode(' ', $raw_arguments);
$config = sprintf('--url=%s', escapeshellarg($this->url));
if ($this->path) {
$config .= sprintf(' --path=%s', escapeshellarg($this->path));
}
// Support WP-CLI environment aliases.
if ($this->alias) {
$config = "@{$this->alias}";
}
$command = "{$this->binary} {$config} --no-color {$command} {$subcommand} {$arguments}";
// Query WP-CLI.
$proc = proc_open(
$command,
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
if ($exit_code === 255 && ! $stdout) {
$stdout = 'Unable to connect to server via SSH. Is it on?';
}
throw new UnexpectedValueException(
sprintf(
"[W102] WP-CLI driver failure in method %1\$s():\n\n%2\$s.\n\nTried to run: %3\$s\n(%4\$s)",
debug_backtrace()[1]['function'],
$stdout,
$command,
$exit_code
)
);
}
return compact('stdout', 'exit_code');
} | [
"public",
"function",
"wpcli",
"(",
"string",
"$",
"command",
",",
"string",
"$",
"subcommand",
",",
"array",
"$",
"raw_arguments",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"arguments",
"=",
"implode",
"(",
"' '",
",",
"$",
"raw_arguments",
")",
";",
"$",
"config",
"=",
"sprintf",
"(",
"'--url=%s'",
",",
"escapeshellarg",
"(",
"$",
"this",
"->",
"url",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"path",
")",
"{",
"$",
"config",
".=",
"sprintf",
"(",
"' --path=%s'",
",",
"escapeshellarg",
"(",
"$",
"this",
"->",
"path",
")",
")",
";",
"}",
"// Support WP-CLI environment aliases.",
"if",
"(",
"$",
"this",
"->",
"alias",
")",
"{",
"$",
"config",
"=",
"\"@{$this->alias}\"",
";",
"}",
"$",
"command",
"=",
"\"{$this->binary} {$config} --no-color {$command} {$subcommand} {$arguments}\"",
";",
"// Query WP-CLI.",
"$",
"proc",
"=",
"proc_open",
"(",
"$",
"command",
",",
"array",
"(",
"1",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
"2",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
")",
",",
"$",
"pipes",
")",
";",
"$",
"stdout",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
")",
";",
"$",
"stderr",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"$",
"exit_code",
"=",
"proc_close",
"(",
"$",
"proc",
")",
";",
"// Sometimes the error message is in stderr.",
"if",
"(",
"!",
"$",
"stdout",
"&&",
"$",
"stderr",
")",
"{",
"$",
"stdout",
"=",
"$",
"stderr",
";",
"}",
"if",
"(",
"$",
"exit_code",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Warning: '",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Error: '",
")",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"exit_code",
"===",
"255",
"&&",
"!",
"$",
"stdout",
")",
"{",
"$",
"stdout",
"=",
"'Unable to connect to server via SSH. Is it on?'",
";",
"}",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"\"[W102] WP-CLI driver failure in method %1\\$s():\\n\\n%2\\$s.\\n\\nTried to run: %3\\$s\\n(%4\\$s)\"",
",",
"debug_backtrace",
"(",
")",
"[",
"1",
"]",
"[",
"'function'",
"]",
",",
"$",
"stdout",
",",
"$",
"command",
",",
"$",
"exit_code",
")",
")",
";",
"}",
"return",
"compact",
"(",
"'stdout'",
",",
"'exit_code'",
")",
";",
"}"
] | Execute a WP-CLI command.
@param string $command Command name.
@param string $subcommand Subcommand name.
@param string[] $raw_arguments Optional. Associative array of arguments for the command.
@throws \UnexpectedValueException
@return array {
WP-CLI command results.
@type string $stdout Response text from WP-CLI.
@type int $exit_code Returned status code of the executed command.
} | [
"Execute",
"a",
"WP",
"-",
"CLI",
"command",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/WpcliDriver.php#L106-L160 |
paulgibbs/behat-wordpress-extension | src/PageObject/DashboardPage.php | DashboardPage.verifyPage | protected function verifyPage()
{
$url = $this->getSession()->getCurrentUrl();
if (strrpos($url, $this->path) !== false) {
return;
}
throw new ExpectationException(
sprintf(
'[W401] Expected screen is the wp-admin dashboard, instead on "%1$s".',
$url
),
$this->getDriver()
);
} | php | protected function verifyPage()
{
$url = $this->getSession()->getCurrentUrl();
if (strrpos($url, $this->path) !== false) {
return;
}
throw new ExpectationException(
sprintf(
'[W401] Expected screen is the wp-admin dashboard, instead on "%1$s".',
$url
),
$this->getDriver()
);
} | [
"protected",
"function",
"verifyPage",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getCurrentUrl",
"(",
")",
";",
"if",
"(",
"strrpos",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"path",
")",
"!==",
"false",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'[W401] Expected screen is the wp-admin dashboard, instead on \"%1$s\".'",
",",
"$",
"url",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}"
] | Asserts the current screen is the Dashboard.
@throws ExpectationException | [
"Asserts",
"the",
"current",
"screen",
"is",
"the",
"Dashboard",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/DashboardPage.php#L22-L37 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/WidgetElement.php | WidgetElement.addToSidebar | public function addToSidebar($widget_name, $sidebar_id, $args)
{
$widget_name = strtolower($widget_name);
$wpcli_args = array_merge([
$widget_name,
$sidebar_id
], buildCLIArgs(array_keys($args), $args));
$this->drivers->getDriver()->wpcli('widget', 'add', $wpcli_args);
} | php | public function addToSidebar($widget_name, $sidebar_id, $args)
{
$widget_name = strtolower($widget_name);
$wpcli_args = array_merge([
$widget_name,
$sidebar_id
], buildCLIArgs(array_keys($args), $args));
$this->drivers->getDriver()->wpcli('widget', 'add', $wpcli_args);
} | [
"public",
"function",
"addToSidebar",
"(",
"$",
"widget_name",
",",
"$",
"sidebar_id",
",",
"$",
"args",
")",
"{",
"$",
"widget_name",
"=",
"strtolower",
"(",
"$",
"widget_name",
")",
";",
"$",
"wpcli_args",
"=",
"array_merge",
"(",
"[",
"$",
"widget_name",
",",
"$",
"sidebar_id",
"]",
",",
"buildCLIArgs",
"(",
"array_keys",
"(",
"$",
"args",
")",
",",
"$",
"args",
")",
")",
";",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'widget'",
",",
"'add'",
",",
"$",
"wpcli_args",
")",
";",
"}"
] | Adds a widget to the sidebar with the specified arguments
@param string $widget_name The ID base of the widget (e.g. 'meta', 'calendar'). Case insensitive.
@param string $sidebar_id The ID of the sidebar to the add the widget to
@param array $args Associative array of widget settings for this widget | [
"Adds",
"a",
"widget",
"to",
"the",
"sidebar",
"with",
"the",
"specified",
"arguments"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/WidgetElement.php#L22-L32 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/WidgetElement.php | WidgetElement.getSidebar | public function getSidebar($sidebar_name)
{
$registered_sidebars = json_decode($this->drivers->getDriver()->wpcli('sidebar', 'list', [
'--format=json',
])['stdout']);
$sidebar_id = null;
foreach ($registered_sidebars as $sidebar) {
if ($sidebar_name === $sidebar->name) {
$sidebar_id = $sidebar->id;
break;
}
}
if ($sidebar_id === null) {
throw new UnexpectedValueException(sprintf('[W506] Sidebar "%s" does not exist', $sidebar_name));
}
return $sidebar_id;
} | php | public function getSidebar($sidebar_name)
{
$registered_sidebars = json_decode($this->drivers->getDriver()->wpcli('sidebar', 'list', [
'--format=json',
])['stdout']);
$sidebar_id = null;
foreach ($registered_sidebars as $sidebar) {
if ($sidebar_name === $sidebar->name) {
$sidebar_id = $sidebar->id;
break;
}
}
if ($sidebar_id === null) {
throw new UnexpectedValueException(sprintf('[W506] Sidebar "%s" does not exist', $sidebar_name));
}
return $sidebar_id;
} | [
"public",
"function",
"getSidebar",
"(",
"$",
"sidebar_name",
")",
"{",
"$",
"registered_sidebars",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'sidebar'",
",",
"'list'",
",",
"[",
"'--format=json'",
",",
"]",
")",
"[",
"'stdout'",
"]",
")",
";",
"$",
"sidebar_id",
"=",
"null",
";",
"foreach",
"(",
"$",
"registered_sidebars",
"as",
"$",
"sidebar",
")",
"{",
"if",
"(",
"$",
"sidebar_name",
"===",
"$",
"sidebar",
"->",
"name",
")",
"{",
"$",
"sidebar_id",
"=",
"$",
"sidebar",
"->",
"id",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"sidebar_id",
"===",
"null",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W506] Sidebar \"%s\" does not exist'",
",",
"$",
"sidebar_name",
")",
")",
";",
"}",
"return",
"$",
"sidebar_id",
";",
"}"
] | Gets a sidebar ID from its human-readable name
@param string $sidebar_name The name of the sidebar (e.g. 'Footer', 'Widget Area', 'Right Sidebar')
@throws UnexpectedValueException If the sidebar is not registered
@return string The sidebar ID | [
"Gets",
"a",
"sidebar",
"ID",
"from",
"its",
"human",
"-",
"readable",
"name"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/WidgetElement.php#L43-L63 |
paulgibbs/behat-wordpress-extension | src/Driver/WpphpDriver.php | WpphpDriver.bootstrap | public function bootstrap()
{
if (! defined('ABSPATH')) {
define('ABSPATH', "{$this->path}/");
}
$_SERVER['DOCUMENT_ROOT'] = $this->path;
$_SERVER['HTTP_HOST'] = '';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['SERVER_NAME'] = '';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
if (! file_exists("{$this->path}/index.php")) {
throw new RuntimeException(sprintf('[W200] WordPress PHP driver cannot find WordPress at %s.', $this->path));
}
// "Cry 'Havoc!' and let slip the dogs of war".
require_once "{$this->path}/wp-blog-header.php";
if (! function_exists('activate_plugin')) {
require_once "{$this->path}/wp-admin/includes/plugin.php";
require_once "{$this->path}/wp-admin/includes/plugin-install.php";
}
$this->wpdb = $GLOBALS['wpdb'];
$this->is_bootstrapped = true;
} | php | public function bootstrap()
{
if (! defined('ABSPATH')) {
define('ABSPATH', "{$this->path}/");
}
$_SERVER['DOCUMENT_ROOT'] = $this->path;
$_SERVER['HTTP_HOST'] = '';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['SERVER_NAME'] = '';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
if (! file_exists("{$this->path}/index.php")) {
throw new RuntimeException(sprintf('[W200] WordPress PHP driver cannot find WordPress at %s.', $this->path));
}
// "Cry 'Havoc!' and let slip the dogs of war".
require_once "{$this->path}/wp-blog-header.php";
if (! function_exists('activate_plugin')) {
require_once "{$this->path}/wp-admin/includes/plugin.php";
require_once "{$this->path}/wp-admin/includes/plugin-install.php";
}
$this->wpdb = $GLOBALS['wpdb'];
$this->is_bootstrapped = true;
} | [
"public",
"function",
"bootstrap",
"(",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'ABSPATH'",
")",
")",
"{",
"define",
"(",
"'ABSPATH'",
",",
"\"{$this->path}/\"",
")",
";",
"}",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
"=",
"$",
"this",
"->",
"path",
";",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
"=",
"''",
";",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"=",
"'GET'",
";",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"=",
"'/'",
";",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
"=",
"''",
";",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
"=",
"'HTTP/1.1'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"\"{$this->path}/index.php\"",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'[W200] WordPress PHP driver cannot find WordPress at %s.'",
",",
"$",
"this",
"->",
"path",
")",
")",
";",
"}",
"// \"Cry 'Havoc!' and let slip the dogs of war\".",
"require_once",
"\"{$this->path}/wp-blog-header.php\"",
";",
"if",
"(",
"!",
"function_exists",
"(",
"'activate_plugin'",
")",
")",
"{",
"require_once",
"\"{$this->path}/wp-admin/includes/plugin.php\"",
";",
"require_once",
"\"{$this->path}/wp-admin/includes/plugin-install.php\"",
";",
"}",
"$",
"this",
"->",
"wpdb",
"=",
"$",
"GLOBALS",
"[",
"'wpdb'",
"]",
";",
"$",
"this",
"->",
"is_bootstrapped",
"=",
"true",
";",
"}"
] | Set up anything required for the driver.
Called when the driver is used for the first time.
@throws \RuntimeException | [
"Set",
"up",
"anything",
"required",
"for",
"the",
"driver",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/WpphpDriver.php#L43-L70 |
paulgibbs/behat-wordpress-extension | src/Driver/WpphpDriver.php | WpphpDriver.getPlugin | public function getPlugin($name)
{
foreach (array_keys(get_plugins()) as $file) {
// Logic taken from WP-CLI.
if ($file === "{$name}.php" || ($name && $file === $name) || (dirname($file) === $name && $name !== '.')) {
return $file;
}
}
return '';
} | php | public function getPlugin($name)
{
foreach (array_keys(get_plugins()) as $file) {
// Logic taken from WP-CLI.
if ($file === "{$name}.php" || ($name && $file === $name) || (dirname($file) === $name && $name !== '.')) {
return $file;
}
}
return '';
} | [
"public",
"function",
"getPlugin",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"get_plugins",
"(",
")",
")",
"as",
"$",
"file",
")",
"{",
"// Logic taken from WP-CLI.",
"if",
"(",
"$",
"file",
"===",
"\"{$name}.php\"",
"||",
"(",
"$",
"name",
"&&",
"$",
"file",
"===",
"$",
"name",
")",
"||",
"(",
"dirname",
"(",
"$",
"file",
")",
"===",
"$",
"name",
"&&",
"$",
"name",
"!==",
"'.'",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Get information about a plugin.
@param string $name
@return string Plugin filename and path. | [
"Get",
"information",
"about",
"a",
"plugin",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/WpphpDriver.php#L84-L94 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/DatabaseElement.php | DatabaseElement.get | public function get($id, $args = [])
{
if (empty($args['path'])) {
$args['path'] = sys_get_temp_dir();
}
$bin = '';
$path = tempnam($args['path'], 'wordhat');
$command_args = sprintf(
'--no-defaults %1$s --add-drop-table --result-file=%2$s --host=%3$s --user=%4$s',
DB_NAME,
$path,
DB_HOST,
DB_USER
);
$old_pwd = getenv('MYSQL_PWD');
putenv('MYSQL_PWD=' . DB_PASSWORD);
// Support Windows.
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$bin = '/usr/bin/env ';
}
// Export DB via mysqldump.
$proc = proc_open(
"{$bin}mysqldump {$command_args}",
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
putenv('MYSQL_PWD=' . $old_pwd);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
throw new RuntimeException(
sprintf(
"[W606] Could not export database in method %1\$s(): \n\n%2\$s.\n(%3\$s)",
debug_backtrace()[1]['function'],
$stdout,
$exit_code
)
);
}
return $path;
} | php | public function get($id, $args = [])
{
if (empty($args['path'])) {
$args['path'] = sys_get_temp_dir();
}
$bin = '';
$path = tempnam($args['path'], 'wordhat');
$command_args = sprintf(
'--no-defaults %1$s --add-drop-table --result-file=%2$s --host=%3$s --user=%4$s',
DB_NAME,
$path,
DB_HOST,
DB_USER
);
$old_pwd = getenv('MYSQL_PWD');
putenv('MYSQL_PWD=' . DB_PASSWORD);
// Support Windows.
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$bin = '/usr/bin/env ';
}
// Export DB via mysqldump.
$proc = proc_open(
"{$bin}mysqldump {$command_args}",
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
putenv('MYSQL_PWD=' . $old_pwd);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
throw new RuntimeException(
sprintf(
"[W606] Could not export database in method %1\$s(): \n\n%2\$s.\n(%3\$s)",
debug_backtrace()[1]['function'],
$stdout,
$exit_code
)
);
}
return $path;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'path'",
"]",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"$",
"bin",
"=",
"''",
";",
"$",
"path",
"=",
"tempnam",
"(",
"$",
"args",
"[",
"'path'",
"]",
",",
"'wordhat'",
")",
";",
"$",
"command_args",
"=",
"sprintf",
"(",
"'--no-defaults %1$s --add-drop-table --result-file=%2$s --host=%3$s --user=%4$s'",
",",
"DB_NAME",
",",
"$",
"path",
",",
"DB_HOST",
",",
"DB_USER",
")",
";",
"$",
"old_pwd",
"=",
"getenv",
"(",
"'MYSQL_PWD'",
")",
";",
"putenv",
"(",
"'MYSQL_PWD='",
".",
"DB_PASSWORD",
")",
";",
"// Support Windows.",
"if",
"(",
"strtoupper",
"(",
"substr",
"(",
"PHP_OS",
",",
"0",
",",
"3",
")",
")",
"===",
"'WIN'",
")",
"{",
"$",
"bin",
"=",
"'/usr/bin/env '",
";",
"}",
"// Export DB via mysqldump.",
"$",
"proc",
"=",
"proc_open",
"(",
"\"{$bin}mysqldump {$command_args}\"",
",",
"array",
"(",
"1",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
"2",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
")",
",",
"$",
"pipes",
")",
";",
"$",
"stdout",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
")",
";",
"$",
"stderr",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"$",
"exit_code",
"=",
"proc_close",
"(",
"$",
"proc",
")",
";",
"putenv",
"(",
"'MYSQL_PWD='",
".",
"$",
"old_pwd",
")",
";",
"// Sometimes the error message is in stderr.",
"if",
"(",
"!",
"$",
"stdout",
"&&",
"$",
"stderr",
")",
"{",
"$",
"stdout",
"=",
"$",
"stderr",
";",
"}",
"if",
"(",
"$",
"exit_code",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Warning: '",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Error: '",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"\"[W606] Could not export database in method %1\\$s(): \\n\\n%2\\$s.\\n(%3\\$s)\"",
",",
"debug_backtrace",
"(",
")",
"[",
"1",
"]",
"[",
"'function'",
"]",
",",
"$",
"stdout",
",",
"$",
"exit_code",
")",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Export site database.
@param int $id Not used.
@param array $args
@return string Path to the database dump. | [
"Export",
"site",
"database",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/DatabaseElement.php#L21-L79 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/DatabaseElement.php | DatabaseElement.update | public function update($id, $args = [])
{
$bin = '';
$command_args = sprintf(
'--no-defaults --no-auto-rehash --host=%1$s --user=%2$s --database=%3$s --execute=%4$s',
DB_HOST,
DB_USER,
DB_NAME,
escapeshellarg(sprintf(
'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %1$s; COMMIT;',
$args['path']
))
);
$old_pwd = getenv('MYSQL_PWD');
putenv('MYSQL_PWD=' . DB_PASSWORD);
// Support Windows.
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$bin = '/usr/bin/env ';
}
// Import DB via mysql-cli.
$proc = proc_open(
"{$bin}mysql {$command_args}",
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
putenv('MYSQL_PWD=' . $old_pwd);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
throw new RuntimeException(
sprintf(
"[W607] Could not import database in method %1\$s(): \n\n%2\$s.\n(%3\$s)",
debug_backtrace()[1]['function'],
$stdout,
$exit_code
)
);
}
/*
* clear the cache after restoration - this is probably only necessary
* because of some kind of global state issue - the WPCLI driver doensn't
* need it. There is some discussion about it here:
*
* https://github.com/paulgibbs/behat-wordpress-extension/pull/150
*/
\wp_cache_flush();
} | php | public function update($id, $args = [])
{
$bin = '';
$command_args = sprintf(
'--no-defaults --no-auto-rehash --host=%1$s --user=%2$s --database=%3$s --execute=%4$s',
DB_HOST,
DB_USER,
DB_NAME,
escapeshellarg(sprintf(
'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %1$s; COMMIT;',
$args['path']
))
);
$old_pwd = getenv('MYSQL_PWD');
putenv('MYSQL_PWD=' . DB_PASSWORD);
// Support Windows.
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$bin = '/usr/bin/env ';
}
// Import DB via mysql-cli.
$proc = proc_open(
"{$bin}mysql {$command_args}",
array(
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
),
$pipes
);
$stdout = trim(stream_get_contents($pipes[1]));
$stderr = trim(stream_get_contents($pipes[2]));
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($proc);
putenv('MYSQL_PWD=' . $old_pwd);
// Sometimes the error message is in stderr.
if (! $stdout && $stderr) {
$stdout = $stderr;
}
if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
throw new RuntimeException(
sprintf(
"[W607] Could not import database in method %1\$s(): \n\n%2\$s.\n(%3\$s)",
debug_backtrace()[1]['function'],
$stdout,
$exit_code
)
);
}
/*
* clear the cache after restoration - this is probably only necessary
* because of some kind of global state issue - the WPCLI driver doensn't
* need it. There is some discussion about it here:
*
* https://github.com/paulgibbs/behat-wordpress-extension/pull/150
*/
\wp_cache_flush();
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"bin",
"=",
"''",
";",
"$",
"command_args",
"=",
"sprintf",
"(",
"'--no-defaults --no-auto-rehash --host=%1$s --user=%2$s --database=%3$s --execute=%4$s'",
",",
"DB_HOST",
",",
"DB_USER",
",",
"DB_NAME",
",",
"escapeshellarg",
"(",
"sprintf",
"(",
"'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %1$s; COMMIT;'",
",",
"$",
"args",
"[",
"'path'",
"]",
")",
")",
")",
";",
"$",
"old_pwd",
"=",
"getenv",
"(",
"'MYSQL_PWD'",
")",
";",
"putenv",
"(",
"'MYSQL_PWD='",
".",
"DB_PASSWORD",
")",
";",
"// Support Windows.",
"if",
"(",
"strtoupper",
"(",
"substr",
"(",
"PHP_OS",
",",
"0",
",",
"3",
")",
")",
"===",
"'WIN'",
")",
"{",
"$",
"bin",
"=",
"'/usr/bin/env '",
";",
"}",
"// Import DB via mysql-cli.",
"$",
"proc",
"=",
"proc_open",
"(",
"\"{$bin}mysql {$command_args}\"",
",",
"array",
"(",
"1",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
"2",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
")",
",",
"$",
"pipes",
")",
";",
"$",
"stdout",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
")",
";",
"$",
"stderr",
"=",
"trim",
"(",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"$",
"exit_code",
"=",
"proc_close",
"(",
"$",
"proc",
")",
";",
"putenv",
"(",
"'MYSQL_PWD='",
".",
"$",
"old_pwd",
")",
";",
"// Sometimes the error message is in stderr.",
"if",
"(",
"!",
"$",
"stdout",
"&&",
"$",
"stderr",
")",
"{",
"$",
"stdout",
"=",
"$",
"stderr",
";",
"}",
"if",
"(",
"$",
"exit_code",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Warning: '",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"stdout",
",",
"'Error: '",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"\"[W607] Could not import database in method %1\\$s(): \\n\\n%2\\$s.\\n(%3\\$s)\"",
",",
"debug_backtrace",
"(",
")",
"[",
"1",
"]",
"[",
"'function'",
"]",
",",
"$",
"stdout",
",",
"$",
"exit_code",
")",
")",
";",
"}",
"/*\n * clear the cache after restoration - this is probably only necessary\n * because of some kind of global state issue - the WPCLI driver doensn't\n * need it. There is some discussion about it here:\n *\n * https://github.com/paulgibbs/behat-wordpress-extension/pull/150\n */",
"\\",
"wp_cache_flush",
"(",
")",
";",
"}"
] | Import site database.
@param int $id Not used.
@param array $args | [
"Import",
"site",
"database",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/DatabaseElement.php#L87-L150 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/ThemeElement.php | ThemeElement.update | public function update($id, $args = [])
{
$theme = wp_get_theme($id);
if (! $theme->exists()) {
throw new UnexpectedValueException(sprintf('[W612] Could not find theme %s', $id));
}
switch_theme($theme->get_template());
} | php | public function update($id, $args = [])
{
$theme = wp_get_theme($id);
if (! $theme->exists()) {
throw new UnexpectedValueException(sprintf('[W612] Could not find theme %s', $id));
}
switch_theme($theme->get_template());
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"theme",
"=",
"wp_get_theme",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"theme",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W612] Could not find theme %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"switch_theme",
"(",
"$",
"theme",
"->",
"get_template",
"(",
")",
")",
";",
"}"
] | Switch active theme.
@param string $id Theme name to switch to.
@param array $args Not used.
@throws \UnexpectedValueException | [
"Switch",
"active",
"theme",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/ThemeElement.php#L21-L30 |
paulgibbs/behat-wordpress-extension | src/Context/RawWordpressContext.php | RawWordpressContext.locatePath | public function locatePath($path)
{
if (stripos($path, 'http') === 0) {
return $path;
}
$url = $this->getMinkParameter('base_url');
if (strpos($path, 'wp-admin') !== false || strpos($path, '.php') !== false) {
$url = $this->getWordpressParameter('site_url');
}
return rtrim($url, '/') . '/' . ltrim($path, '/');
} | php | public function locatePath($path)
{
if (stripos($path, 'http') === 0) {
return $path;
}
$url = $this->getMinkParameter('base_url');
if (strpos($path, 'wp-admin') !== false || strpos($path, '.php') !== false) {
$url = $this->getWordpressParameter('site_url');
}
return rtrim($url, '/') . '/' . ltrim($path, '/');
} | [
"public",
"function",
"locatePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"path",
",",
"'http'",
")",
"===",
"0",
")",
"{",
"return",
"$",
"path",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"getMinkParameter",
"(",
"'base_url'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'wp-admin'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"path",
",",
"'.php'",
")",
"!==",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getWordpressParameter",
"(",
"'site_url'",
")",
";",
"}",
"return",
"rtrim",
"(",
"$",
"url",
",",
"'/'",
")",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}"
] | Build URL, based on provided path.
@param string $path Relative or absolute URL.
@return string | [
"Build",
"URL",
"based",
"on",
"provided",
"path",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/RawWordpressContext.php#L48-L61 |
paulgibbs/behat-wordpress-extension | src/Context/RawWordpressContext.php | RawWordpressContext.getWordpressParameter | public function getWordpressParameter(string $name)
{
return ! empty($this->wordpress_parameters[$name]) ? $this->wordpress_parameters[$name] : null;
} | php | public function getWordpressParameter(string $name)
{
return ! empty($this->wordpress_parameters[$name]) ? $this->wordpress_parameters[$name] : null;
} | [
"public",
"function",
"getWordpressParameter",
"(",
"string",
"$",
"name",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"wordpress_parameters",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"wordpress_parameters",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Get a specific WordPress parameter.
IMPORTANT: this only sets the variable for the current Context!
Each Context exists independently.
@param string $name Parameter name.
@return mixed | [
"Get",
"a",
"specific",
"WordPress",
"parameter",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/RawWordpressContext.php#L106-L109 |
paulgibbs/behat-wordpress-extension | src/Context/RawWordpressContext.php | RawWordpressContext.getRandomString | public function getRandomString(int $length = 64): string
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()';
$random = '';
for ($i = 0; $i < $length; $i++) {
$random .= substr($chars, random_int(0, strlen($chars) - 1), 1);
}
return $random;
} | php | public function getRandomString(int $length = 64): string
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()';
$random = '';
for ($i = 0; $i < $length; $i++) {
$random .= substr($chars, random_int(0, strlen($chars) - 1), 1);
}
return $random;
} | [
"public",
"function",
"getRandomString",
"(",
"int",
"$",
"length",
"=",
"64",
")",
":",
"string",
"{",
"$",
"chars",
"=",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()'",
";",
"$",
"random",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"random",
".=",
"substr",
"(",
"$",
"chars",
",",
"random_int",
"(",
"0",
",",
"strlen",
"(",
"$",
"chars",
")",
"-",
"1",
")",
",",
"1",
")",
";",
"}",
"return",
"$",
"random",
";",
"}"
] | Get a random string.
@see https://developer.wordpress.org/reference/functions/wp_generate_password/ Implementation copied from WordPress.
@param int $length Optional. Length of string to return. Default is 64.
@return string | [
"Get",
"a",
"random",
"string",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/RawWordpressContext.php#L150-L160 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/Toolbar.php | Toolbar.clickToolbarLink | public function clickToolbarLink(string $link)
{
$link_parts = array_map('trim', preg_split('/(?<!\\\\)>/', $link));
$click_node = false;
$first_level_items = $this->findAll('css', '.ab-top-menu > li');
foreach ($first_level_items as $first_level_item) {
if (! $this->elementIsTargetLink($first_level_item, $link_parts[0])) {
continue;
}
if (count($link_parts) > 1) {
$click_node = $this->getSubmenuLinkNode($first_level_item, $link_parts[1]);
} else {
// We are clicking a top-level item:
$click_node = $first_level_item->find('css', 'a');
}
break;
}
if (false === $click_node) {
throw new ExpectationException(
sprintf('[W403] Toolbar link "%s" could not be found', $link),
$this->getDriver()
);
}
$click_node->click();
} | php | public function clickToolbarLink(string $link)
{
$link_parts = array_map('trim', preg_split('/(?<!\\\\)>/', $link));
$click_node = false;
$first_level_items = $this->findAll('css', '.ab-top-menu > li');
foreach ($first_level_items as $first_level_item) {
if (! $this->elementIsTargetLink($first_level_item, $link_parts[0])) {
continue;
}
if (count($link_parts) > 1) {
$click_node = $this->getSubmenuLinkNode($first_level_item, $link_parts[1]);
} else {
// We are clicking a top-level item:
$click_node = $first_level_item->find('css', 'a');
}
break;
}
if (false === $click_node) {
throw new ExpectationException(
sprintf('[W403] Toolbar link "%s" could not be found', $link),
$this->getDriver()
);
}
$click_node->click();
} | [
"public",
"function",
"clickToolbarLink",
"(",
"string",
"$",
"link",
")",
"{",
"$",
"link_parts",
"=",
"array_map",
"(",
"'trim'",
",",
"preg_split",
"(",
"'/(?<!\\\\\\\\)>/'",
",",
"$",
"link",
")",
")",
";",
"$",
"click_node",
"=",
"false",
";",
"$",
"first_level_items",
"=",
"$",
"this",
"->",
"findAll",
"(",
"'css'",
",",
"'.ab-top-menu > li'",
")",
";",
"foreach",
"(",
"$",
"first_level_items",
"as",
"$",
"first_level_item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"elementIsTargetLink",
"(",
"$",
"first_level_item",
",",
"$",
"link_parts",
"[",
"0",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"link_parts",
")",
">",
"1",
")",
"{",
"$",
"click_node",
"=",
"$",
"this",
"->",
"getSubmenuLinkNode",
"(",
"$",
"first_level_item",
",",
"$",
"link_parts",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"// We are clicking a top-level item:",
"$",
"click_node",
"=",
"$",
"first_level_item",
"->",
"find",
"(",
"'css'",
",",
"'a'",
")",
";",
"}",
"break",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"click_node",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'[W403] Toolbar link \"%s\" could not be found'",
",",
"$",
"link",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"$",
"click_node",
"->",
"click",
"(",
")",
";",
"}"
] | Click a specific item in the toolbar.
Top-level items are identified by their link text (e.g. 'Comments').
Second-level items are identified by their parent text and link text,
delimited by a right angle bracket. E.g. New > Post.
@param string $link The toolbar item to click.
@throws \Behat\Mink\Exception\ExpectationException If the menu item does not exist | [
"Click",
"a",
"specific",
"item",
"in",
"the",
"toolbar",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/Toolbar.php#L32-L62 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/Toolbar.php | Toolbar.elementIsTargetLink | protected function elementIsTargetLink(NodeElement $element, string $link_text): bool
{
$current_item_name = strtolower($element->find('css', '.ab-item')->getText());
switch (strtolower($link_text)) {
case 'wordpress':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-wp-logo';
break;
case 'updates':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-updates';
break;
case 'comments':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-comments';
break;
default:
$is_link = strtolower($link_text) === $current_item_name;
}
return $is_link;
} | php | protected function elementIsTargetLink(NodeElement $element, string $link_text): bool
{
$current_item_name = strtolower($element->find('css', '.ab-item')->getText());
switch (strtolower($link_text)) {
case 'wordpress':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-wp-logo';
break;
case 'updates':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-updates';
break;
case 'comments':
$is_link = $element->getAttribute('id') === 'wp-admin-bar-comments';
break;
default:
$is_link = strtolower($link_text) === $current_item_name;
}
return $is_link;
} | [
"protected",
"function",
"elementIsTargetLink",
"(",
"NodeElement",
"$",
"element",
",",
"string",
"$",
"link_text",
")",
":",
"bool",
"{",
"$",
"current_item_name",
"=",
"strtolower",
"(",
"$",
"element",
"->",
"find",
"(",
"'css'",
",",
"'.ab-item'",
")",
"->",
"getText",
"(",
")",
")",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"link_text",
")",
")",
"{",
"case",
"'wordpress'",
":",
"$",
"is_link",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'id'",
")",
"===",
"'wp-admin-bar-wp-logo'",
";",
"break",
";",
"case",
"'updates'",
":",
"$",
"is_link",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'id'",
")",
"===",
"'wp-admin-bar-updates'",
";",
"break",
";",
"case",
"'comments'",
":",
"$",
"is_link",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'id'",
")",
"===",
"'wp-admin-bar-comments'",
";",
"break",
";",
"default",
":",
"$",
"is_link",
"=",
"strtolower",
"(",
"$",
"link_text",
")",
"===",
"$",
"current_item_name",
";",
"}",
"return",
"$",
"is_link",
";",
"}"
] | Determines whether the link name refers to the given NodeElement.
Some toolbar links do not have any visible text, so we handle those
separately. Otherwise we compare the link text to the text of the
element.
@param \Behat\Mink\Element\NodeElement $element The element to check
@param string $link_text The link (text) to check for
@return bool True if $link_text refers to $element. False otherwise. | [
"Determines",
"whether",
"the",
"link",
"name",
"refers",
"to",
"the",
"given",
"NodeElement",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/Toolbar.php#L76-L95 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/Toolbar.php | Toolbar.getSubmenuLinkNode | protected function getSubmenuLinkNode(NodeElement $first_level_item, string $link_text)
{
$second_level_items = $first_level_item->findAll('css', 'ul li a');
$submenu_link_node = null;
foreach ($second_level_items as $second_level_item) {
$current_item_name = Util\stripTagsAndContent($second_level_item->getHtml());
if (strtolower($link_text) !== strtolower($current_item_name)) {
continue;
}
$id = $first_level_item->getAttribute('id');
try {
$element_exists = $this->getSession()->evaluateScript(
'return document.getElementById("' . $id . '");'
);
if ($element_exists !== null) {
// "Focus" (add hover class) on the toolbar link so the submenu appears.
$this->getSession()->executeScript(
'document.getElementById("' . $id . '").classList.add("hover");'
);
}
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
$submenu_link_node = $second_level_item;
break;
}
return $submenu_link_node;
} | php | protected function getSubmenuLinkNode(NodeElement $first_level_item, string $link_text)
{
$second_level_items = $first_level_item->findAll('css', 'ul li a');
$submenu_link_node = null;
foreach ($second_level_items as $second_level_item) {
$current_item_name = Util\stripTagsAndContent($second_level_item->getHtml());
if (strtolower($link_text) !== strtolower($current_item_name)) {
continue;
}
$id = $first_level_item->getAttribute('id');
try {
$element_exists = $this->getSession()->evaluateScript(
'return document.getElementById("' . $id . '");'
);
if ($element_exists !== null) {
// "Focus" (add hover class) on the toolbar link so the submenu appears.
$this->getSession()->executeScript(
'document.getElementById("' . $id . '").classList.add("hover");'
);
}
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
$submenu_link_node = $second_level_item;
break;
}
return $submenu_link_node;
} | [
"protected",
"function",
"getSubmenuLinkNode",
"(",
"NodeElement",
"$",
"first_level_item",
",",
"string",
"$",
"link_text",
")",
"{",
"$",
"second_level_items",
"=",
"$",
"first_level_item",
"->",
"findAll",
"(",
"'css'",
",",
"'ul li a'",
")",
";",
"$",
"submenu_link_node",
"=",
"null",
";",
"foreach",
"(",
"$",
"second_level_items",
"as",
"$",
"second_level_item",
")",
"{",
"$",
"current_item_name",
"=",
"Util",
"\\",
"stripTagsAndContent",
"(",
"$",
"second_level_item",
"->",
"getHtml",
"(",
")",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"link_text",
")",
"!==",
"strtolower",
"(",
"$",
"current_item_name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"id",
"=",
"$",
"first_level_item",
"->",
"getAttribute",
"(",
"'id'",
")",
";",
"try",
"{",
"$",
"element_exists",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"evaluateScript",
"(",
"'return document.getElementById(\"'",
".",
"$",
"id",
".",
"'\");'",
")",
";",
"if",
"(",
"$",
"element_exists",
"!==",
"null",
")",
"{",
"// \"Focus\" (add hover class) on the toolbar link so the submenu appears.",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"executeScript",
"(",
"'document.getElementById(\"'",
".",
"$",
"id",
".",
"'\").classList.add(\"hover\");'",
")",
";",
"}",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"}",
"$",
"submenu_link_node",
"=",
"$",
"second_level_item",
";",
"break",
";",
"}",
"return",
"$",
"submenu_link_node",
";",
"}"
] | Returns a second-level toolbar NodeElement corresponding to the link text
under the given first-level toolbar NodeElement.
@param \Behat\Mink\Element\NodeElement $first_level_item The element to check under.
@param string $link_text The link (text) to check for.
@return \Behat\Mink\Element\NodeElement|null | [
"Returns",
"a",
"second",
"-",
"level",
"toolbar",
"NodeElement",
"corresponding",
"to",
"the",
"link",
"text",
"under",
"the",
"given",
"first",
"-",
"level",
"toolbar",
"NodeElement",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/Toolbar.php#L106-L140 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/Toolbar.php | Toolbar.search | public function search(string $text)
{
$search = $this->find('css', '#adminbarsearch');
if (! $search) {
throw new ExpectationException(
'[W404] Search field in the toolbar could not be found',
$this->getDriver()
);
}
try {
$search->find('css', '#adminbar-search')->press();
$search->find('css', '#adminbar-search')->focus();
$search->fillField('adminbar-search', $text);
$search->find('css', '#adminbar-search')->focus();
} catch (UnsupportedDriverActionException $e) {
$search->fillField('adminbar-search', $text);
}
$search->submit();
} | php | public function search(string $text)
{
$search = $this->find('css', '#adminbarsearch');
if (! $search) {
throw new ExpectationException(
'[W404] Search field in the toolbar could not be found',
$this->getDriver()
);
}
try {
$search->find('css', '#adminbar-search')->press();
$search->find('css', '#adminbar-search')->focus();
$search->fillField('adminbar-search', $text);
$search->find('css', '#adminbar-search')->focus();
} catch (UnsupportedDriverActionException $e) {
$search->fillField('adminbar-search', $text);
}
$search->submit();
} | [
"public",
"function",
"search",
"(",
"string",
"$",
"text",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'#adminbarsearch'",
")",
";",
"if",
"(",
"!",
"$",
"search",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"'[W404] Search field in the toolbar could not be found'",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"try",
"{",
"$",
"search",
"->",
"find",
"(",
"'css'",
",",
"'#adminbar-search'",
")",
"->",
"press",
"(",
")",
";",
"$",
"search",
"->",
"find",
"(",
"'css'",
",",
"'#adminbar-search'",
")",
"->",
"focus",
"(",
")",
";",
"$",
"search",
"->",
"fillField",
"(",
"'adminbar-search'",
",",
"$",
"text",
")",
";",
"$",
"search",
"->",
"find",
"(",
"'css'",
",",
"'#adminbar-search'",
")",
"->",
"focus",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"$",
"search",
"->",
"fillField",
"(",
"'adminbar-search'",
",",
"$",
"text",
")",
";",
"}",
"$",
"search",
"->",
"submit",
"(",
")",
";",
"}"
] | Searches for the given text using the toolbar search field.
@param string $text Text to enter into the search field
@throws \Behat\Mink\Exception\ExpectationException | [
"Searches",
"for",
"the",
"given",
"text",
"using",
"the",
"toolbar",
"search",
"field",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/Toolbar.php#L149-L170 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/Toolbar.php | Toolbar.logOut | public function logOut()
{
/*
* Using NodeElement::mouseOver() won't work because WordPress is using hoverIndent.
* Instead we just manually add the hover class.
*
* See https://github.com/paulgibbs/behat-wordpress-extension/issues/65
*/
try {
$element_exists = $this->getSession()->evaluateScript(
'return document.getElementById("wp-admin-bar-my-account");'
);
if ($element_exists !== null) {
$this->getSession()->executeScript(
'document.getElementById("wp-admin-bar-my-account").classList.add("hover");'
);
$this->find('css', '#wp-admin-bar-logout a')->click();
}
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
$this->find('css', '#wp-admin-bar-logout a')->click();
}
} | php | public function logOut()
{
/*
* Using NodeElement::mouseOver() won't work because WordPress is using hoverIndent.
* Instead we just manually add the hover class.
*
* See https://github.com/paulgibbs/behat-wordpress-extension/issues/65
*/
try {
$element_exists = $this->getSession()->evaluateScript(
'return document.getElementById("wp-admin-bar-my-account");'
);
if ($element_exists !== null) {
$this->getSession()->executeScript(
'document.getElementById("wp-admin-bar-my-account").classList.add("hover");'
);
$this->find('css', '#wp-admin-bar-logout a')->click();
}
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
$this->find('css', '#wp-admin-bar-logout a')->click();
}
} | [
"public",
"function",
"logOut",
"(",
")",
"{",
"/*\n * Using NodeElement::mouseOver() won't work because WordPress is using hoverIndent.\n * Instead we just manually add the hover class.\n *\n * See https://github.com/paulgibbs/behat-wordpress-extension/issues/65\n */",
"try",
"{",
"$",
"element_exists",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"evaluateScript",
"(",
"'return document.getElementById(\"wp-admin-bar-my-account\");'",
")",
";",
"if",
"(",
"$",
"element_exists",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"executeScript",
"(",
"'document.getElementById(\"wp-admin-bar-my-account\").classList.add(\"hover\");'",
")",
";",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'#wp-admin-bar-logout a'",
")",
"->",
"click",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'#wp-admin-bar-logout a'",
")",
"->",
"click",
"(",
")",
";",
"}",
"}"
] | Logs-out using the toolbar log-out link. | [
"Logs",
"-",
"out",
"using",
"the",
"toolbar",
"log",
"-",
"out",
"link",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/Toolbar.php#L185-L209 |
paulgibbs/behat-wordpress-extension | src/PageObject/LoginPage.php | LoginPage.verifyLoginPage | protected function verifyLoginPage()
{
// Get the session.
$session = $this->verifySession();
// Get the url.
$url = $session->getCurrentUrl();
// If the login path isn't in the current URL.
if (false === strrpos($url, $this->path)) {
// We aren't on the login screen.
throw new ExpectationException(
sprintf(
'Expected screen is the wp-login form, instead on "%1$s".',
$url
),
$this->getDriver()
);
}
// Get the page.
$page = $session->getPage();
// Login form CSS selector
$login_form_selector = '#loginform';
// Search for the login form exists.
$login_form = $page->find('css', $login_form_selector);
// If the login form was not found.
if (null === $login_form) {
// We aren't on the login screen.
throw new ExpectationException(
sprintf(
'Expected to find the login form with the selector "%1$s" at the current URL "%2$s".',
$login_form_selector,
$url
),
$this->getDriver()
);
}
} | php | protected function verifyLoginPage()
{
// Get the session.
$session = $this->verifySession();
// Get the url.
$url = $session->getCurrentUrl();
// If the login path isn't in the current URL.
if (false === strrpos($url, $this->path)) {
// We aren't on the login screen.
throw new ExpectationException(
sprintf(
'Expected screen is the wp-login form, instead on "%1$s".',
$url
),
$this->getDriver()
);
}
// Get the page.
$page = $session->getPage();
// Login form CSS selector
$login_form_selector = '#loginform';
// Search for the login form exists.
$login_form = $page->find('css', $login_form_selector);
// If the login form was not found.
if (null === $login_form) {
// We aren't on the login screen.
throw new ExpectationException(
sprintf(
'Expected to find the login form with the selector "%1$s" at the current URL "%2$s".',
$login_form_selector,
$url
),
$this->getDriver()
);
}
} | [
"protected",
"function",
"verifyLoginPage",
"(",
")",
"{",
"// Get the session.",
"$",
"session",
"=",
"$",
"this",
"->",
"verifySession",
"(",
")",
";",
"// Get the url.",
"$",
"url",
"=",
"$",
"session",
"->",
"getCurrentUrl",
"(",
")",
";",
"// If the login path isn't in the current URL.",
"if",
"(",
"false",
"===",
"strrpos",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"path",
")",
")",
"{",
"// We aren't on the login screen.",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'Expected screen is the wp-login form, instead on \"%1$s\".'",
",",
"$",
"url",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"// Get the page.",
"$",
"page",
"=",
"$",
"session",
"->",
"getPage",
"(",
")",
";",
"// Login form CSS selector",
"$",
"login_form_selector",
"=",
"'#loginform'",
";",
"// Search for the login form exists.",
"$",
"login_form",
"=",
"$",
"page",
"->",
"find",
"(",
"'css'",
",",
"$",
"login_form_selector",
")",
";",
"// If the login form was not found.",
"if",
"(",
"null",
"===",
"$",
"login_form",
")",
"{",
"// We aren't on the login screen.",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'Expected to find the login form with the selector \"%1$s\" at the current URL \"%2$s\".'",
",",
"$",
"login_form_selector",
",",
"$",
"url",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"}"
] | Asserts the current screen is the login page.
@throws ExpectationException | [
"Asserts",
"the",
"current",
"screen",
"is",
"the",
"login",
"page",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/LoginPage.php#L29-L71 |
paulgibbs/behat-wordpress-extension | src/PageObject/LoginPage.php | LoginPage.setUserName | public function setUserName(string $username)
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the user_login field.
$user_login_field = $page->find('css', '#user_login');
// Try to focus the user_login field.
try {
$user_login_field->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Set the value of $username in the user_login field.
$user_login_field->setValue($username);
// The field can be stubborn, so we use fillField also.
$page->fillField('user_login', $username);
// Attempt to fill the user_login field with JavaScript.
try {
$session->executeScript(
"document.getElementById('user_login').value='$username'"
);
} catch (UnsupportedDriverActionException $e) {
// This will fail for drivers without JavaScript support
}
// Get the actual value of the user_login field.
$username_actual = $user_login_field->getValue();
// Verify the username was filled in correctly.
if ($username_actual !== $username) {
throw new ExpectationException(
sprintf(
'Expected the username field to be "%1$s", found "%2$s".',
$username,
$$username_actual
),
$this->getDriver()
);
}
} | php | public function setUserName(string $username)
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the user_login field.
$user_login_field = $page->find('css', '#user_login');
// Try to focus the user_login field.
try {
$user_login_field->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Set the value of $username in the user_login field.
$user_login_field->setValue($username);
// The field can be stubborn, so we use fillField also.
$page->fillField('user_login', $username);
// Attempt to fill the user_login field with JavaScript.
try {
$session->executeScript(
"document.getElementById('user_login').value='$username'"
);
} catch (UnsupportedDriverActionException $e) {
// This will fail for drivers without JavaScript support
}
// Get the actual value of the user_login field.
$username_actual = $user_login_field->getValue();
// Verify the username was filled in correctly.
if ($username_actual !== $username) {
throw new ExpectationException(
sprintf(
'Expected the username field to be "%1$s", found "%2$s".',
$username,
$$username_actual
),
$this->getDriver()
);
}
} | [
"public",
"function",
"setUserName",
"(",
"string",
"$",
"username",
")",
"{",
"// Get the session.",
"$",
"session",
"=",
"$",
"this",
"->",
"verifySession",
"(",
")",
";",
"// Verify we are on the login page.",
"$",
"this",
"->",
"verifyLoginPage",
"(",
")",
";",
"// Get the page.",
"$",
"page",
"=",
"$",
"session",
"->",
"getPage",
"(",
")",
";",
"// Find the user_login field.",
"$",
"user_login_field",
"=",
"$",
"page",
"->",
"find",
"(",
"'css'",
",",
"'#user_login'",
")",
";",
"// Try to focus the user_login field.",
"try",
"{",
"$",
"user_login_field",
"->",
"focus",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"}",
"// Set the value of $username in the user_login field.",
"$",
"user_login_field",
"->",
"setValue",
"(",
"$",
"username",
")",
";",
"// The field can be stubborn, so we use fillField also.",
"$",
"page",
"->",
"fillField",
"(",
"'user_login'",
",",
"$",
"username",
")",
";",
"// Attempt to fill the user_login field with JavaScript.",
"try",
"{",
"$",
"session",
"->",
"executeScript",
"(",
"\"document.getElementById('user_login').value='$username'\"",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for drivers without JavaScript support",
"}",
"// Get the actual value of the user_login field.",
"$",
"username_actual",
"=",
"$",
"user_login_field",
"->",
"getValue",
"(",
")",
";",
"// Verify the username was filled in correctly.",
"if",
"(",
"$",
"username_actual",
"!==",
"$",
"username",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'Expected the username field to be \"%1$s\", found \"%2$s\".'",
",",
"$",
"username",
",",
"$",
"$",
"username_actual",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"}"
] | Fills the user_login field of the login form with a given username.
@param string $username the username to fill into the login form
@throws \Behat\Mink\Exception\ExpectationException | [
"Fills",
"the",
"user_login",
"field",
"of",
"the",
"login",
"form",
"with",
"a",
"given",
"username",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/LoginPage.php#L80-L130 |
paulgibbs/behat-wordpress-extension | src/PageObject/LoginPage.php | LoginPage.setUserPassword | public function setUserPassword(string $password)
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the user_pass field.
$user_pass_field = $page->find('css', '#user_pass');
// Try to focus the user_pass field.
try {
$user_pass_field->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Set the value of $password in the user_pass field.
$user_pass_field->setValue($password);
// The field can be stubborn, so we use fillField also.
$page->fillField('user_pass', $password);
// Attempt to fill the user_pass field with JavaScript.
try {
$session->executeScript(
"document.getElementById('user_pass').value='$password'"
);
} catch (UnsupportedDriverActionException $e) {
// This will fail for drivers without JavaScript support
}
// Get the actual value of the user_pass field.
$password_actual = $user_pass_field->getValue();
// Verify the password was filled in correctly.
if ($password_actual !== $password) {
throw new ExpectationException(
sprintf(
'Expected the password field to be "%1$s", found "%2$s".',
$password,
$$password_actual
),
$this->getDriver()
);
}
} | php | public function setUserPassword(string $password)
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the user_pass field.
$user_pass_field = $page->find('css', '#user_pass');
// Try to focus the user_pass field.
try {
$user_pass_field->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Set the value of $password in the user_pass field.
$user_pass_field->setValue($password);
// The field can be stubborn, so we use fillField also.
$page->fillField('user_pass', $password);
// Attempt to fill the user_pass field with JavaScript.
try {
$session->executeScript(
"document.getElementById('user_pass').value='$password'"
);
} catch (UnsupportedDriverActionException $e) {
// This will fail for drivers without JavaScript support
}
// Get the actual value of the user_pass field.
$password_actual = $user_pass_field->getValue();
// Verify the password was filled in correctly.
if ($password_actual !== $password) {
throw new ExpectationException(
sprintf(
'Expected the password field to be "%1$s", found "%2$s".',
$password,
$$password_actual
),
$this->getDriver()
);
}
} | [
"public",
"function",
"setUserPassword",
"(",
"string",
"$",
"password",
")",
"{",
"// Get the session.",
"$",
"session",
"=",
"$",
"this",
"->",
"verifySession",
"(",
")",
";",
"// Verify we are on the login page.",
"$",
"this",
"->",
"verifyLoginPage",
"(",
")",
";",
"// Get the page.",
"$",
"page",
"=",
"$",
"session",
"->",
"getPage",
"(",
")",
";",
"// Find the user_pass field.",
"$",
"user_pass_field",
"=",
"$",
"page",
"->",
"find",
"(",
"'css'",
",",
"'#user_pass'",
")",
";",
"// Try to focus the user_pass field.",
"try",
"{",
"$",
"user_pass_field",
"->",
"focus",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"}",
"// Set the value of $password in the user_pass field.",
"$",
"user_pass_field",
"->",
"setValue",
"(",
"$",
"password",
")",
";",
"// The field can be stubborn, so we use fillField also.",
"$",
"page",
"->",
"fillField",
"(",
"'user_pass'",
",",
"$",
"password",
")",
";",
"// Attempt to fill the user_pass field with JavaScript.",
"try",
"{",
"$",
"session",
"->",
"executeScript",
"(",
"\"document.getElementById('user_pass').value='$password'\"",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for drivers without JavaScript support",
"}",
"// Get the actual value of the user_pass field.",
"$",
"password_actual",
"=",
"$",
"user_pass_field",
"->",
"getValue",
"(",
")",
";",
"// Verify the password was filled in correctly.",
"if",
"(",
"$",
"password_actual",
"!==",
"$",
"password",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'Expected the password field to be \"%1$s\", found \"%2$s\".'",
",",
"$",
"password",
",",
"$",
"$",
"password_actual",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"}"
] | Fills the user_pass field of the login form with a given password.
@param string $password the password to fill into the login form
@throws \Behat\Mink\Exception\ExpectationException | [
"Fills",
"the",
"user_pass",
"field",
"of",
"the",
"login",
"form",
"with",
"a",
"given",
"password",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/LoginPage.php#L139-L189 |
paulgibbs/behat-wordpress-extension | src/PageObject/LoginPage.php | LoginPage.submitLoginForm | public function submitLoginForm()
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the submit button.
$submit_button = $page->find('css', '#wp-submit');
// Try to focus the submit button.
try {
$submit_button->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Click the submit button.
$submit_button->click();
} | php | public function submitLoginForm()
{
// Get the session.
$session = $this->verifySession();
// Verify we are on the login page.
$this->verifyLoginPage();
// Get the page.
$page = $session->getPage();
// Find the submit button.
$submit_button = $page->find('css', '#wp-submit');
// Try to focus the submit button.
try {
$submit_button->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
// Click the submit button.
$submit_button->click();
} | [
"public",
"function",
"submitLoginForm",
"(",
")",
"{",
"// Get the session.",
"$",
"session",
"=",
"$",
"this",
"->",
"verifySession",
"(",
")",
";",
"// Verify we are on the login page.",
"$",
"this",
"->",
"verifyLoginPage",
"(",
")",
";",
"// Get the page.",
"$",
"page",
"=",
"$",
"session",
"->",
"getPage",
"(",
")",
";",
"// Find the submit button.",
"$",
"submit_button",
"=",
"$",
"page",
"->",
"find",
"(",
"'css'",
",",
"'#wp-submit'",
")",
";",
"// Try to focus the submit button.",
"try",
"{",
"$",
"submit_button",
"->",
"focus",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"}",
"// Click the submit button.",
"$",
"submit_button",
"->",
"click",
"(",
")",
";",
"}"
] | Submit the WordPress login form | [
"Submit",
"the",
"WordPress",
"login",
"form"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/LoginPage.php#L194-L218 |
paulgibbs/behat-wordpress-extension | src/PageObject/LoginPage.php | LoginPage.verifySession | protected function verifySession()
{
// Get the session.
$session = $this->getSession();
// Start the session if needed.
if (! $session->isStarted()) {
$session->start();
}
// If we aren't on a valid page
if ('about:blank' === $session->getCurrentUrl()) {
// Go to the home page
$session->visit('/');
}
// Return the session.
return $session;
} | php | protected function verifySession()
{
// Get the session.
$session = $this->getSession();
// Start the session if needed.
if (! $session->isStarted()) {
$session->start();
}
// If we aren't on a valid page
if ('about:blank' === $session->getCurrentUrl()) {
// Go to the home page
$session->visit('/');
}
// Return the session.
return $session;
} | [
"protected",
"function",
"verifySession",
"(",
")",
"{",
"// Get the session.",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"// Start the session if needed.",
"if",
"(",
"!",
"$",
"session",
"->",
"isStarted",
"(",
")",
")",
"{",
"$",
"session",
"->",
"start",
"(",
")",
";",
"}",
"// If we aren't on a valid page",
"if",
"(",
"'about:blank'",
"===",
"$",
"session",
"->",
"getCurrentUrl",
"(",
")",
")",
"{",
"// Go to the home page",
"$",
"session",
"->",
"visit",
"(",
"'/'",
")",
";",
"}",
"// Return the session.",
"return",
"$",
"session",
";",
"}"
] | Verify and return a properly started Mink session
@return \Behat\Mink\Session Mink session. | [
"Verify",
"and",
"return",
"a",
"properly",
"started",
"Mink",
"session"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/LoginPage.php#L225-L243 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/AdminMenu.php | AdminMenu.clickMenuItem | public function clickMenuItem(string $item)
{
$click_node = false;
$first_level_items = $this->findAll('css', 'li.menu-top');
$items = array_map('trim', preg_split('/(?<!\\\\)>/', $item));
foreach ($first_level_items as $first_level_item) {
/*
* We use getHtml and strip the tags, as `.wp-menu-name` might not be visible (i.e. when the menu is
* collapsed) so getText() will be empty.
*
* See https://github.com/stephenharris/WordPressBehatExtension/issues/2
*/
$item_name = Util\stripTagsAndContent($first_level_item->find('css', '.wp-menu-name')->getHtml());
if (strtolower($items[0]) !== strtolower($item_name)) {
continue;
}
if (isset($items[1])) {
$second_level_items = $first_level_item->findAll('css', 'ul li a');
foreach ($second_level_items as $second_level_item) {
$item_name = Util\stripTagsAndContent($second_level_item->getHtml());
if (strtolower($items[1]) !== strtolower($item_name)) {
continue;
}
try {
// Focus on the menu link so the submenu appears.
$first_level_item->find('css', 'a.menu-top')->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
$click_node = $second_level_item;
break;
}
} else {
// We are clicking a top-level item.
$click_node = $first_level_item->find('css', 'a');
}
break;
}
if (false === $click_node) {
throw new RuntimeException('[W405] Menu item could not be found');
}
$click_node->click();
} | php | public function clickMenuItem(string $item)
{
$click_node = false;
$first_level_items = $this->findAll('css', 'li.menu-top');
$items = array_map('trim', preg_split('/(?<!\\\\)>/', $item));
foreach ($first_level_items as $first_level_item) {
/*
* We use getHtml and strip the tags, as `.wp-menu-name` might not be visible (i.e. when the menu is
* collapsed) so getText() will be empty.
*
* See https://github.com/stephenharris/WordPressBehatExtension/issues/2
*/
$item_name = Util\stripTagsAndContent($first_level_item->find('css', '.wp-menu-name')->getHtml());
if (strtolower($items[0]) !== strtolower($item_name)) {
continue;
}
if (isset($items[1])) {
$second_level_items = $first_level_item->findAll('css', 'ul li a');
foreach ($second_level_items as $second_level_item) {
$item_name = Util\stripTagsAndContent($second_level_item->getHtml());
if (strtolower($items[1]) !== strtolower($item_name)) {
continue;
}
try {
// Focus on the menu link so the submenu appears.
$first_level_item->find('css', 'a.menu-top')->focus();
} catch (UnsupportedDriverActionException $e) {
// This will fail for GoutteDriver but neither is it necessary.
}
$click_node = $second_level_item;
break;
}
} else {
// We are clicking a top-level item.
$click_node = $first_level_item->find('css', 'a');
}
break;
}
if (false === $click_node) {
throw new RuntimeException('[W405] Menu item could not be found');
}
$click_node->click();
} | [
"public",
"function",
"clickMenuItem",
"(",
"string",
"$",
"item",
")",
"{",
"$",
"click_node",
"=",
"false",
";",
"$",
"first_level_items",
"=",
"$",
"this",
"->",
"findAll",
"(",
"'css'",
",",
"'li.menu-top'",
")",
";",
"$",
"items",
"=",
"array_map",
"(",
"'trim'",
",",
"preg_split",
"(",
"'/(?<!\\\\\\\\)>/'",
",",
"$",
"item",
")",
")",
";",
"foreach",
"(",
"$",
"first_level_items",
"as",
"$",
"first_level_item",
")",
"{",
"/*\n * We use getHtml and strip the tags, as `.wp-menu-name` might not be visible (i.e. when the menu is\n * collapsed) so getText() will be empty.\n *\n * See https://github.com/stephenharris/WordPressBehatExtension/issues/2\n */",
"$",
"item_name",
"=",
"Util",
"\\",
"stripTagsAndContent",
"(",
"$",
"first_level_item",
"->",
"find",
"(",
"'css'",
",",
"'.wp-menu-name'",
")",
"->",
"getHtml",
"(",
")",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"items",
"[",
"0",
"]",
")",
"!==",
"strtolower",
"(",
"$",
"item_name",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"items",
"[",
"1",
"]",
")",
")",
"{",
"$",
"second_level_items",
"=",
"$",
"first_level_item",
"->",
"findAll",
"(",
"'css'",
",",
"'ul li a'",
")",
";",
"foreach",
"(",
"$",
"second_level_items",
"as",
"$",
"second_level_item",
")",
"{",
"$",
"item_name",
"=",
"Util",
"\\",
"stripTagsAndContent",
"(",
"$",
"second_level_item",
"->",
"getHtml",
"(",
")",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"items",
"[",
"1",
"]",
")",
"!==",
"strtolower",
"(",
"$",
"item_name",
")",
")",
"{",
"continue",
";",
"}",
"try",
"{",
"// Focus on the menu link so the submenu appears.",
"$",
"first_level_item",
"->",
"find",
"(",
"'css'",
",",
"'a.menu-top'",
")",
"->",
"focus",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedDriverActionException",
"$",
"e",
")",
"{",
"// This will fail for GoutteDriver but neither is it necessary.",
"}",
"$",
"click_node",
"=",
"$",
"second_level_item",
";",
"break",
";",
"}",
"}",
"else",
"{",
"// We are clicking a top-level item.",
"$",
"click_node",
"=",
"$",
"first_level_item",
"->",
"find",
"(",
"'css'",
",",
"'a'",
")",
";",
"}",
"break",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"click_node",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'[W405] Menu item could not be found'",
")",
";",
"}",
"$",
"click_node",
"->",
"click",
"(",
")",
";",
"}"
] | Click a specific item in the admin menu.
Top-level items are identified by their link text (e.g. 'Comments').
Second-level items are identified by their parent text and link text,
delimited by a right angle bracket. E.g. Posts > Add New.
@param string $item The menu item to click.
@throws \RuntimeException If the menu item does not exist | [
"Click",
"a",
"specific",
"item",
"in",
"the",
"admin",
"menu",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/AdminMenu.php#L31-L82 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/ContentElement.php | ContentElement.create | public function create($args)
{
$args = wp_slash($args);
$id = wp_insert_post($args);
if (is_wp_error($id)) {
throw new UnexpectedValueException(sprintf('[W603] Failed creating new content: %s', $id->get_error_message()));
}
return $this->get($id);
} | php | public function create($args)
{
$args = wp_slash($args);
$id = wp_insert_post($args);
if (is_wp_error($id)) {
throw new UnexpectedValueException(sprintf('[W603] Failed creating new content: %s', $id->get_error_message()));
}
return $this->get($id);
} | [
"public",
"function",
"create",
"(",
"$",
"args",
")",
"{",
"$",
"args",
"=",
"wp_slash",
"(",
"$",
"args",
")",
";",
"$",
"id",
"=",
"wp_insert_post",
"(",
"$",
"args",
")",
";",
"if",
"(",
"is_wp_error",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W603] Failed creating new content: %s'",
",",
"$",
"id",
"->",
"get_error_message",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}"
] | Create an item for this element.
@param array $args Data used to create an object.
@throws \UnexpectedValueException
@return \WP_Post The new item. | [
"Create",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/ContentElement.php#L23-L33 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/ContentElement.php | ContentElement.get | public function get($id, $args = [])
{
$post = false;
if (is_numeric($id) || (is_object($id) && $id instanceof \WP_Post)) {
$post = get_post($id);
} else {
$query = new WP_Query();
$query = $query->query(array(
"{$args['by']}" => $id,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'posts_per_page' => 1,
'suppress_filters' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
));
if ($query) {
$post = $query[0];
}
}
if (! $post) {
throw new UnexpectedValueException(sprintf('[W604] Could not find content with ID %d', $id));
}
$post->url = get_permalink($post);
return $post;
} | php | public function get($id, $args = [])
{
$post = false;
if (is_numeric($id) || (is_object($id) && $id instanceof \WP_Post)) {
$post = get_post($id);
} else {
$query = new WP_Query();
$query = $query->query(array(
"{$args['by']}" => $id,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'posts_per_page' => 1,
'suppress_filters' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
));
if ($query) {
$post = $query[0];
}
}
if (! $post) {
throw new UnexpectedValueException(sprintf('[W604] Could not find content with ID %d', $id));
}
$post->url = get_permalink($post);
return $post;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"post",
"=",
"false",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"id",
")",
"||",
"(",
"is_object",
"(",
"$",
"id",
")",
"&&",
"$",
"id",
"instanceof",
"\\",
"WP_Post",
")",
")",
"{",
"$",
"post",
"=",
"get_post",
"(",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"new",
"WP_Query",
"(",
")",
";",
"$",
"query",
"=",
"$",
"query",
"->",
"query",
"(",
"array",
"(",
"\"{$args['by']}\"",
"=>",
"$",
"id",
",",
"'ignore_sticky_posts'",
"=>",
"true",
",",
"'no_found_rows'",
"=>",
"true",
",",
"'posts_per_page'",
"=>",
"1",
",",
"'suppress_filters'",
"=>",
"false",
",",
"'update_post_meta_cache'",
"=>",
"false",
",",
"'update_post_term_cache'",
"=>",
"false",
",",
")",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"post",
"=",
"$",
"query",
"[",
"0",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W604] Could not find content with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"post",
"->",
"url",
"=",
"get_permalink",
"(",
"$",
"post",
")",
";",
"return",
"$",
"post",
";",
"}"
] | Retrieve an item for this element.
@param \WP_Post|string|int $id Object ID.
@param array $args Optional data used to fetch an object.
@throws \UnexpectedValueException
@return \WP_Post The item. | [
"Retrieve",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/ContentElement.php#L45-L75 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/ContentElement.php | ContentElement.delete | public function delete($id, $args = [])
{
$result = wp_delete_post($id, isset($args['force']));
if (! $result) {
throw new UnexpectedValueException('[W605] Failed deleting content.');
}
} | php | public function delete($id, $args = [])
{
$result = wp_delete_post($id, isset($args['force']));
if (! $result) {
throw new UnexpectedValueException('[W605] Failed deleting content.');
}
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"wp_delete_post",
"(",
"$",
"id",
",",
"isset",
"(",
"$",
"args",
"[",
"'force'",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'[W605] Failed deleting content.'",
")",
";",
"}",
"}"
] | Delete an item for this element.
@param int $id Object ID.
@param array $args Optional data used to delete an object.
@throws \UnexpectedValueException | [
"Delete",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/ContentElement.php#L85-L92 |
paulgibbs/behat-wordpress-extension | src/WordpressDriverManager.php | WordpressDriverManager.registerDriverElement | public function registerDriverElement(string $name, ElementInterface $element, string $driver_name)
{
$this->getDriver($driver_name, 'skip bootstrap')->registerElement($name, $element);
} | php | public function registerDriverElement(string $name, ElementInterface $element, string $driver_name)
{
$this->getDriver($driver_name, 'skip bootstrap')->registerElement($name, $element);
} | [
"public",
"function",
"registerDriverElement",
"(",
"string",
"$",
"name",
",",
"ElementInterface",
"$",
"element",
",",
"string",
"$",
"driver_name",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
"$",
"driver_name",
",",
"'skip bootstrap'",
")",
"->",
"registerElement",
"(",
"$",
"name",
",",
"$",
"element",
")",
";",
"}"
] | Register a new driver element.
@since 1.1.0 Added $driver_name parameter.
@param string $name Element name.
@param ElementInterface $element An instance of a ElementInterface.
@param string $driver_name Driver name. | [
"Register",
"a",
"new",
"driver",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/WordpressDriverManager.php#L73-L76 |
paulgibbs/behat-wordpress-extension | src/WordpressDriverManager.php | WordpressDriverManager.getDriver | public function getDriver(string $name = '', string $bootstrap = 'do bootstrap'): DriverInterface
{
$do_bootstrap = ($bootstrap === 'do bootstrap');
$name = $name ? strtolower($name) : $this->default_driver;
if (! isset($this->drivers[$name])) {
throw new InvalidArgumentException("[W002] Driver '{$name}' is not registered.");
}
$driver = $this->drivers[$name];
// Bootstrap driver if needed.
if ($do_bootstrap && ! $driver->isBootstrapped()) {
$driver->bootstrap();
}
return $driver;
} | php | public function getDriver(string $name = '', string $bootstrap = 'do bootstrap'): DriverInterface
{
$do_bootstrap = ($bootstrap === 'do bootstrap');
$name = $name ? strtolower($name) : $this->default_driver;
if (! isset($this->drivers[$name])) {
throw new InvalidArgumentException("[W002] Driver '{$name}' is not registered.");
}
$driver = $this->drivers[$name];
// Bootstrap driver if needed.
if ($do_bootstrap && ! $driver->isBootstrapped()) {
$driver->bootstrap();
}
return $driver;
} | [
"public",
"function",
"getDriver",
"(",
"string",
"$",
"name",
"=",
"''",
",",
"string",
"$",
"bootstrap",
"=",
"'do bootstrap'",
")",
":",
"DriverInterface",
"{",
"$",
"do_bootstrap",
"=",
"(",
"$",
"bootstrap",
"===",
"'do bootstrap'",
")",
";",
"$",
"name",
"=",
"$",
"name",
"?",
"strtolower",
"(",
"$",
"name",
")",
":",
"$",
"this",
"->",
"default_driver",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"[W002] Driver '{$name}' is not registered.\"",
")",
";",
"}",
"$",
"driver",
"=",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
";",
"// Bootstrap driver if needed.",
"if",
"(",
"$",
"do_bootstrap",
"&&",
"!",
"$",
"driver",
"->",
"isBootstrapped",
"(",
")",
")",
"{",
"$",
"driver",
"->",
"bootstrap",
"(",
")",
";",
"}",
"return",
"$",
"driver",
";",
"}"
] | Return a registered driver by name (defaults to the default driver).
@since 1.1.0 Added $bootstrap parameter.
@param string $name Optional. The name of the driver to return. If omitted, the default driver is returned.
@param string $bootstrap Optional. If "skip bootstrap", driver bootstrap is skipped. Default: "do bootstrap".
@return DriverInterface The requested driver.
@throws \InvalidArgumentException | [
"Return",
"a",
"registered",
"driver",
"by",
"name",
"(",
"defaults",
"to",
"the",
"default",
"driver",
")",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/WordpressDriverManager.php#L90-L107 |
paulgibbs/behat-wordpress-extension | src/WordpressDriverManager.php | WordpressDriverManager.setDefaultDriverName | public function setDefaultDriverName($name)
{
$name = strtolower($name);
if (! isset($this->drivers[$name])) {
throw new InvalidArgumentException("[W002] Driver '{$name}' is not registered.");
}
$this->default_driver = $name;
} | php | public function setDefaultDriverName($name)
{
$name = strtolower($name);
if (! isset($this->drivers[$name])) {
throw new InvalidArgumentException("[W002] Driver '{$name}' is not registered.");
}
$this->default_driver = $name;
} | [
"public",
"function",
"setDefaultDriverName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"[W002] Driver '{$name}' is not registered.\"",
")",
";",
"}",
"$",
"this",
"->",
"default_driver",
"=",
"$",
"name",
";",
"}"
] | Set the default driver name.
@param string $name Default driver name to set.
@throws \InvalidArgumentException | [
"Set",
"the",
"default",
"driver",
"name",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/WordpressDriverManager.php#L126-L135 |
paulgibbs/behat-wordpress-extension | src/WordpressDriverManager.php | WordpressDriverManager.getSetting | public function getSetting($name)
{
return ! empty($this->settings[$name]) ? $this->settings[$name] : null;
} | php | public function getSetting($name)
{
return ! empty($this->settings[$name]) ? $this->settings[$name] : null;
} | [
"public",
"function",
"getSetting",
"(",
"$",
"name",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"settings",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Return the value of an internal setting.
Internal use only.
This value persists across Contexts, unlike getWordpressParameter().
@param string $name Setting name.
@return mixed | [
"Return",
"the",
"value",
"of",
"an",
"internal",
"setting",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/WordpressDriverManager.php#L147-L150 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.logIn | public function logIn(string $username, string $password, string $redirect_to = '/')
{
if ($this->loggedIn()) {
$this->logOut();
}
// Start a session.
$session = $this->getSession();
// Go to the login form.
$this->visitPath('wp-login.php?redirect_to=' . urlencode($this->locatePath($redirect_to)));
// Fill in username.
$this->login_page->setUserName($username);
// Fill in password.
$this->login_page->setUserPassword($password);
// Submit the login form.
$this->login_page->submitLoginForm();
if (! $this->loggedIn()) {
throw new ExpectationException('[W803] The user could not be logged-in.', $this->getSession()->getDriver());
}
} | php | public function logIn(string $username, string $password, string $redirect_to = '/')
{
if ($this->loggedIn()) {
$this->logOut();
}
// Start a session.
$session = $this->getSession();
// Go to the login form.
$this->visitPath('wp-login.php?redirect_to=' . urlencode($this->locatePath($redirect_to)));
// Fill in username.
$this->login_page->setUserName($username);
// Fill in password.
$this->login_page->setUserPassword($password);
// Submit the login form.
$this->login_page->submitLoginForm();
if (! $this->loggedIn()) {
throw new ExpectationException('[W803] The user could not be logged-in.', $this->getSession()->getDriver());
}
} | [
"public",
"function",
"logIn",
"(",
"string",
"$",
"username",
",",
"string",
"$",
"password",
",",
"string",
"$",
"redirect_to",
"=",
"'/'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loggedIn",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logOut",
"(",
")",
";",
"}",
"// Start a session.",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"// Go to the login form.",
"$",
"this",
"->",
"visitPath",
"(",
"'wp-login.php?redirect_to='",
".",
"urlencode",
"(",
"$",
"this",
"->",
"locatePath",
"(",
"$",
"redirect_to",
")",
")",
")",
";",
"// Fill in username.",
"$",
"this",
"->",
"login_page",
"->",
"setUserName",
"(",
"$",
"username",
")",
";",
"// Fill in password.",
"$",
"this",
"->",
"login_page",
"->",
"setUserPassword",
"(",
"$",
"password",
")",
";",
"// Submit the login form.",
"$",
"this",
"->",
"login_page",
"->",
"submitLoginForm",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"loggedIn",
"(",
")",
")",
"{",
"throw",
"new",
"ExpectationException",
"(",
"'[W803] The user could not be logged-in.'",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"}"
] | Log in the user.
@param string $username
@param string $password
@param string $redirect_to Optional. After succesful log in, redirect browser to this path. Default = "/".
@throws ExpectationException | [
"Log",
"in",
"the",
"user",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L45-L69 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.loggedIn | public function loggedIn(): bool
{
$session = $this->getSession();
if (! $session->isStarted()) {
$session->start();
// If there isn't a session started the user can't be logged in.
return false;
}
$page = $session->getPage();
// Look for a selector to determine if the user is logged in.
try {
// Search for the body element.
$body_element = $page->find('css', 'body');
// If the page doesn't have a body element the user is not logged in.
if (null === $body_element) {
return false;
}
// The user is logged in if:
$is_logged_in = (
// The body has a logged-in class (front-end).
$body_element->hasClass('logged-in') ||
// The body has a wp-admin class (dashboard)
$body_element->hasClass('wp-admin')
);
return $is_logged_in;
} catch (DriverException $e) {
// This may fail if the user has not loaded any site yet.
}
return false;
} | php | public function loggedIn(): bool
{
$session = $this->getSession();
if (! $session->isStarted()) {
$session->start();
// If there isn't a session started the user can't be logged in.
return false;
}
$page = $session->getPage();
// Look for a selector to determine if the user is logged in.
try {
// Search for the body element.
$body_element = $page->find('css', 'body');
// If the page doesn't have a body element the user is not logged in.
if (null === $body_element) {
return false;
}
// The user is logged in if:
$is_logged_in = (
// The body has a logged-in class (front-end).
$body_element->hasClass('logged-in') ||
// The body has a wp-admin class (dashboard)
$body_element->hasClass('wp-admin')
);
return $is_logged_in;
} catch (DriverException $e) {
// This may fail if the user has not loaded any site yet.
}
return false;
} | [
"public",
"function",
"loggedIn",
"(",
")",
":",
"bool",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
";",
"if",
"(",
"!",
"$",
"session",
"->",
"isStarted",
"(",
")",
")",
"{",
"$",
"session",
"->",
"start",
"(",
")",
";",
"// If there isn't a session started the user can't be logged in.",
"return",
"false",
";",
"}",
"$",
"page",
"=",
"$",
"session",
"->",
"getPage",
"(",
")",
";",
"// Look for a selector to determine if the user is logged in.",
"try",
"{",
"// Search for the body element.",
"$",
"body_element",
"=",
"$",
"page",
"->",
"find",
"(",
"'css'",
",",
"'body'",
")",
";",
"// If the page doesn't have a body element the user is not logged in.",
"if",
"(",
"null",
"===",
"$",
"body_element",
")",
"{",
"return",
"false",
";",
"}",
"// The user is logged in if:",
"$",
"is_logged_in",
"=",
"(",
"// The body has a logged-in class (front-end).",
"$",
"body_element",
"->",
"hasClass",
"(",
"'logged-in'",
")",
"||",
"// The body has a wp-admin class (dashboard)",
"$",
"body_element",
"->",
"hasClass",
"(",
"'wp-admin'",
")",
")",
";",
"return",
"$",
"is_logged_in",
";",
"}",
"catch",
"(",
"DriverException",
"$",
"e",
")",
"{",
"// This may fail if the user has not loaded any site yet.",
"}",
"return",
"false",
";",
"}"
] | Determine if the current user is logged in or not.
@return bool | [
"Determine",
"if",
"the",
"current",
"user",
"is",
"logged",
"in",
"or",
"not",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L92-L126 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.createUser | public function createUser(string $user_login, string $user_email, array $args = []): array
{
$args['user_email'] = $user_email;
$args['user_login'] = $user_login;
try {
$user = $this->getDriver()->user->create($args);
} catch (UnexpectedValueException $exception) {
$user = $this->getExistingMatchingUser($args);
}
$return_array = array(
'id' => $user->ID,
'slug' => $user->user_nicename
);
return $return_array;
} | php | public function createUser(string $user_login, string $user_email, array $args = []): array
{
$args['user_email'] = $user_email;
$args['user_login'] = $user_login;
try {
$user = $this->getDriver()->user->create($args);
} catch (UnexpectedValueException $exception) {
$user = $this->getExistingMatchingUser($args);
}
$return_array = array(
'id' => $user->ID,
'slug' => $user->user_nicename
);
return $return_array;
} | [
"public",
"function",
"createUser",
"(",
"string",
"$",
"user_login",
",",
"string",
"$",
"user_email",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"args",
"[",
"'user_email'",
"]",
"=",
"$",
"user_email",
";",
"$",
"args",
"[",
"'user_login'",
"]",
"=",
"$",
"user_login",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"user",
"->",
"create",
"(",
"$",
"args",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"exception",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getExistingMatchingUser",
"(",
"$",
"args",
")",
";",
"}",
"$",
"return_array",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"user",
"->",
"ID",
",",
"'slug'",
"=>",
"$",
"user",
"->",
"user_nicename",
")",
";",
"return",
"$",
"return_array",
";",
"}"
] | Create a user.
If the user already exists, the existing user will be
compared with the user which was asked to be created. If all matches
no fault with be thrown. If it does not match then UnexpectedValueException
will be thrown.
@param string $user_login User login name.
@param string $user_email User email address.
@param array $args Optional. Extra parameters to pass to WordPress.
@return array {
@type int $id User ID.
@type string $slug User slug (nicename).
} | [
"Create",
"a",
"user",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L145-L162 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.getExistingMatchingUser | protected function getExistingMatchingUser(array $args)
{
$user_id = $this->getUserIdFromLogin($args['user_login']);
$user = $this->getDriver()->user->get($user_id);
/* users can have more than one role so needs to be a special case */
if (array_key_exists('role', $args)) {
$this->checkUserHasRole($user, $args['role']);
}
/*
* Loop through each of the passed arguements.
* if they are arguments which apply to users
* then check that that which exist matches that which was specified.
*/
foreach ($args as $parameter => $value) {
if ($parameter === 'password') {
continue;
}
if ($this->isValidUserParameter($parameter) && $user->$parameter !== $args[$parameter]) {
throw new UnexpectedValueException('[W804] User with login: ' . $user->user_login . 'exists, but ' . $parameter . ' is ' . $user->$parameter . ' not ' . $args[$parameter] . 'which was specified');
}
}
return $user;
} | php | protected function getExistingMatchingUser(array $args)
{
$user_id = $this->getUserIdFromLogin($args['user_login']);
$user = $this->getDriver()->user->get($user_id);
/* users can have more than one role so needs to be a special case */
if (array_key_exists('role', $args)) {
$this->checkUserHasRole($user, $args['role']);
}
/*
* Loop through each of the passed arguements.
* if they are arguments which apply to users
* then check that that which exist matches that which was specified.
*/
foreach ($args as $parameter => $value) {
if ($parameter === 'password') {
continue;
}
if ($this->isValidUserParameter($parameter) && $user->$parameter !== $args[$parameter]) {
throw new UnexpectedValueException('[W804] User with login: ' . $user->user_login . 'exists, but ' . $parameter . ' is ' . $user->$parameter . ' not ' . $args[$parameter] . 'which was specified');
}
}
return $user;
} | [
"protected",
"function",
"getExistingMatchingUser",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"user_id",
"=",
"$",
"this",
"->",
"getUserIdFromLogin",
"(",
"$",
"args",
"[",
"'user_login'",
"]",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"user",
"->",
"get",
"(",
"$",
"user_id",
")",
";",
"/* users can have more than one role so needs to be a special case */",
"if",
"(",
"array_key_exists",
"(",
"'role'",
",",
"$",
"args",
")",
")",
"{",
"$",
"this",
"->",
"checkUserHasRole",
"(",
"$",
"user",
",",
"$",
"args",
"[",
"'role'",
"]",
")",
";",
"}",
"/*\n * Loop through each of the passed arguements.\n * if they are arguments which apply to users\n * then check that that which exist matches that which was specified.\n */",
"foreach",
"(",
"$",
"args",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"parameter",
"===",
"'password'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isValidUserParameter",
"(",
"$",
"parameter",
")",
"&&",
"$",
"user",
"->",
"$",
"parameter",
"!==",
"$",
"args",
"[",
"$",
"parameter",
"]",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'[W804] User with login: '",
".",
"$",
"user",
"->",
"user_login",
".",
"'exists, but '",
".",
"$",
"parameter",
".",
"' is '",
".",
"$",
"user",
"->",
"$",
"parameter",
".",
"' not '",
".",
"$",
"args",
"[",
"$",
"parameter",
"]",
".",
"'which was specified'",
")",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Get a user which matches all parameters.
Fetches a user if all the passed parameters match
if none is found then UnexpectedValueException is thrown.
@param array $args Keyed array of parameters.
@throws \UnexpectedValueException
@return object $user | [
"Get",
"a",
"user",
"which",
"matches",
"all",
"parameters",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L176-L202 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.checkUserHasRole | protected function checkUserHasRole($user, string $role): bool
{
if (! in_array($role, $user->roles, true)) {
$message = sprintf(
'[W804] User with login: %s exists, but role %s is not in the list of applied roles: %s',
$user->user_login,
$role,
$user->roles
);
throw new \UnexpectedValueException($message);
}
return true;
} | php | protected function checkUserHasRole($user, string $role): bool
{
if (! in_array($role, $user->roles, true)) {
$message = sprintf(
'[W804] User with login: %s exists, but role %s is not in the list of applied roles: %s',
$user->user_login,
$role,
$user->roles
);
throw new \UnexpectedValueException($message);
}
return true;
} | [
"protected",
"function",
"checkUserHasRole",
"(",
"$",
"user",
",",
"string",
"$",
"role",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"role",
",",
"$",
"user",
"->",
"roles",
",",
"true",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'[W804] User with login: %s exists, but role %s is not in the list of applied roles: %s'",
",",
"$",
"user",
"->",
"user_login",
",",
"$",
"role",
",",
"$",
"user",
"->",
"roles",
")",
";",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"$",
"message",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Checks to see if the user has an assigned role or not.
@param object $user
@param string $role
@throws \UnexpectedValueException
@return boolean $retval True if the role does apply to the user. | [
"Checks",
"to",
"see",
"if",
"the",
"user",
"has",
"an",
"assigned",
"role",
"or",
"not",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L214-L227 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.isValidUserParameter | protected function isValidUserParameter(string $user_parameter): bool
{
$validUserParameters = array(
'id',
'user_login',
'display_name',
'user_email',
'user_registered',
'roles',
'user_nicename',
'user_url',
'user_activation_key',
'user_status',
'url'
);
return in_array(strtolower($user_parameter), $validUserParameters, true);
} | php | protected function isValidUserParameter(string $user_parameter): bool
{
$validUserParameters = array(
'id',
'user_login',
'display_name',
'user_email',
'user_registered',
'roles',
'user_nicename',
'user_url',
'user_activation_key',
'user_status',
'url'
);
return in_array(strtolower($user_parameter), $validUserParameters, true);
} | [
"protected",
"function",
"isValidUserParameter",
"(",
"string",
"$",
"user_parameter",
")",
":",
"bool",
"{",
"$",
"validUserParameters",
"=",
"array",
"(",
"'id'",
",",
"'user_login'",
",",
"'display_name'",
",",
"'user_email'",
",",
"'user_registered'",
",",
"'roles'",
",",
"'user_nicename'",
",",
"'user_url'",
",",
"'user_activation_key'",
",",
"'user_status'",
",",
"'url'",
")",
";",
"return",
"in_array",
"(",
"strtolower",
"(",
"$",
"user_parameter",
")",
",",
"$",
"validUserParameters",
",",
"true",
")",
";",
"}"
] | Checks to see if the passed in parameter applies to a user or not.
@param string $user_parameter the parameter to be checked.
@return boolean $retval True if the parameter does apply to a user. | [
"Checks",
"to",
"see",
"if",
"the",
"passed",
"in",
"parameter",
"applies",
"to",
"a",
"user",
"or",
"not",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L236-L252 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.getUserIdFromLogin | public function getUserIdFromLogin(string $username): int
{
return (int) $this->getDriver()->user->get($username, ['by' => 'login'])->ID;
} | php | public function getUserIdFromLogin(string $username): int
{
return (int) $this->getDriver()->user->get($username, ['by' => 'login'])->ID;
} | [
"public",
"function",
"getUserIdFromLogin",
"(",
"string",
"$",
"username",
")",
":",
"int",
"{",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"user",
"->",
"get",
"(",
"$",
"username",
",",
"[",
"'by'",
"=>",
"'login'",
"]",
")",
"->",
"ID",
";",
"}"
] | Get a user's ID from their username.
@param string $username The username of the user to get the ID of.
@return int ID of the user. | [
"Get",
"a",
"user",
"s",
"ID",
"from",
"their",
"username",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L261-L264 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.deleteUser | public function deleteUser(int $user_id, array $args = [])
{
$this->getDriver()->user->delete($user_id, $args);
} | php | public function deleteUser(int $user_id, array $args = [])
{
$this->getDriver()->user->delete($user_id, $args);
} | [
"public",
"function",
"deleteUser",
"(",
"int",
"$",
"user_id",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"user",
"->",
"delete",
"(",
"$",
"user_id",
",",
"$",
"args",
")",
";",
"}"
] | Delete a user.
@param int $user_id ID of user to delete.
@param array $args Optional. Extra parameters to pass to WordPress. | [
"Delete",
"a",
"user",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L272-L275 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/UserAwareContextTrait.php | UserAwareContextTrait.getUserDataFromUsername | public function getUserDataFromUsername(string $data, string $username)
{
return $this->getDriver()->user->get($username, ['by' => 'login'])->{$data};
} | php | public function getUserDataFromUsername(string $data, string $username)
{
return $this->getDriver()->user->get($username, ['by' => 'login'])->{$data};
} | [
"public",
"function",
"getUserDataFromUsername",
"(",
"string",
"$",
"data",
",",
"string",
"$",
"username",
")",
"{",
"return",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"user",
"->",
"get",
"(",
"$",
"username",
",",
"[",
"'by'",
"=>",
"'login'",
"]",
")",
"->",
"{",
"$",
"data",
"}",
";",
"}"
] | Get a piece of user data from their username.
@param string $data The user data to return (the name of a column from the WP_Users table).
@param string $username The username of the user to fetch a property from.
@return mixed The specified user data. | [
"Get",
"a",
"piece",
"of",
"user",
"data",
"from",
"their",
"username",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/UserAwareContextTrait.php#L285-L288 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/TermElement.php | TermElement.create | public function create($args)
{
$args = wp_slash($args);
$term = wp_insert_term($args['term'], $args['taxonomy'], $args);
if (is_wordpress_error($term)) {
throw new UnexpectedValueException(sprintf('[W609] Failed creating a new term: %s', $term->get_error_message()));
}
return $this->get($term['term_id']);
} | php | public function create($args)
{
$args = wp_slash($args);
$term = wp_insert_term($args['term'], $args['taxonomy'], $args);
if (is_wordpress_error($term)) {
throw new UnexpectedValueException(sprintf('[W609] Failed creating a new term: %s', $term->get_error_message()));
}
return $this->get($term['term_id']);
} | [
"public",
"function",
"create",
"(",
"$",
"args",
")",
"{",
"$",
"args",
"=",
"wp_slash",
"(",
"$",
"args",
")",
";",
"$",
"term",
"=",
"wp_insert_term",
"(",
"$",
"args",
"[",
"'term'",
"]",
",",
"$",
"args",
"[",
"'taxonomy'",
"]",
",",
"$",
"args",
")",
";",
"if",
"(",
"is_wordpress_error",
"(",
"$",
"term",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W609] Failed creating a new term: %s'",
",",
"$",
"term",
"->",
"get_error_message",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"term",
"[",
"'term_id'",
"]",
")",
";",
"}"
] | Create an item for this element.
@param array $args Data used to create an object.
@throws \UnexpectedValueException
@return \WP_Term The new item. | [
"Create",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/TermElement.php#L22-L32 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/TermElement.php | TermElement.get | public function get($id, $args = [])
{
$term = get_term($id, $args['taxonomy']);
if (! $term) {
throw new UnexpectedValueException(sprintf('[W610] Could not find term with ID %d', $id));
} elseif (is_wp_error($term)) {
throw new UnexpectedValueException(
sprintf('[W610] Could not find term with ID %d: %s', $id, $term->get_error_message())
);
}
return $term;
} | php | public function get($id, $args = [])
{
$term = get_term($id, $args['taxonomy']);
if (! $term) {
throw new UnexpectedValueException(sprintf('[W610] Could not find term with ID %d', $id));
} elseif (is_wp_error($term)) {
throw new UnexpectedValueException(
sprintf('[W610] Could not find term with ID %d: %s', $id, $term->get_error_message())
);
}
return $term;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"term",
"=",
"get_term",
"(",
"$",
"id",
",",
"$",
"args",
"[",
"'taxonomy'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"term",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W610] Could not find term with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"elseif",
"(",
"is_wp_error",
"(",
"$",
"term",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W610] Could not find term with ID %d: %s'",
",",
"$",
"id",
",",
"$",
"term",
"->",
"get_error_message",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"term",
";",
"}"
] | Retrieve an item for this element.
@param int $id Object ID.
@param array $args Optional data used to fetch an object.
@throws \UnexpectedValueException
@return \WP_Term The item. | [
"Retrieve",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/TermElement.php#L44-L57 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpphp/TermElement.php | TermElement.delete | public function delete($id, $args = [])
{
$result = wp_delete_term($id, $args['taxonomy']);
if (is_wordpress_error($result)) {
throw new UnexpectedValueException(
sprintf('[W611] Failed deleting a term: %s', $result->get_error_message())
);
}
} | php | public function delete($id, $args = [])
{
$result = wp_delete_term($id, $args['taxonomy']);
if (is_wordpress_error($result)) {
throw new UnexpectedValueException(
sprintf('[W611] Failed deleting a term: %s', $result->get_error_message())
);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"wp_delete_term",
"(",
"$",
"id",
",",
"$",
"args",
"[",
"'taxonomy'",
"]",
")",
";",
"if",
"(",
"is_wordpress_error",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W611] Failed deleting a term: %s'",
",",
"$",
"result",
"->",
"get_error_message",
"(",
")",
")",
")",
";",
"}",
"}"
] | Delete an item for this element.
@param int $id Object ID.
@param array $args Optional data used to delete an object.
@throws \UnexpectedValueException | [
"Delete",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpphp/TermElement.php#L67-L76 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.configure | public function configure(ArrayNodeDefinition $builder)
{
$builder
->children()
// Common settings.
->enumNode('default_driver')
// "wpapi" is for backwards compatibility; means "wpphp".
->values(['wpcli', 'wpapi', 'wpphp', 'blackbox'])
->defaultValue('wpcli')
->end()
->scalarNode('path')
->defaultValue('')
->end()
// WordPress' "siteurl" option.
->scalarNode('site_url')->defaultValue('%mink.base_url%')->end()
// Account roles -> username/password.
->arrayNode('users')
->prototype('array')
->children()
->variableNode('roles')
->defaultValue(['administrator'])
->end()
->scalarNode('username')
->defaultValue('admin')
->end()
->scalarNode('password')
->defaultValue('admin')
->end()
->end()
->end()
->end()
// WP-CLI driver.
->arrayNode('wpcli')
->addDefaultsIfNotSet()
->children()
->scalarNode('alias')->end()
->scalarNode('binary')
->defaultValue('wp')
->end()
->end()
->end()
// WordPress PHP driver.
->arrayNode('wpphp')
->addDefaultsIfNotSet()
->children()
->end()
->end()
// Blackbox driver.
->arrayNode('blackbox')
->addDefaultsIfNotSet()
->children()
->end()
->end()
// Database management.
->arrayNode('database')
->addDefaultsIfNotSet()
->children()
->booleanNode('restore_after_test')
->defaultFalse()
->end()
->scalarNode('backup_path')
->end()
->end()
->end()
// Permalink patterns.
->arrayNode('permalinks')
->addDefaultsIfNotSet()
->children()
->scalarNode('author_archive')
->defaultValue('author/%s/')
->end()
->end()
->end()
// Internal use only. Don't use it. Or else.
->arrayNode('internal')
->addDefaultsIfNotSet()
->end()
->end()
->end();
} | php | public function configure(ArrayNodeDefinition $builder)
{
$builder
->children()
// Common settings.
->enumNode('default_driver')
// "wpapi" is for backwards compatibility; means "wpphp".
->values(['wpcli', 'wpapi', 'wpphp', 'blackbox'])
->defaultValue('wpcli')
->end()
->scalarNode('path')
->defaultValue('')
->end()
// WordPress' "siteurl" option.
->scalarNode('site_url')->defaultValue('%mink.base_url%')->end()
// Account roles -> username/password.
->arrayNode('users')
->prototype('array')
->children()
->variableNode('roles')
->defaultValue(['administrator'])
->end()
->scalarNode('username')
->defaultValue('admin')
->end()
->scalarNode('password')
->defaultValue('admin')
->end()
->end()
->end()
->end()
// WP-CLI driver.
->arrayNode('wpcli')
->addDefaultsIfNotSet()
->children()
->scalarNode('alias')->end()
->scalarNode('binary')
->defaultValue('wp')
->end()
->end()
->end()
// WordPress PHP driver.
->arrayNode('wpphp')
->addDefaultsIfNotSet()
->children()
->end()
->end()
// Blackbox driver.
->arrayNode('blackbox')
->addDefaultsIfNotSet()
->children()
->end()
->end()
// Database management.
->arrayNode('database')
->addDefaultsIfNotSet()
->children()
->booleanNode('restore_after_test')
->defaultFalse()
->end()
->scalarNode('backup_path')
->end()
->end()
->end()
// Permalink patterns.
->arrayNode('permalinks')
->addDefaultsIfNotSet()
->children()
->scalarNode('author_archive')
->defaultValue('author/%s/')
->end()
->end()
->end()
// Internal use only. Don't use it. Or else.
->arrayNode('internal')
->addDefaultsIfNotSet()
->end()
->end()
->end();
} | [
"public",
"function",
"configure",
"(",
"ArrayNodeDefinition",
"$",
"builder",
")",
"{",
"$",
"builder",
"->",
"children",
"(",
")",
"// Common settings.",
"->",
"enumNode",
"(",
"'default_driver'",
")",
"// \"wpapi\" is for backwards compatibility; means \"wpphp\".",
"->",
"values",
"(",
"[",
"'wpcli'",
",",
"'wpapi'",
",",
"'wpphp'",
",",
"'blackbox'",
"]",
")",
"->",
"defaultValue",
"(",
"'wpcli'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'path'",
")",
"->",
"defaultValue",
"(",
"''",
")",
"->",
"end",
"(",
")",
"// WordPress' \"siteurl\" option.",
"->",
"scalarNode",
"(",
"'site_url'",
")",
"->",
"defaultValue",
"(",
"'%mink.base_url%'",
")",
"->",
"end",
"(",
")",
"// Account roles -> username/password.",
"->",
"arrayNode",
"(",
"'users'",
")",
"->",
"prototype",
"(",
"'array'",
")",
"->",
"children",
"(",
")",
"->",
"variableNode",
"(",
"'roles'",
")",
"->",
"defaultValue",
"(",
"[",
"'administrator'",
"]",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'username'",
")",
"->",
"defaultValue",
"(",
"'admin'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'password'",
")",
"->",
"defaultValue",
"(",
"'admin'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// WP-CLI driver.",
"->",
"arrayNode",
"(",
"'wpcli'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'alias'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'binary'",
")",
"->",
"defaultValue",
"(",
"'wp'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// WordPress PHP driver.",
"->",
"arrayNode",
"(",
"'wpphp'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// Blackbox driver.",
"->",
"arrayNode",
"(",
"'blackbox'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// Database management.",
"->",
"arrayNode",
"(",
"'database'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"booleanNode",
"(",
"'restore_after_test'",
")",
"->",
"defaultFalse",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'backup_path'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// Permalink patterns.",
"->",
"arrayNode",
"(",
"'permalinks'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'author_archive'",
")",
"->",
"defaultValue",
"(",
"'author/%s/'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"// Internal use only. Don't use it. Or else.",
"->",
"arrayNode",
"(",
"'internal'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"}"
] | Declare configuration options for the extension.
@param ArrayNodeDefinition $builder | [
"Declare",
"configuration",
"options",
"for",
"the",
"extension",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L73-L160 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.load | public function load(ContainerBuilder $container, array $config)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.yml');
// Backwards compatibility for pre-1.0. Will be removed in 2.0.
if ($config['default_driver'] === 'wpapi') {
$config['default_driver'] = 'wpphp';
}
$container->setParameter('wordpress.wordpress.default_driver', $config['default_driver']);
$container->setParameter('wordpress.path', $config['path']);
$container->setParameter('wordpress.parameters', $config);
$this->setupWpcliDriver($loader, $container, $config);
$this->setupWpphpDriver($loader, $container, $config);
$this->setupBlackboxDriver($loader, $container, $config);
} | php | public function load(ContainerBuilder $container, array $config)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.yml');
// Backwards compatibility for pre-1.0. Will be removed in 2.0.
if ($config['default_driver'] === 'wpapi') {
$config['default_driver'] = 'wpphp';
}
$container->setParameter('wordpress.wordpress.default_driver', $config['default_driver']);
$container->setParameter('wordpress.path', $config['path']);
$container->setParameter('wordpress.parameters', $config);
$this->setupWpcliDriver($loader, $container, $config);
$this->setupWpphpDriver($loader, $container, $config);
$this->setupBlackboxDriver($loader, $container, $config);
} | [
"public",
"function",
"load",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"$",
"loader",
"=",
"new",
"YamlFileLoader",
"(",
"$",
"container",
",",
"new",
"FileLocator",
"(",
"__DIR__",
".",
"'/config'",
")",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"'services.yml'",
")",
";",
"// Backwards compatibility for pre-1.0. Will be removed in 2.0.",
"if",
"(",
"$",
"config",
"[",
"'default_driver'",
"]",
"===",
"'wpapi'",
")",
"{",
"$",
"config",
"[",
"'default_driver'",
"]",
"=",
"'wpphp'",
";",
"}",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.wordpress.default_driver'",
",",
"$",
"config",
"[",
"'default_driver'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.path'",
",",
"$",
"config",
"[",
"'path'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.parameters'",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"setupWpcliDriver",
"(",
"$",
"loader",
",",
"$",
"container",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"setupWpphpDriver",
"(",
"$",
"loader",
",",
"$",
"container",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"setupBlackboxDriver",
"(",
"$",
"loader",
",",
"$",
"container",
",",
"$",
"config",
")",
";",
"}"
] | Load extension services into ServiceContainer.
@param ContainerBuilder $container
@param array $config | [
"Load",
"extension",
"services",
"into",
"ServiceContainer",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L168-L185 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.setupWpcliDriver | protected function setupWpcliDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['wpcli'])) {
return;
}
$loader->load('drivers/wpcli.yml');
$config['wpcli']['alias'] = isset($config['wpcli']['alias']) ? $config['wpcli']['alias'] : '';
$container->setParameter('wordpress.driver.wpcli.alias', $config['wpcli']['alias']);
$config['wpcli']['path'] = isset($config['path']) ? $config['path'] : '';
$container->setParameter('wordpress.driver.wpcli.path', $config['path']);
$config['wpcli']['binary'] = isset($config['wpcli']['binary']) ? $config['wpcli']['binary'] : null;
$container->setParameter('wordpress.driver.wpcli.binary', $config['wpcli']['binary']);
} | php | protected function setupWpcliDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['wpcli'])) {
return;
}
$loader->load('drivers/wpcli.yml');
$config['wpcli']['alias'] = isset($config['wpcli']['alias']) ? $config['wpcli']['alias'] : '';
$container->setParameter('wordpress.driver.wpcli.alias', $config['wpcli']['alias']);
$config['wpcli']['path'] = isset($config['path']) ? $config['path'] : '';
$container->setParameter('wordpress.driver.wpcli.path', $config['path']);
$config['wpcli']['binary'] = isset($config['wpcli']['binary']) ? $config['wpcli']['binary'] : null;
$container->setParameter('wordpress.driver.wpcli.binary', $config['wpcli']['binary']);
} | [
"protected",
"function",
"setupWpcliDriver",
"(",
"FileLoader",
"$",
"loader",
",",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'wpcli'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"loader",
"->",
"load",
"(",
"'drivers/wpcli.yml'",
")",
";",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'alias'",
"]",
"=",
"isset",
"(",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'alias'",
"]",
")",
"?",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'alias'",
"]",
":",
"''",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.driver.wpcli.alias'",
",",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'alias'",
"]",
")",
";",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'path'",
"]",
"=",
"isset",
"(",
"$",
"config",
"[",
"'path'",
"]",
")",
"?",
"$",
"config",
"[",
"'path'",
"]",
":",
"''",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.driver.wpcli.path'",
",",
"$",
"config",
"[",
"'path'",
"]",
")",
";",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'binary'",
"]",
"=",
"isset",
"(",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'binary'",
"]",
")",
"?",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'binary'",
"]",
":",
"null",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.driver.wpcli.binary'",
",",
"$",
"config",
"[",
"'wpcli'",
"]",
"[",
"'binary'",
"]",
")",
";",
"}"
] | Load settings for the WP-CLI driver.
@param FileLoader $loader
@param ContainerBuilder $container
@param array $config | [
"Load",
"settings",
"for",
"the",
"WP",
"-",
"CLI",
"driver",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L194-L210 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.setupWpphpDriver | protected function setupWpphpDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['wpphp'])) {
return;
}
$loader->load('drivers/wpphp.yml');
$config['wpphp']['path'] = isset($config['path']) ? $config['path'] : '';
$container->setParameter('wordpress.driver.wpphp.path', $config['wpphp']['path']);
} | php | protected function setupWpphpDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['wpphp'])) {
return;
}
$loader->load('drivers/wpphp.yml');
$config['wpphp']['path'] = isset($config['path']) ? $config['path'] : '';
$container->setParameter('wordpress.driver.wpphp.path', $config['wpphp']['path']);
} | [
"protected",
"function",
"setupWpphpDriver",
"(",
"FileLoader",
"$",
"loader",
",",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'wpphp'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"loader",
"->",
"load",
"(",
"'drivers/wpphp.yml'",
")",
";",
"$",
"config",
"[",
"'wpphp'",
"]",
"[",
"'path'",
"]",
"=",
"isset",
"(",
"$",
"config",
"[",
"'path'",
"]",
")",
"?",
"$",
"config",
"[",
"'path'",
"]",
":",
"''",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'wordpress.driver.wpphp.path'",
",",
"$",
"config",
"[",
"'wpphp'",
"]",
"[",
"'path'",
"]",
")",
";",
"}"
] | Load settings for the WordPress PHP driver.
@param FileLoader $loader
@param ContainerBuilder $container
@param array $config | [
"Load",
"settings",
"for",
"the",
"WordPress",
"PHP",
"driver",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L219-L229 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.setupBlackboxDriver | protected function setupBlackboxDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['blackbox'])) {
return;
}
$loader->load('drivers/blackbox.yml');
} | php | protected function setupBlackboxDriver(FileLoader $loader, ContainerBuilder $container, array $config)
{
if (! isset($config['blackbox'])) {
return;
}
$loader->load('drivers/blackbox.yml');
} | [
"protected",
"function",
"setupBlackboxDriver",
"(",
"FileLoader",
"$",
"loader",
",",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'blackbox'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"loader",
"->",
"load",
"(",
"'drivers/blackbox.yml'",
")",
";",
"}"
] | Load settings for the blackbox driver.
@param FileLoader $loader
@param ContainerBuilder $container
@param array $config | [
"Load",
"settings",
"for",
"the",
"blackbox",
"driver",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L238-L245 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.process | public function process(ContainerBuilder $container)
{
$this->processDriverPass($container);
$this->processDriverElementPass($container);
$this->processEventSubscriberPass($container);
$this->processClassGenerator($container);
$this->setPageObjectNamespaces($container);
$this->injectSiteUrlIntoPageObjects($container);
} | php | public function process(ContainerBuilder $container)
{
$this->processDriverPass($container);
$this->processDriverElementPass($container);
$this->processEventSubscriberPass($container);
$this->processClassGenerator($container);
$this->setPageObjectNamespaces($container);
$this->injectSiteUrlIntoPageObjects($container);
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"processDriverPass",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"processDriverElementPass",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"processEventSubscriberPass",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"processClassGenerator",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"setPageObjectNamespaces",
"(",
"$",
"container",
")",
";",
"$",
"this",
"->",
"injectSiteUrlIntoPageObjects",
"(",
"$",
"container",
")",
";",
"}"
] | Modify the container before Symfony compiles it.
@param ContainerBuilder $container | [
"Modify",
"the",
"container",
"before",
"Symfony",
"compiles",
"it",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L252-L261 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.setPageObjectNamespaces | protected function setPageObjectNamespaces(ContainerBuilder $container)
{
// Append our namespaces as earlier namespaces take precedence.
$pages = $container->getParameter('sensio_labs.page_object_extension.namespaces.page');
$pages[] = 'PaulGibbs\WordpressBehatExtension\PageObject';
$elements = $container->getParameter('sensio_labs.page_object_extension.namespaces.element');
$elements[] = 'PaulGibbs\WordpressBehatExtension\PageObject\Element';
$container->setParameter('sensio_labs.page_object_extension.namespaces.page', $pages);
$container->setParameter('sensio_labs.page_object_extension.namespaces.element', $elements);
} | php | protected function setPageObjectNamespaces(ContainerBuilder $container)
{
// Append our namespaces as earlier namespaces take precedence.
$pages = $container->getParameter('sensio_labs.page_object_extension.namespaces.page');
$pages[] = 'PaulGibbs\WordpressBehatExtension\PageObject';
$elements = $container->getParameter('sensio_labs.page_object_extension.namespaces.element');
$elements[] = 'PaulGibbs\WordpressBehatExtension\PageObject\Element';
$container->setParameter('sensio_labs.page_object_extension.namespaces.page', $pages);
$container->setParameter('sensio_labs.page_object_extension.namespaces.element', $elements);
} | [
"protected",
"function",
"setPageObjectNamespaces",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"// Append our namespaces as earlier namespaces take precedence.",
"$",
"pages",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'sensio_labs.page_object_extension.namespaces.page'",
")",
";",
"$",
"pages",
"[",
"]",
"=",
"'PaulGibbs\\WordpressBehatExtension\\PageObject'",
";",
"$",
"elements",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'sensio_labs.page_object_extension.namespaces.element'",
")",
";",
"$",
"elements",
"[",
"]",
"=",
"'PaulGibbs\\WordpressBehatExtension\\PageObject\\Element'",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'sensio_labs.page_object_extension.namespaces.page'",
",",
"$",
"pages",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'sensio_labs.page_object_extension.namespaces.element'",
",",
"$",
"elements",
")",
";",
"}"
] | Tell Page Object Extension the namespace of our page objects
@param ContainerBuilder $container | [
"Tell",
"Page",
"Object",
"Extension",
"the",
"namespace",
"of",
"our",
"page",
"objects"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L314-L325 |
paulgibbs/behat-wordpress-extension | src/ServiceContainer/WordpressBehatExtension.php | WordpressBehatExtension.injectSiteUrlIntoPageObjects | protected function injectSiteUrlIntoPageObjects(ContainerBuilder $container)
{
$page_parameters = $container->getParameter('sensio_labs.page_object_extension.page_factory.page_parameters');
$page_parameters = $container->getParameterBag()->resolveValue($page_parameters);
$page_parameters['site_url'] = $container->getParameter('wordpress.parameters')['site_url'];
$container->setParameter('sensio_labs.page_object_extension.page_factory.page_parameters', $page_parameters);
} | php | protected function injectSiteUrlIntoPageObjects(ContainerBuilder $container)
{
$page_parameters = $container->getParameter('sensio_labs.page_object_extension.page_factory.page_parameters');
$page_parameters = $container->getParameterBag()->resolveValue($page_parameters);
$page_parameters['site_url'] = $container->getParameter('wordpress.parameters')['site_url'];
$container->setParameter('sensio_labs.page_object_extension.page_factory.page_parameters', $page_parameters);
} | [
"protected",
"function",
"injectSiteUrlIntoPageObjects",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"page_parameters",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'sensio_labs.page_object_extension.page_factory.page_parameters'",
")",
";",
"$",
"page_parameters",
"=",
"$",
"container",
"->",
"getParameterBag",
"(",
")",
"->",
"resolveValue",
"(",
"$",
"page_parameters",
")",
";",
"$",
"page_parameters",
"[",
"'site_url'",
"]",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'wordpress.parameters'",
")",
"[",
"'site_url'",
"]",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'sensio_labs.page_object_extension.page_factory.page_parameters'",
",",
"$",
"page_parameters",
")",
";",
"}"
] | Adds the WordPress site url as a page parameter into page objects.
@param ContainerBuilder $container | [
"Adds",
"the",
"WordPress",
"site",
"url",
"as",
"a",
"page",
"parameter",
"into",
"page",
"objects",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/ServiceContainer/WordpressBehatExtension.php#L332-L338 |
paulgibbs/behat-wordpress-extension | src/Context/Initialiser/WordpressAwareInitialiser.php | WordpressAwareInitialiser.initializeContext | public function initializeContext(Context $context)
{
if (! $context instanceof WordpressAwareInterface) {
return;
}
$context->setWordpress($this->wordpress);
$context->setWordpressParameters($this->parameters);
} | php | public function initializeContext(Context $context)
{
if (! $context instanceof WordpressAwareInterface) {
return;
}
$context->setWordpress($this->wordpress);
$context->setWordpressParameters($this->parameters);
} | [
"public",
"function",
"initializeContext",
"(",
"Context",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"context",
"instanceof",
"WordpressAwareInterface",
")",
"{",
"return",
";",
"}",
"$",
"context",
"->",
"setWordpress",
"(",
"$",
"this",
"->",
"wordpress",
")",
";",
"$",
"context",
"->",
"setWordpressParameters",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"}"
] | Prepare everything that the Context needs.
@param Context $context | [
"Prepare",
"everything",
"that",
"the",
"Context",
"needs",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Initialiser/WordpressAwareInitialiser.php#L47-L55 |
paulgibbs/behat-wordpress-extension | src/Context/WordpressContext.php | WordpressContext.maybeBackupDatabase | public function maybeBackupDatabase(BeforeScenarioScope $scope)
{
$db = $this->getWordpressParameter('database');
if (! $db['restore_after_test']) {
return;
}
/*
* We need the logic of this method to operate only once, and have access to the Context.
* Otherwise, we would use the (static) BeforeSuiteScope hook.
*/
$backup_file = $this->getWordpress()->getSetting('database_backup_file');
if ($backup_file) {
return;
}
// Get the file to use as a backup.
$file = ! empty($db['backup_path']) ? $db['backup_path'] : '';
// If the path specified is not a file, use it as the preferred folder to store a new backup.
if (! $file || ! is_file($file) || ! is_readable($file)) {
$file = $this->exportDatabase(['path' => $file]);
}
// Note: $file may be either an absolute OR relative file path.
$this->getWordpress()->setSetting('database_backup_file', $file);
} | php | public function maybeBackupDatabase(BeforeScenarioScope $scope)
{
$db = $this->getWordpressParameter('database');
if (! $db['restore_after_test']) {
return;
}
/*
* We need the logic of this method to operate only once, and have access to the Context.
* Otherwise, we would use the (static) BeforeSuiteScope hook.
*/
$backup_file = $this->getWordpress()->getSetting('database_backup_file');
if ($backup_file) {
return;
}
// Get the file to use as a backup.
$file = ! empty($db['backup_path']) ? $db['backup_path'] : '';
// If the path specified is not a file, use it as the preferred folder to store a new backup.
if (! $file || ! is_file($file) || ! is_readable($file)) {
$file = $this->exportDatabase(['path' => $file]);
}
// Note: $file may be either an absolute OR relative file path.
$this->getWordpress()->setSetting('database_backup_file', $file);
} | [
"public",
"function",
"maybeBackupDatabase",
"(",
"BeforeScenarioScope",
"$",
"scope",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getWordpressParameter",
"(",
"'database'",
")",
";",
"if",
"(",
"!",
"$",
"db",
"[",
"'restore_after_test'",
"]",
")",
"{",
"return",
";",
"}",
"/*\n * We need the logic of this method to operate only once, and have access to the Context.\n * Otherwise, we would use the (static) BeforeSuiteScope hook.\n */",
"$",
"backup_file",
"=",
"$",
"this",
"->",
"getWordpress",
"(",
")",
"->",
"getSetting",
"(",
"'database_backup_file'",
")",
";",
"if",
"(",
"$",
"backup_file",
")",
"{",
"return",
";",
"}",
"// Get the file to use as a backup.",
"$",
"file",
"=",
"!",
"empty",
"(",
"$",
"db",
"[",
"'backup_path'",
"]",
")",
"?",
"$",
"db",
"[",
"'backup_path'",
"]",
":",
"''",
";",
"// If the path specified is not a file, use it as the preferred folder to store a new backup.",
"if",
"(",
"!",
"$",
"file",
"||",
"!",
"is_file",
"(",
"$",
"file",
")",
"||",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"exportDatabase",
"(",
"[",
"'path'",
"=>",
"$",
"file",
"]",
")",
";",
"}",
"// Note: $file may be either an absolute OR relative file path.",
"$",
"this",
"->",
"getWordpress",
"(",
")",
"->",
"setSetting",
"(",
"'database_backup_file'",
",",
"$",
"file",
")",
";",
"}"
] | If database.restore_after_test is set, and a scenario is tagged "db", create a database backup.
The database will be restored from this backup via maybeRestoreDatabase().
@BeforeScenario @db
@param BeforeScenarioScope $scope | [
"If",
"database",
".",
"restore_after_test",
"is",
"set",
"and",
"a",
"scenario",
"is",
"tagged",
"db",
"create",
"a",
"database",
"backup",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/WordpressContext.php#L36-L62 |
paulgibbs/behat-wordpress-extension | src/Context/WordpressContext.php | WordpressContext.fixToolbar | public function fixToolbar()
{
$driver = $this->getSession()->getDriver();
if (! $driver instanceof Selenium2Driver || ! $driver->getWebDriverSession()) {
return;
}
try {
$this->getSession()->getDriver()->executeScript(
'if (document.getElementById("wpadminbar")) {
document.getElementById("wpadminbar").style.position="absolute";
if (document.getElementsByTagName("body")[0].className.match(/wp-admin/)) {
document.getElementById("wpadminbar").style.top="-32px";
}
};'
);
} catch (\Exception $e) {
/*
* If a browser is not open, then Selenium2Driver::executeScript() will throw an exception.
* In this case, our toolbar workaround obviously isn't required, so fail quietly.
*/
}
} | php | public function fixToolbar()
{
$driver = $this->getSession()->getDriver();
if (! $driver instanceof Selenium2Driver || ! $driver->getWebDriverSession()) {
return;
}
try {
$this->getSession()->getDriver()->executeScript(
'if (document.getElementById("wpadminbar")) {
document.getElementById("wpadminbar").style.position="absolute";
if (document.getElementsByTagName("body")[0].className.match(/wp-admin/)) {
document.getElementById("wpadminbar").style.top="-32px";
}
};'
);
} catch (\Exception $e) {
/*
* If a browser is not open, then Selenium2Driver::executeScript() will throw an exception.
* In this case, our toolbar workaround obviously isn't required, so fail quietly.
*/
}
} | [
"public",
"function",
"fixToolbar",
"(",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"if",
"(",
"!",
"$",
"driver",
"instanceof",
"Selenium2Driver",
"||",
"!",
"$",
"driver",
"->",
"getWebDriverSession",
"(",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
"->",
"executeScript",
"(",
"'if (document.getElementById(\"wpadminbar\")) {\n document.getElementById(\"wpadminbar\").style.position=\"absolute\";\n if (document.getElementsByTagName(\"body\")[0].className.match(/wp-admin/)) {\n document.getElementById(\"wpadminbar\").style.top=\"-32px\";\n }\n };'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"/*\n * If a browser is not open, then Selenium2Driver::executeScript() will throw an exception.\n * In this case, our toolbar workaround obviously isn't required, so fail quietly.\n */",
"}",
"}"
] | When using the Selenium driver, position the admin bar to the top of the page, not fixed to the screen.
Otherwise the admin toolbar can hide clickable elements.
@BeforeStep | [
"When",
"using",
"the",
"Selenium",
"driver",
"position",
"the",
"admin",
"bar",
"to",
"the",
"top",
"of",
"the",
"page",
"not",
"fixed",
"to",
"the",
"screen",
".",
"Otherwise",
"the",
"admin",
"toolbar",
"can",
"hide",
"clickable",
"elements",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/WordpressContext.php#L70-L92 |
paulgibbs/behat-wordpress-extension | src/Context/WordpressContext.php | WordpressContext.maybeRestoreDatabase | public function maybeRestoreDatabase(AfterScenarioScope $scope)
{
$db = $this->getWordpressParameter('database');
if (! $db['restore_after_test']) {
return;
}
$file = $this->getWordpress()->getSetting('database_backup_file');
if (! $file) {
return;
}
$this->importDatabase(['path' => $file]);
} | php | public function maybeRestoreDatabase(AfterScenarioScope $scope)
{
$db = $this->getWordpressParameter('database');
if (! $db['restore_after_test']) {
return;
}
$file = $this->getWordpress()->getSetting('database_backup_file');
if (! $file) {
return;
}
$this->importDatabase(['path' => $file]);
} | [
"public",
"function",
"maybeRestoreDatabase",
"(",
"AfterScenarioScope",
"$",
"scope",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getWordpressParameter",
"(",
"'database'",
")",
";",
"if",
"(",
"!",
"$",
"db",
"[",
"'restore_after_test'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"getWordpress",
"(",
")",
"->",
"getSetting",
"(",
"'database_backup_file'",
")",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"importDatabase",
"(",
"[",
"'path'",
"=>",
"$",
"file",
"]",
")",
";",
"}"
] | If database.restore_after_test is set, and scenario is tagged "db", restore the database from a backup.
The database will be restored from a backup made via maybeBackupDatabase().
@AfterScenario @db
@param AfterScenarioScope $scope | [
"If",
"database",
".",
"restore_after_test",
"is",
"set",
"and",
"scenario",
"is",
"tagged",
"db",
"restore",
"the",
"database",
"from",
"a",
"backup",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/WordpressContext.php#L113-L126 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/TermAwareContextTrait.php | TermAwareContextTrait.createTerm | public function createTerm(string $term, string $taxonomy, array $args = []): array
{
$args['taxonomy'] = $taxonomy;
$args['term'] = $term;
$term = $this->getDriver()->term->create($args);
return array(
'id' => $term->term_id,
'slug' => $term->slug
);
} | php | public function createTerm(string $term, string $taxonomy, array $args = []): array
{
$args['taxonomy'] = $taxonomy;
$args['term'] = $term;
$term = $this->getDriver()->term->create($args);
return array(
'id' => $term->term_id,
'slug' => $term->slug
);
} | [
"public",
"function",
"createTerm",
"(",
"string",
"$",
"term",
",",
"string",
"$",
"taxonomy",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"args",
"[",
"'taxonomy'",
"]",
"=",
"$",
"taxonomy",
";",
"$",
"args",
"[",
"'term'",
"]",
"=",
"$",
"term",
";",
"$",
"term",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"term",
"->",
"create",
"(",
"$",
"args",
")",
";",
"return",
"array",
"(",
"'id'",
"=>",
"$",
"term",
"->",
"term_id",
",",
"'slug'",
"=>",
"$",
"term",
"->",
"slug",
")",
";",
"}"
] | Create a term in a taxonomy.
@param string $term
@param string $taxonomy
@param array $args Optional. Set the values of the new term.
@return array {
@type int $id Term ID.
@type string $slug Term slug.
} | [
"Create",
"a",
"term",
"in",
"a",
"taxonomy",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/TermAwareContextTrait.php#L24-L35 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/TermAwareContextTrait.php | TermAwareContextTrait.deleteTerm | public function deleteTerm(int $term_id, string $taxonomy)
{
$this->getDriver()->term->delete($term_id, compact($taxonomy));
} | php | public function deleteTerm(int $term_id, string $taxonomy)
{
$this->getDriver()->term->delete($term_id, compact($taxonomy));
} | [
"public",
"function",
"deleteTerm",
"(",
"int",
"$",
"term_id",
",",
"string",
"$",
"taxonomy",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"term",
"->",
"delete",
"(",
"$",
"term_id",
",",
"compact",
"(",
"$",
"taxonomy",
")",
")",
";",
"}"
] | Delete a term from a taxonomy.
@param int $term_id
@param string $taxonomy | [
"Delete",
"a",
"term",
"from",
"a",
"taxonomy",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/TermAwareContextTrait.php#L43-L46 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.getHeaderText | public function getHeaderText(): string
{
$header = $this->getHeaderElement();
$header_text = $header->getText();
$header_link = $header->find('css', 'a');
// The page headers can often include an 'add new link'. Strip that out of the header text.
if ($header_link) {
$header_text = trim(str_replace($header_link->getText(), '', $header_text));
}
return $header_text;
} | php | public function getHeaderText(): string
{
$header = $this->getHeaderElement();
$header_text = $header->getText();
$header_link = $header->find('css', 'a');
// The page headers can often include an 'add new link'. Strip that out of the header text.
if ($header_link) {
$header_text = trim(str_replace($header_link->getText(), '', $header_text));
}
return $header_text;
} | [
"public",
"function",
"getHeaderText",
"(",
")",
":",
"string",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"getHeaderElement",
"(",
")",
";",
"$",
"header_text",
"=",
"$",
"header",
"->",
"getText",
"(",
")",
";",
"$",
"header_link",
"=",
"$",
"header",
"->",
"find",
"(",
"'css'",
",",
"'a'",
")",
";",
"// The page headers can often include an 'add new link'. Strip that out of the header text.",
"if",
"(",
"$",
"header_link",
")",
"{",
"$",
"header_text",
"=",
"trim",
"(",
"str_replace",
"(",
"$",
"header_link",
"->",
"getText",
"(",
")",
",",
"''",
",",
"$",
"header_text",
")",
")",
";",
"}",
"return",
"$",
"header_text",
";",
"}"
] | Returns the text in the header tag.
The first h1 element is used, or first h2 element if it is not present.
@return string The text in the header tag. | [
"Returns",
"the",
"text",
"in",
"the",
"header",
"tag",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L24-L36 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.assertHasHeader | public function assertHasHeader(string $expected)
{
$actual = $this->getHeaderText();
if ($expected === $actual) {
return;
}
throw new ExpectationException(
sprintf(
'[W402] Expected screen header "%1$s", found "%2$s".',
$expected,
$actual
),
$this->getDriver()
);
} | php | public function assertHasHeader(string $expected)
{
$actual = $this->getHeaderText();
if ($expected === $actual) {
return;
}
throw new ExpectationException(
sprintf(
'[W402] Expected screen header "%1$s", found "%2$s".',
$expected,
$actual
),
$this->getDriver()
);
} | [
"public",
"function",
"assertHasHeader",
"(",
"string",
"$",
"expected",
")",
"{",
"$",
"actual",
"=",
"$",
"this",
"->",
"getHeaderText",
"(",
")",
";",
"if",
"(",
"$",
"expected",
"===",
"$",
"actual",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"ExpectationException",
"(",
"sprintf",
"(",
"'[W402] Expected screen header \"%1$s\", found \"%2$s\".'",
",",
"$",
"expected",
",",
"$",
"actual",
")",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}"
] | Asserts the text in the header tag matches the given text.
@param string $expected
@throws \Behat\Mink\Exception\ExpectationException | [
"Asserts",
"the",
"text",
"in",
"the",
"header",
"tag",
"matches",
"the",
"given",
"text",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L45-L60 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.getHeaderElement | protected function getHeaderElement()
{
/*
* h2s were used prior to WP v4.3/4 and h1s after.
* See https://make.wordpress.org/core/2015/10/28/headings-hierarchy-changes-in-the-admin-screens/
*/
$header2 = $this->find('css', '.wrap > h2');
$header1 = $this->find('css', '.wrap > h1');
if ($header1) {
return $header1;
} elseif ($header2) {
return $header2;
}
throw new ExpectationException('[W402] Header could not be found', $this->getDriver());
} | php | protected function getHeaderElement()
{
/*
* h2s were used prior to WP v4.3/4 and h1s after.
* See https://make.wordpress.org/core/2015/10/28/headings-hierarchy-changes-in-the-admin-screens/
*/
$header2 = $this->find('css', '.wrap > h2');
$header1 = $this->find('css', '.wrap > h1');
if ($header1) {
return $header1;
} elseif ($header2) {
return $header2;
}
throw new ExpectationException('[W402] Header could not be found', $this->getDriver());
} | [
"protected",
"function",
"getHeaderElement",
"(",
")",
"{",
"/*\n * h2s were used prior to WP v4.3/4 and h1s after.\n * See https://make.wordpress.org/core/2015/10/28/headings-hierarchy-changes-in-the-admin-screens/\n */",
"$",
"header2",
"=",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'.wrap > h2'",
")",
";",
"$",
"header1",
"=",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'.wrap > h1'",
")",
";",
"if",
"(",
"$",
"header1",
")",
"{",
"return",
"$",
"header1",
";",
"}",
"elseif",
"(",
"$",
"header2",
")",
"{",
"return",
"$",
"header2",
";",
"}",
"throw",
"new",
"ExpectationException",
"(",
"'[W402] Header could not be found'",
",",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
";",
"}"
] | Get the text in the header tag.
The first h1 element is used, or first h2 element if it is not present.
@throws \Behat\Mink\Exception\ExpectationException | [
"Get",
"the",
"text",
"in",
"the",
"header",
"tag",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L69-L85 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.clickLinkInHeader | public function clickLinkInHeader(string $link)
{
$header_link = $this->find('css', '.page-title-action');
if ($header_link->getText() === $link) {
$header_link->click();
} else {
$this->getHeaderElement()->clickLink($link);
}
} | php | public function clickLinkInHeader(string $link)
{
$header_link = $this->find('css', '.page-title-action');
if ($header_link->getText() === $link) {
$header_link->click();
} else {
$this->getHeaderElement()->clickLink($link);
}
} | [
"public",
"function",
"clickLinkInHeader",
"(",
"string",
"$",
"link",
")",
"{",
"$",
"header_link",
"=",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'.page-title-action'",
")",
";",
"if",
"(",
"$",
"header_link",
"->",
"getText",
"(",
")",
"===",
"$",
"link",
")",
"{",
"$",
"header_link",
"->",
"click",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getHeaderElement",
"(",
")",
"->",
"clickLink",
"(",
"$",
"link",
")",
";",
"}",
"}"
] | Click a link within the page header tag.
@param string $link Link text. | [
"Click",
"a",
"link",
"within",
"the",
"page",
"header",
"tag",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L92-L101 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.makeSurePathIsAbsolute | protected function makeSurePathIsAbsolute($path): string
{
$site_url = rtrim($this->getParameter('site_url'), '/') . '/';
if (0 !== strpos($path, 'http')) {
return $site_url . ltrim($path, '/');
} else {
return $path;
}
} | php | protected function makeSurePathIsAbsolute($path): string
{
$site_url = rtrim($this->getParameter('site_url'), '/') . '/';
if (0 !== strpos($path, 'http')) {
return $site_url . ltrim($path, '/');
} else {
return $path;
}
} | [
"protected",
"function",
"makeSurePathIsAbsolute",
"(",
"$",
"path",
")",
":",
"string",
"{",
"$",
"site_url",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'site_url'",
")",
",",
"'/'",
")",
".",
"'/'",
";",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"path",
",",
"'http'",
")",
")",
"{",
"return",
"$",
"site_url",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"path",
";",
"}",
"}"
] | We use WordHat's site_url property rather than Mink's base_url property
to get the correct URL to wp-admin, wp-login.php etc.
@param string $path Relative path of this page
@return string Absolute URL | [
"We",
"use",
"WordHat",
"s",
"site_url",
"property",
"rather",
"than",
"Mink",
"s",
"base_url",
"property",
"to",
"get",
"the",
"correct",
"URL",
"to",
"wp",
"-",
"admin",
"wp",
"-",
"login",
".",
"php",
"etc",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L150-L159 |
paulgibbs/behat-wordpress-extension | src/PageObject/AdminPage.php | AdminPage.unmaskUrl | protected function unmaskUrl(array $url_parameters): string
{
$url = $this->getPath();
foreach ($url_parameters as $parameter => $value) {
$url = str_replace(sprintf('{%s}', $parameter), $value, $url);
}
return $url;
} | php | protected function unmaskUrl(array $url_parameters): string
{
$url = $this->getPath();
foreach ($url_parameters as $parameter => $value) {
$url = str_replace(sprintf('{%s}', $parameter), $value, $url);
}
return $url;
} | [
"protected",
"function",
"unmaskUrl",
"(",
"array",
"$",
"url_parameters",
")",
":",
"string",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"foreach",
"(",
"$",
"url_parameters",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"sprintf",
"(",
"'{%s}'",
",",
"$",
"parameter",
")",
",",
"$",
"value",
",",
"$",
"url",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Insert values for placeholders in the page's path.
@param array $url_parameters
@return string | [
"Insert",
"values",
"for",
"placeholders",
"in",
"the",
"page",
"s",
"path",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/AdminPage.php#L168-L177 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/CommentAwareContextTrait.php | CommentAwareContextTrait.createComment | public function createComment(array $args): array
{
$comment = $this->getDriver()->comment->create($args);
return array(
'id' => $comment->comment_ID
);
} | php | public function createComment(array $args): array
{
$comment = $this->getDriver()->comment->create($args);
return array(
'id' => $comment->comment_ID
);
} | [
"public",
"function",
"createComment",
"(",
"array",
"$",
"args",
")",
":",
"array",
"{",
"$",
"comment",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"comment",
"->",
"create",
"(",
"$",
"args",
")",
";",
"return",
"array",
"(",
"'id'",
"=>",
"$",
"comment",
"->",
"comment_ID",
")",
";",
"}"
] | Create a comment.
@param array $args Set the values of the new comment.
@return array {
@type int $id Content ID.
} | [
"Create",
"a",
"comment",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/CommentAwareContextTrait.php#L21-L28 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/CommentAwareContextTrait.php | CommentAwareContextTrait.deleteComment | public function deleteComment(int $comment_id, array $args = [])
{
$this->getDriver()->comment->delete($comment_id, $args);
} | php | public function deleteComment(int $comment_id, array $args = [])
{
$this->getDriver()->comment->delete($comment_id, $args);
} | [
"public",
"function",
"deleteComment",
"(",
"int",
"$",
"comment_id",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"comment",
"->",
"delete",
"(",
"$",
"comment_id",
",",
"$",
"args",
")",
";",
"}"
] | Delete specified comment.
@param int $comment_id ID of comment to delete.
@param array $args Optional. Extra parameters to pass to WordPress. | [
"Delete",
"specified",
"comment",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/CommentAwareContextTrait.php#L36-L39 |
paulgibbs/behat-wordpress-extension | src/Context/ToolbarContext.php | ToolbarContext.iShouldSeeTextInToolbar | public function iShouldSeeTextInToolbar(string $text)
{
$toolbar = $this->getElement('Toolbar');
$actual = $toolbar->getText();
$regex = '/' . preg_quote($text, '/') . '/ui';
if (! preg_match($regex, $actual)) {
$message = sprintf('[W806] The text "%s" was not found in the toolbar', $text);
throw new ElementTextException($message, $this->getSession()->getDriver(), $toolbar);
}
} | php | public function iShouldSeeTextInToolbar(string $text)
{
$toolbar = $this->getElement('Toolbar');
$actual = $toolbar->getText();
$regex = '/' . preg_quote($text, '/') . '/ui';
if (! preg_match($regex, $actual)) {
$message = sprintf('[W806] The text "%s" was not found in the toolbar', $text);
throw new ElementTextException($message, $this->getSession()->getDriver(), $toolbar);
}
} | [
"public",
"function",
"iShouldSeeTextInToolbar",
"(",
"string",
"$",
"text",
")",
"{",
"$",
"toolbar",
"=",
"$",
"this",
"->",
"getElement",
"(",
"'Toolbar'",
")",
";",
"$",
"actual",
"=",
"$",
"toolbar",
"->",
"getText",
"(",
")",
";",
"$",
"regex",
"=",
"'/'",
".",
"preg_quote",
"(",
"$",
"text",
",",
"'/'",
")",
".",
"'/ui'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"actual",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'[W806] The text \"%s\" was not found in the toolbar'",
",",
"$",
"text",
")",
";",
"throw",
"new",
"ElementTextException",
"(",
"$",
"message",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
",",
"$",
"toolbar",
")",
";",
"}",
"}"
] | Clicks the specified link in the toolbar.
Example: Then I should see "Howdy, admin" in the toolbar
@Then I should see :text in the toolbar
@param string $text
@throws ElementTextException | [
"Clicks",
"the",
"specified",
"link",
"in",
"the",
"toolbar",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ToolbarContext.php#L37-L47 |
paulgibbs/behat-wordpress-extension | src/Context/ToolbarContext.php | ToolbarContext.theUsernameShouldBe | public function theUsernameShouldBe(string $username)
{
$toolbar = $this->getElement('Toolbar');
$actual = $toolbar->getAuthenticatedUserText();
if ($username !== $actual) {
$message = sprintf('[W807] Toolbar shows authenticated user is "%1$s", not "%2$s"', $actual, $username);
throw new ElementTextException($message, $this->getSession()->getDriver(), $toolbar);
}
} | php | public function theUsernameShouldBe(string $username)
{
$toolbar = $this->getElement('Toolbar');
$actual = $toolbar->getAuthenticatedUserText();
if ($username !== $actual) {
$message = sprintf('[W807] Toolbar shows authenticated user is "%1$s", not "%2$s"', $actual, $username);
throw new ElementTextException($message, $this->getSession()->getDriver(), $toolbar);
}
} | [
"public",
"function",
"theUsernameShouldBe",
"(",
"string",
"$",
"username",
")",
"{",
"$",
"toolbar",
"=",
"$",
"this",
"->",
"getElement",
"(",
"'Toolbar'",
")",
";",
"$",
"actual",
"=",
"$",
"toolbar",
"->",
"getAuthenticatedUserText",
"(",
")",
";",
"if",
"(",
"$",
"username",
"!==",
"$",
"actual",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'[W807] Toolbar shows authenticated user is \"%1$s\", not \"%2$s\"'",
",",
"$",
"actual",
",",
"$",
"username",
")",
";",
"throw",
"new",
"ElementTextException",
"(",
"$",
"message",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getDriver",
"(",
")",
",",
"$",
"toolbar",
")",
";",
"}",
"}"
] | Checks the authenticated user show in the toolbar.
Example: Then the toolbar should show I am authenticated as admin
@Then the toolbar should show I am authenticated as :username
@param string $username | [
"Checks",
"the",
"authenticated",
"user",
"show",
"in",
"the",
"toolbar",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ToolbarContext.php#L58-L67 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/ContentAwareContextTrait.php | ContentAwareContextTrait.createContent | public function createContent(array $args): array
{
$post = $this->getDriver()->content->create($args);
return array(
'id' => (int) $post->ID,
'slug' => $post->post_name,
'url' => $post->url,
);
} | php | public function createContent(array $args): array
{
$post = $this->getDriver()->content->create($args);
return array(
'id' => (int) $post->ID,
'slug' => $post->post_name,
'url' => $post->url,
);
} | [
"public",
"function",
"createContent",
"(",
"array",
"$",
"args",
")",
":",
"array",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"content",
"->",
"create",
"(",
"$",
"args",
")",
";",
"return",
"array",
"(",
"'id'",
"=>",
"(",
"int",
")",
"$",
"post",
"->",
"ID",
",",
"'slug'",
"=>",
"$",
"post",
"->",
"post_name",
",",
"'url'",
"=>",
"$",
"post",
"->",
"url",
",",
")",
";",
"}"
] | Create content.
@param array $args Set the values of the new content item.
@return array {
@type int $id Content ID.
@type string $slug Content slug.
@type string $url Content permalink.
} | [
"Create",
"content",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/ContentAwareContextTrait.php#L23-L32 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/ContentAwareContextTrait.php | ContentAwareContextTrait.getContentFromTitle | public function getContentFromTitle(string $title, string $post_type = ''): array
{
$post = $this->getDriver()->content->get($title, ['by' => 'title', 'post_type' => $post_type]);
return array(
'id' => (int) $post->ID,
'slug' => $post->post_name,
'url' => $post->url,
);
} | php | public function getContentFromTitle(string $title, string $post_type = ''): array
{
$post = $this->getDriver()->content->get($title, ['by' => 'title', 'post_type' => $post_type]);
return array(
'id' => (int) $post->ID,
'slug' => $post->post_name,
'url' => $post->url,
);
} | [
"public",
"function",
"getContentFromTitle",
"(",
"string",
"$",
"title",
",",
"string",
"$",
"post_type",
"=",
"''",
")",
":",
"array",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"content",
"->",
"get",
"(",
"$",
"title",
",",
"[",
"'by'",
"=>",
"'title'",
",",
"'post_type'",
"=>",
"$",
"post_type",
"]",
")",
";",
"return",
"array",
"(",
"'id'",
"=>",
"(",
"int",
")",
"$",
"post",
"->",
"ID",
",",
"'slug'",
"=>",
"$",
"post",
"->",
"post_name",
",",
"'url'",
"=>",
"$",
"post",
"->",
"url",
",",
")",
";",
"}"
] | Get content from its title.
@param string $title The title of the content to get.
@param string $post_type Post type(s) to consider when searching for the content.
@return array {
@type int $id Content ID.
@type string $slug Content slug.
@type string $url Content url.
} | [
"Get",
"content",
"from",
"its",
"title",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/ContentAwareContextTrait.php#L46-L55 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/ContentAwareContextTrait.php | ContentAwareContextTrait.deleteContent | public function deleteContent(int $content_id, array $args = [])
{
$this->getDriver()->content->delete($content_id, $args);
} | php | public function deleteContent(int $content_id, array $args = [])
{
$this->getDriver()->content->delete($content_id, $args);
} | [
"public",
"function",
"deleteContent",
"(",
"int",
"$",
"content_id",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"content",
"->",
"delete",
"(",
"$",
"content_id",
",",
"$",
"args",
")",
";",
"}"
] | Delete specified content.
@param int $content_id ID of content to delete.
@param array $args Optional. Extra parameters to pass to WordPress. | [
"Delete",
"specified",
"content",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/ContentAwareContextTrait.php#L63-L66 |
paulgibbs/behat-wordpress-extension | src/Context/DashboardContext.php | DashboardContext.iGoToMenuItem | public function iGoToMenuItem(string $item)
{
$adminMenu = $this->admin_page->getMenu();
$adminMenu->clickMenuItem($item);
} | php | public function iGoToMenuItem(string $item)
{
$adminMenu = $this->admin_page->getMenu();
$adminMenu->clickMenuItem($item);
} | [
"public",
"function",
"iGoToMenuItem",
"(",
"string",
"$",
"item",
")",
"{",
"$",
"adminMenu",
"=",
"$",
"this",
"->",
"admin_page",
"->",
"getMenu",
"(",
")",
";",
"$",
"adminMenu",
"->",
"clickMenuItem",
"(",
"$",
"item",
")",
";",
"}"
] | Go to a given screen on the admin menu.
Example: Given I go to the "Users" menu
Example: Given I go to the menu "Settings > Reading"
@Given I go to the menu :item
@Given I go to the :item menu
@param string $item | [
"Go",
"to",
"a",
"given",
"screen",
"on",
"the",
"admin",
"menu",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/DashboardContext.php#L88-L92 |
paulgibbs/behat-wordpress-extension | src/Context/DashboardContext.php | DashboardContext.iShouldSeeMessageThatSays | public function iShouldSeeMessageThatSays(string $type, string $message)
{
$selector = 'div.notice';
if ($type === 'error') {
$selector .= '.error';
} else {
$selector .= '.updated';
}
$this->assertSession()->elementTextContains('css', $selector, $message);
} | php | public function iShouldSeeMessageThatSays(string $type, string $message)
{
$selector = 'div.notice';
if ($type === 'error') {
$selector .= '.error';
} else {
$selector .= '.updated';
}
$this->assertSession()->elementTextContains('css', $selector, $message);
} | [
"public",
"function",
"iShouldSeeMessageThatSays",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"message",
")",
"{",
"$",
"selector",
"=",
"'div.notice'",
";",
"if",
"(",
"$",
"type",
"===",
"'error'",
")",
"{",
"$",
"selector",
".=",
"'.error'",
";",
"}",
"else",
"{",
"$",
"selector",
".=",
"'.updated'",
";",
"}",
"$",
"this",
"->",
"assertSession",
"(",
")",
"->",
"elementTextContains",
"(",
"'css'",
",",
"$",
"selector",
",",
"$",
"message",
")",
";",
"}"
] | Check the specified notification is on-screen.
Example: Then I should see a status message that says "Post published"
@Then /^(?:I|they) should see an? (error|status) message that says "([^"]+)"$/
@param string $type Message type. Either "error" or "status".
@param string $message Text to search for. | [
"Check",
"the",
"specified",
"notification",
"is",
"on",
"-",
"screen",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/DashboardContext.php#L104-L115 |
paulgibbs/behat-wordpress-extension | src/Context/Traits/WidgetAwareContextTrait.php | WidgetAwareContextTrait.addWidgetToSidebar | public function addWidgetToSidebar(string $widget_name, string $sidebar_id, array $args)
{
$this->getDriver()->widget->addToSidebar($widget_name, $sidebar_id, $args);
} | php | public function addWidgetToSidebar(string $widget_name, string $sidebar_id, array $args)
{
$this->getDriver()->widget->addToSidebar($widget_name, $sidebar_id, $args);
} | [
"public",
"function",
"addWidgetToSidebar",
"(",
"string",
"$",
"widget_name",
",",
"string",
"$",
"sidebar_id",
",",
"array",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"widget",
"->",
"addToSidebar",
"(",
"$",
"widget_name",
",",
"$",
"sidebar_id",
",",
"$",
"args",
")",
";",
"}"
] | Adds a widget to the sidebar with the specified arguments.
@param string $widget_name The ID base of the widget (e.g. 'meta', 'calendar'). Case insensitive.
@param string $sidebar_id The ID of the sidebar to the add the widget to.
@param array $args Associative array of widget settings for this widget. | [
"Adds",
"a",
"widget",
"to",
"the",
"sidebar",
"with",
"the",
"specified",
"arguments",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/Traits/WidgetAwareContextTrait.php#L28-L31 |
paulgibbs/behat-wordpress-extension | src/Context/ContextClass/ClassGenerator.php | ClassGenerator.generateClass | public function generateClass(Suite $suite, $context_class)
{
$fqn = $context_class;
$namespace = '';
$pos = strrpos($fqn, '\\');
if ($pos) {
$context_class = substr($fqn, $pos + 1);
$namespace = sprintf('namespace %s;%s', substr($fqn, 0, $pos), PHP_EOL . PHP_EOL);
}
return strtr(
static::$template,
array(
'{namespace}' => $namespace,
'{class_name}' => $context_class,
)
);
} | php | public function generateClass(Suite $suite, $context_class)
{
$fqn = $context_class;
$namespace = '';
$pos = strrpos($fqn, '\\');
if ($pos) {
$context_class = substr($fqn, $pos + 1);
$namespace = sprintf('namespace %s;%s', substr($fqn, 0, $pos), PHP_EOL . PHP_EOL);
}
return strtr(
static::$template,
array(
'{namespace}' => $namespace,
'{class_name}' => $context_class,
)
);
} | [
"public",
"function",
"generateClass",
"(",
"Suite",
"$",
"suite",
",",
"$",
"context_class",
")",
"{",
"$",
"fqn",
"=",
"$",
"context_class",
";",
"$",
"namespace",
"=",
"''",
";",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"fqn",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"pos",
")",
"{",
"$",
"context_class",
"=",
"substr",
"(",
"$",
"fqn",
",",
"$",
"pos",
"+",
"1",
")",
";",
"$",
"namespace",
"=",
"sprintf",
"(",
"'namespace %s;%s'",
",",
"substr",
"(",
"$",
"fqn",
",",
"0",
",",
"$",
"pos",
")",
",",
"PHP_EOL",
".",
"PHP_EOL",
")",
";",
"}",
"return",
"strtr",
"(",
"static",
"::",
"$",
"template",
",",
"array",
"(",
"'{namespace}'",
"=>",
"$",
"namespace",
",",
"'{class_name}'",
"=>",
"$",
"context_class",
",",
")",
")",
";",
"}"
] | Generate context class code.
@param Suite $suite
@param string $context_class
@return string The context class source code. | [
"Generate",
"context",
"class",
"code",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ContextClass/ClassGenerator.php#L61-L79 |
paulgibbs/behat-wordpress-extension | src/Driver/Element/Wpcli/TermElement.php | TermElement.get | public function get($id, $args = [])
{
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $args['taxonomy'], $id, '--format=json');
$term = $this->drivers->getDriver()->wpcli('term', 'get', $wpcli_args)['stdout'];
$term = json_decode($term);
if (! $term) {
throw new UnexpectedValueException(sprintf('[W503] Could not find term with ID %d', $id));
}
return $term;
} | php | public function get($id, $args = [])
{
$wpcli_args = buildCLIArgs(
array(
'field',
'fields',
),
$args
);
array_unshift($wpcli_args, $args['taxonomy'], $id, '--format=json');
$term = $this->drivers->getDriver()->wpcli('term', 'get', $wpcli_args)['stdout'];
$term = json_decode($term);
if (! $term) {
throw new UnexpectedValueException(sprintf('[W503] Could not find term with ID %d', $id));
}
return $term;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"wpcli_args",
"=",
"buildCLIArgs",
"(",
"array",
"(",
"'field'",
",",
"'fields'",
",",
")",
",",
"$",
"args",
")",
";",
"array_unshift",
"(",
"$",
"wpcli_args",
",",
"$",
"args",
"[",
"'taxonomy'",
"]",
",",
"$",
"id",
",",
"'--format=json'",
")",
";",
"$",
"term",
"=",
"$",
"this",
"->",
"drivers",
"->",
"getDriver",
"(",
")",
"->",
"wpcli",
"(",
"'term'",
",",
"'get'",
",",
"$",
"wpcli_args",
")",
"[",
"'stdout'",
"]",
";",
"$",
"term",
"=",
"json_decode",
"(",
"$",
"term",
")",
";",
"if",
"(",
"!",
"$",
"term",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'[W503] Could not find term with ID %d'",
",",
"$",
"id",
")",
")",
";",
"}",
"return",
"$",
"term",
";",
"}"
] | Retrieve an item for this element.
@param int|string $id Object ID.
@param array $args Optional data used to fetch an object.
@throws \UnexpectedValueException
@return mixed The item. | [
"Retrieve",
"an",
"item",
"for",
"this",
"element",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Driver/Element/Wpcli/TermElement.php#L48-L67 |
paulgibbs/behat-wordpress-extension | src/Context/WidgetContext.php | WidgetContext.iHaveTheMetaWidgetIn | public function iHaveTheMetaWidgetIn(string $widget_name, string $sidebar_name, TableNode $widget_settings)
{
$sidebar = $this->getWidgetSidebar($sidebar_name);
$keys = array_map('strtolower', $widget_settings->getRow(0));
$values = $widget_settings->getRow(1); // We only support one widget for now.
$args = array_combine($keys, $values);
$this->addWidgetToSidebar($widget_name, $sidebar, $args);
} | php | public function iHaveTheMetaWidgetIn(string $widget_name, string $sidebar_name, TableNode $widget_settings)
{
$sidebar = $this->getWidgetSidebar($sidebar_name);
$keys = array_map('strtolower', $widget_settings->getRow(0));
$values = $widget_settings->getRow(1); // We only support one widget for now.
$args = array_combine($keys, $values);
$this->addWidgetToSidebar($widget_name, $sidebar, $args);
} | [
"public",
"function",
"iHaveTheMetaWidgetIn",
"(",
"string",
"$",
"widget_name",
",",
"string",
"$",
"sidebar_name",
",",
"TableNode",
"$",
"widget_settings",
")",
"{",
"$",
"sidebar",
"=",
"$",
"this",
"->",
"getWidgetSidebar",
"(",
"$",
"sidebar_name",
")",
";",
"$",
"keys",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"widget_settings",
"->",
"getRow",
"(",
"0",
")",
")",
";",
"$",
"values",
"=",
"$",
"widget_settings",
"->",
"getRow",
"(",
"1",
")",
";",
"// We only support one widget for now.",
"$",
"args",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"values",
")",
";",
"$",
"this",
"->",
"addWidgetToSidebar",
"(",
"$",
"widget_name",
",",
"$",
"sidebar",
",",
"$",
"args",
")",
";",
"}"
] | Adds a widget (identified by its ID base) to the sidebar (identified by it's human-readable name, e.g. 'Widget
Area', 'Right Sidebar', or 'Footer') with the given arguments.
Example: Given I have the "Meta" widget in "Widget Area
Example: Given I have the "RSS" widget in "Widget Area"
| Title | Url | Items |
| My feed | https://wordpress.org/news/feed/ | 3 |
@Given I have the :widget_name widget in :sidebar_name
@param string $widget_name
@param string $sidebar_name
@param TableNode $widget_settings | [
"Adds",
"a",
"widget",
"(",
"identified",
"by",
"its",
"ID",
"base",
")",
"to",
"the",
"sidebar",
"(",
"identified",
"by",
"it",
"s",
"human",
"-",
"readable",
"name",
"e",
".",
"g",
".",
"Widget",
"Area",
"Right",
"Sidebar",
"or",
"Footer",
")",
"with",
"the",
"given",
"arguments",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/WidgetContext.php#L30-L38 |
paulgibbs/behat-wordpress-extension | src/Context/ContentContext.php | ContentContext.thereArePosts | public function thereArePosts(TableNode $posts)
{
foreach ($posts->getHash() as $post) {
$this->createContent($this->parseArgs($post));
}
} | php | public function thereArePosts(TableNode $posts)
{
foreach ($posts->getHash() as $post) {
$this->createContent($this->parseArgs($post));
}
} | [
"public",
"function",
"thereArePosts",
"(",
"TableNode",
"$",
"posts",
")",
"{",
"foreach",
"(",
"$",
"posts",
"->",
"getHash",
"(",
")",
"as",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"createContent",
"(",
"$",
"this",
"->",
"parseArgs",
"(",
"$",
"post",
")",
")",
";",
"}",
"}"
] | Create content of the given type.
Example: Given there are posts:
| post_type | post_title | post_content | post_status |
| page | Test Post | Hello World | publish |
@Given /^(?:there are|there is a) posts?:/
@param TableNode $posts | [
"Create",
"content",
"of",
"the",
"given",
"type",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ContentContext.php#L29-L34 |
paulgibbs/behat-wordpress-extension | src/Context/ContentContext.php | ContentContext.iAmViewingBlogPost | public function iAmViewingBlogPost($post_data_or_title)
{
// Retrieve the first row only.
if ($post_data_or_title instanceof TableNode) {
$post_data_hash = $post_data_or_title->getHash();
if (count($post_data_hash) > 1) {
throw new UnexpectedValueException('[W810] "Given I am viewing a post:" step must only contain one post');
}
$post = $this->createContent($this->parseArgs($post_data_hash[0]));
} else {
$post = $this->getContentFromTitle($post_data_or_title);
}
$this->visitPath($post['url']);
} | php | public function iAmViewingBlogPost($post_data_or_title)
{
// Retrieve the first row only.
if ($post_data_or_title instanceof TableNode) {
$post_data_hash = $post_data_or_title->getHash();
if (count($post_data_hash) > 1) {
throw new UnexpectedValueException('[W810] "Given I am viewing a post:" step must only contain one post');
}
$post = $this->createContent($this->parseArgs($post_data_hash[0]));
} else {
$post = $this->getContentFromTitle($post_data_or_title);
}
$this->visitPath($post['url']);
} | [
"public",
"function",
"iAmViewingBlogPost",
"(",
"$",
"post_data_or_title",
")",
"{",
"// Retrieve the first row only.",
"if",
"(",
"$",
"post_data_or_title",
"instanceof",
"TableNode",
")",
"{",
"$",
"post_data_hash",
"=",
"$",
"post_data_or_title",
"->",
"getHash",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"post_data_hash",
")",
">",
"1",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'[W810] \"Given I am viewing a post:\" step must only contain one post'",
")",
";",
"}",
"$",
"post",
"=",
"$",
"this",
"->",
"createContent",
"(",
"$",
"this",
"->",
"parseArgs",
"(",
"$",
"post_data_hash",
"[",
"0",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"getContentFromTitle",
"(",
"$",
"post_data_or_title",
")",
";",
"}",
"$",
"this",
"->",
"visitPath",
"(",
"$",
"post",
"[",
"'url'",
"]",
")",
";",
"}"
] | Create content, and go to it in the browser.
Example: Given I am viewing a post:
| post_type | post_title | post_content | post_status |
| page | Test Post | Hello World | publish |
Example: Given I am viewing the post: "Test Post"
@Given /^(?:I am|they are) viewing (?:a|the)(?: blog)? post(?: "([^"]+)"|:)/
@param TableNode|string $post_data_or_title
@throws \UnexpectedValueException | [
"Create",
"content",
"and",
"go",
"to",
"it",
"in",
"the",
"browser",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ContentContext.php#L50-L66 |
paulgibbs/behat-wordpress-extension | src/Context/ContentContext.php | ContentContext.iShouldNotBeAbleToViewThePost | public function iShouldNotBeAbleToViewThePost($post_title)
{
try {
$this->getContentFromTitle($post_title);
} catch (UnexpectedValueException $e) {
// This is expected to fail.
return;
}
throw new RuntimeException(sprintf('[W811] Content "%s" exists, but it should not.', $post_title));
} | php | public function iShouldNotBeAbleToViewThePost($post_title)
{
try {
$this->getContentFromTitle($post_title);
} catch (UnexpectedValueException $e) {
// This is expected to fail.
return;
}
throw new RuntimeException(sprintf('[W811] Content "%s" exists, but it should not.', $post_title));
} | [
"public",
"function",
"iShouldNotBeAbleToViewThePost",
"(",
"$",
"post_title",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getContentFromTitle",
"(",
"$",
"post_title",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"// This is expected to fail.",
"return",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'[W811] Content \"%s\" exists, but it should not.'",
",",
"$",
"post_title",
")",
")",
";",
"}"
] | @Then I should not be able to view the post :post_title
@throws RuntimeException | [
"@Then",
"I",
"should",
"not",
"be",
"able",
"to",
"view",
"the",
"post",
":",
"post_title"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/Context/ContentContext.php#L100-L110 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/TinyMCEEditor.php | TinyMCEEditor.setMode | public function setMode(string $mode)
{
if (self::VISUAL === $mode) {
$this->find('css', '#content-tmce')->press();
} else {
$this->find('css', '#content-html')->press();
}
} | php | public function setMode(string $mode)
{
if (self::VISUAL === $mode) {
$this->find('css', '#content-tmce')->press();
} else {
$this->find('css', '#content-html')->press();
}
} | [
"public",
"function",
"setMode",
"(",
"string",
"$",
"mode",
")",
"{",
"if",
"(",
"self",
"::",
"VISUAL",
"===",
"$",
"mode",
")",
"{",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'#content-tmce'",
")",
"->",
"press",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"find",
"(",
"'css'",
",",
"'#content-html'",
")",
"->",
"press",
"(",
")",
";",
"}",
"}"
] | Sets the mode of the WYSIWYG editor.
@param string $mode VISUAL or TEXT. | [
"Sets",
"the",
"mode",
"of",
"the",
"WYSIWYG",
"editor",
"."
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/TinyMCEEditor.php#L33-L40 |
paulgibbs/behat-wordpress-extension | src/PageObject/Element/TinyMCEEditor.php | TinyMCEEditor.setContent | public function setContent(string $content)
{
if (self::VISUAL === $this->getMode()) {
$this->getDriver()->switchToIFrame(self::$wysiwyg_iframe_id);
$this->getDriver()->executeScript(
';document.body.innerHTML = \'<p>' . addslashes(htmlspecialchars($content)) . '</p>\';'
);
$this->getDriver()->switchToIFrame();
} else {
$this->fillField(self::$textarea_id, $content);
}
} | php | public function setContent(string $content)
{
if (self::VISUAL === $this->getMode()) {
$this->getDriver()->switchToIFrame(self::$wysiwyg_iframe_id);
$this->getDriver()->executeScript(
';document.body.innerHTML = \'<p>' . addslashes(htmlspecialchars($content)) . '</p>\';'
);
$this->getDriver()->switchToIFrame();
} else {
$this->fillField(self::$textarea_id, $content);
}
} | [
"public",
"function",
"setContent",
"(",
"string",
"$",
"content",
")",
"{",
"if",
"(",
"self",
"::",
"VISUAL",
"===",
"$",
"this",
"->",
"getMode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"switchToIFrame",
"(",
"self",
"::",
"$",
"wysiwyg_iframe_id",
")",
";",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"executeScript",
"(",
"';document.body.innerHTML = \\'<p>'",
".",
"addslashes",
"(",
"htmlspecialchars",
"(",
"$",
"content",
")",
")",
".",
"'</p>\\';'",
")",
";",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"switchToIFrame",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fillField",
"(",
"self",
"::",
"$",
"textarea_id",
",",
"$",
"content",
")",
";",
"}",
"}"
] | Enter the given content into the WYSIWYG editor
@param string $content The content being entered | [
"Enter",
"the",
"given",
"content",
"into",
"the",
"WYSIWYG",
"editor"
] | train | https://github.com/paulgibbs/behat-wordpress-extension/blob/a5262e58510c8900ac165b91adb861adb8398774/src/PageObject/Element/TinyMCEEditor.php#L57-L68 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.