public function CircleBuildHookTest::testDeploymentInfo in Build Hooks 3.x
Same name and namespace in other branches
- 8.2 modules/build_hooks_circleci/tests/src/Kernel/CircleBuildHookTest.php \Drupal\Tests\build_hooks_circleci\Kernel\CircleBuildHookTest::testDeploymentInfo()
Tests deployment info.
File
- modules/
build_hooks_circleci/ tests/ src/ Kernel/ CircleBuildHookTest.php, line 103
Class
- CircleBuildHookTest
- Defines a class for testing circle CI build hooks module.
Namespace
Drupal\Tests\build_hooks_circleci\KernelCode
public function testDeploymentInfo() {
$directory = dirname(__FILE__, 3) . '/fixtures';
$this
->mockClient(new Response('200', [], file_get_contents($directory . '/builds.json')), new Response('200', [], file_get_contents($directory . '/workflow-1.json')), new Response('200', [], file_get_contents($directory . '/workflow-2.json')), new Response('200', [], file_get_contents($directory . '/workflow-3.json')), new Response('200', [], file_get_contents($directory . '/workflow-4.json')), new Response('200', [], file_get_contents($directory . '/workflow-5.json')), new Response('200', [], file_get_contents($directory . '/builds.json')), new Response('500', [], json_encode([])), new Response('500', [], json_encode([])), new Response('500', [], json_encode([])), new Response('500', [], json_encode([])), new Response('500', [], json_encode([])), new Response('500', [], json_encode([])));
$title = $this
->randomMachineName();
/** @var \Drupal\build_hooks\Entity\FrontendEnvironment $environment */
$project = 'foo/bar';
$environment = FrontendEnvironment::create([
'id' => 'foo',
'label' => $title,
'settings' => [
'provider' => 'build_hooks_circleci',
'project' => $project,
'type' => 'branch',
'reference' => 'master',
'parameters' => [],
'token' => '12345678910',
],
'plugin' => 'circleciv2',
'deployment_strategy' => Trigger::DEPLOYMENT_STRATEGY_CRON,
]);
$environment
->save();
/** @var \Drupal\build_hooks\Plugin\FrontendEnvironmentInterface $plugin */
$plugin = $environment
->getPlugin();
$extra = $plugin
->getAdditionalDeployFormElements(new FormState())['builds'];
$expected_url = 'https://circleci.com/api/v2/project/gh/' . $project . '/pipeline/mine?branch=master';
$request = reset($this->history)['request'];
$this
->assertEquals($expected_url, (string) $request
->getUri());
$this
->assertEquals('table', $extra['#type']);
$this
->assertCount(5, $extra['#rows']);
$row = reset($extra['#rows']);
$this
->assertEquals('https://app.circleci.com/pipelines/github/foo/bar/57/workflows/1be799d9-4607-4a48-8bc4-27b9dbcb0958', $row[3]['data']['#url']
->toString());
$this
->assertEquals('Success', $row[2]);
$this
->assertEquals('Canceled', end($extra['#rows'])[2]);
// Now with error handling - workflows fail.
$extra = $plugin
->getAdditionalDeployFormElements(new FormState())['builds'];
foreach ($extra['#rows'] as $row) {
$this
->assertEquals('Could not get workflows', $row[2]);
}
// Now with error handling - jobs fail.
$extra = $plugin
->getAdditionalDeployFormElements(new FormState());
$this
->assertEquals('Could not get list of recent builds', (string) $extra['error']['#markup']);
}