-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
998cdf8
commit c95cd5b
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Acquia\Cli\Tests\Commands; | ||
|
||
use Acquia\Cli\Command\App\LinkCommand; | ||
use Acquia\Cli\Command\CommandBase; | ||
use Acquia\Cli\Command\Self\TelemetryCommand; | ||
use Acquia\Cli\Helpers\DataStoreContract; | ||
use Acquia\Cli\Tests\CommandTestBase; | ||
use Symfony\Component\Filesystem\Path; | ||
|
||
/** | ||
* @property \Acquia\Cli\Command\Self\TelemetryCommand $command | ||
*/ | ||
class TelemetryCommandTest extends CommandTestBase { | ||
|
||
protected string $legacyAcliConfigFilepath; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
$this->legacyAcliConfigFilepath = Path::join($this->dataDir, 'acquia-cli.json'); | ||
$this->fs->remove($this->legacyAcliConfigFilepath); | ||
} | ||
|
||
/**b | ||
*/ | ||
protected function createCommand(): CommandBase { | ||
return $this->injectCommand(TelemetryCommand::class); | ||
} | ||
|
||
/** | ||
* @group brokenProphecy | ||
*/ | ||
public function testTelemetryCommand(): void { | ||
$this->mockRequest('getAccount'); | ||
$this->executeCommand(); | ||
$output = $this->getDisplay(); | ||
$this->assertStringContainsString('Telemetry has been enabled.', $output); | ||
$this->executeCommand(); | ||
$output = $this->getDisplay(); | ||
$this->assertStringContainsString('Telemetry has been disabled.', $output); | ||
} | ||
|
||
/** | ||
* @return string[][] | ||
*/ | ||
public function providerTestTelemetryPrompt(): array { | ||
return [ | ||
[ | ||
// Would you like to share anonymous performance usage and data? | ||
['n'], | ||
'Ok, no data will be collected and shared with us.', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Tests telemetry prompt. | ||
* | ||
* @dataProvider providerTestTelemetryPrompt | ||
* @param $message | ||
*/ | ||
public function testTelemetryPrompt(array $inputs, mixed $message): void { | ||
$this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => NULL]; | ||
$this->createMockConfigFiles(); | ||
$this->createMockAcliConfigFile('a47ac10b-58cc-4372-a567-0e02b2c3d470'); | ||
$this->createDataStores(); | ||
$this->mockApplicationRequest(); | ||
$this->command = $this->injectCommand(LinkCommand::class); | ||
$this->executeCommand([], $inputs); | ||
$output = $this->getDisplay(); | ||
|
||
$this->assertStringContainsString('Would you like to share anonymous performance usage and data?', $output); | ||
$this->assertStringContainsString($message, $output); | ||
} | ||
|
||
/** | ||
* Opted out by default. | ||
*/ | ||
public function testAmplitudeDisabled(): void { | ||
$this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => FALSE]; | ||
$this->createMockConfigFiles(); | ||
$this->executeCommand(); | ||
|
||
$this->assertEquals(0, $this->getStatusCode()); | ||
|
||
} | ||
|
||
public function testMigrateLegacyTelemetryPreference(): void { | ||
$this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => NULL]; | ||
$this->createMockConfigFiles(); | ||
$this->fs->remove($this->legacyAcliConfigFilepath); | ||
$legacyAcliConfig = ['send_telemetry' => FALSE]; | ||
$contents = json_encode($legacyAcliConfig); | ||
$this->fs->dumpFile($this->legacyAcliConfigFilepath, $contents); | ||
$this->executeCommand(); | ||
|
||
$this->assertEquals(0, $this->getStatusCode()); | ||
$this->fs->remove($this->legacyAcliConfigFilepath); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
tests/phpunit/src/Commands/TelemetryDisableCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Acquia\Cli\Tests\Commands; | ||
|
||
use Acquia\Cli\Command\CommandBase; | ||
use Acquia\Cli\Command\Self\TelemetryDisableCommand; | ||
use Acquia\Cli\Tests\CommandTestBase; | ||
|
||
/** | ||
* @property \Acquia\Cli\Command\Self\TelemetryDisableCommand $command | ||
*/ | ||
class TelemetryDisableCommandTest extends CommandTestBase { | ||
|
||
protected function createCommand(): CommandBase { | ||
return $this->injectCommand(TelemetryDisableCommand::class); | ||
} | ||
|
||
public function testTelemetryDisableCommand(): void { | ||
$this->executeCommand(); | ||
$output = $this->getDisplay(); | ||
$this->assertStringContainsString('Telemetry has been disabled.', $output); | ||
|
||
$settings = json_decode(file_get_contents($this->cloudConfigFilepath), TRUE); | ||
$this->assertFalse($settings['send_telemetry']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Acquia\Cli\Tests\Commands; | ||
|
||
use Acquia\Cli\Command\CommandBase; | ||
use Acquia\Cli\Command\Self\TelemetryEnableCommand; | ||
use Acquia\Cli\Tests\CommandTestBase; | ||
|
||
/** | ||
* @property \Acquia\Cli\Command\Self\TelemetryEnableCommand $command | ||
*/ | ||
class TelemetryEnableCommandTest extends CommandTestBase { | ||
|
||
/**b | ||
*/ | ||
protected function createCommand(): CommandBase { | ||
return $this->injectCommand(TelemetryEnableCommand::class); | ||
} | ||
|
||
public function testTelemetryEnableCommand(): void { | ||
$this->executeCommand(); | ||
$output = $this->getDisplay(); | ||
$this->assertStringContainsString('Telemetry has been enabled.', $output); | ||
|
||
$settings = json_decode(file_get_contents($this->cloudConfigFilepath), TRUE); | ||
$this->assertTrue($settings['send_telemetry']); | ||
} | ||
|
||
} |