/** * @param FunctionalTester\UserSteps $I * * @actor FunctionalTester\UserSteps * * @return void */ public function exportByTags(FunctionalTester\UserSteps $I) { $I->am('Admin User'); $I->wantTo('Export a project issues by tag into CSV file'); list($manager, $project, $issues1, $issues2, $developer) = $this->_createData($I, true); $I->login($manager->email, '123', $manager->firstname); // Add tag to issues1 $I->sendAjaxGetRequest($I->getApplication()->url->action('Administration\\TagsController@getTags', ['term' => 'f'])); $tags = new Collection((array) $I->getJsonResponseContent()); $tags = $tags->filter(function ($tag) use($I) { return strpos(strtolower($tag->label), ':feature') !== false; }); array_walk($issues1, function ($issue) use($I, $tags) { foreach ($tags as $tag) { $issue->tags()->save(Tag::find($tag->value)); } }); $this->_exportIssues($I, $project, ['assignto' => $developer->id, 'tags' => $tags->implode('value', ',')]); $this->_downloadExport($I, $project); $this->_assertExport($I, $project, $issues1, $issues2); }
/** * Create new tags from a string "group:tag_name" and fetch tag from a tag id. * * @param array $tags * @param bool $isAdmin * * @return Collection */ protected function createTags(array $tags, $isAdmin = false) { $newTags = new Collection($tags); // Transform the user input tags into tag objects $newTags->transform(function ($tagNameOrId) use($isAdmin) { if (strpos($tagNameOrId, ':') !== false && $isAdmin) { return (new Tag())->createTagFromString($tagNameOrId); } else { return Tag::find($tagNameOrId); } }); // Filter out invalid tags entered by the user $newTags = $newTags->filter(function ($tag) { return $tag instanceof Tag; }); return $newTags; }