1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CoreAdminHome\tests\Integration\Commands;
use Piwik\Container\StaticContainer;
use Piwik\DataAccess\RawLogDao;
use Piwik\Tests\Fixtures\ManySitesImportedLogs;
use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase;
/**
* @group Core
*/
class DeleteLogsDataTest extends ConsoleCommandTestCase
{
/**
* @var ManySitesImportedLogs
*/
public static $fixture;
/**
* @dataProvider getTestDataForInvalidDateRangeTest
*/
public function testCommandFailsWhenInvalidDateRangeSupplied($dateRange)
{
$this->applicationTester->setInputs(["N\n"]);
$result = $this->applicationTester->run(array(
'command' => 'core:delete-logs-data',
'--dates' => $dateRange,
'--idsite' => self::$fixture->idSite,
'-vvv' => true,
));
$this->assertNotEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
self::assertStringContainsString('Invalid date range supplied', $this->applicationTester->getDisplay());
}
public function getTestDataForInvalidDateRangeTest()
{
return array(
array('completegarbage'),
array('2012-01-01,garbage'),
array('garbage,2012-01-01'),
array('2012-02-01,2012-01-01'), // first date is older than the last date
array(','),
);
}
public function testCommandFailsWhenInvalidSiteIdSupplied()
{
$this->applicationTester->setInputs(["N\n"]);
$result = $this->applicationTester->run(array(
'command' => 'core:delete-logs-data',
'--dates' => '2012-01-01,2012-01-02',
'--idsite' => 43,
'-vvv' => true,
));
$this->assertNotEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
self::assertStringContainsString('Invalid site ID', $this->applicationTester->getDisplay());
}
/**
* @dataProvider getTestDataForInvalidIterationStepTest
*/
public function testCommandFailsWhenInvalidIterationStepSupplied($limit)
{
$this->applicationTester->setInputs(["N\n"]);
$result = $this->applicationTester->run(array(
'command' => 'core:delete-logs-data',
'--dates' => '2012-01-01,2012-01-02',
'--idsite' => self::$fixture->idSite,
'--limit' => $limit,
'-vvv' => true,
));
$this->assertNotEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
self::assertStringContainsString('Invalid row limit supplied', $this->applicationTester->getDisplay());
}
public function getTestDataForInvalidIterationStepTest()
{
return array(
array(0),
array(-45),
);
}
public function testCommandSkipsLogDeletionIfUserDoesNotConfirm()
{
$this->applicationTester->setInputs(["N\n"]);
$dateRange = '2012-08-09,2012-08-11';
$this->assertVisitsFoundInLogs($dateRange);
$result = $this->applicationTester->run(array(
'command' => 'core:delete-logs-data',
'--dates' => $dateRange,
'--idsite' => self::$fixture->idSite,
'-vvv' => true,
));
$this->assertEquals(1, $result, $this->getCommandDisplayOutputErrorMessage());
$this->assertNotRegExp("/Successfully deleted [0-9]+ rows from all log tables/", $this->applicationTester->getDisplay());
}
public function testCommandCorrectlyDeletesRequestedLogFiles()
{
$this->applicationTester->setInputs(["Y\n"]);
$dateRange = '2012-08-09,2012-08-11';
$this->assertVisitsFoundInLogs($dateRange);
$options = array('interactive' => true);
$result = $this->applicationTester->run(array(
'command' => 'core:delete-logs-data',
'--dates' => $dateRange,
'--idsite' => self::$fixture->idSite,
'-vvv' => true,
), $options);
$this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
self::assertStringContainsString("Successfully deleted 19 visits", $this->applicationTester->getDisplay());
}
protected function assertVisitsFoundInLogs($dateRange)
{
list($from, $to) = explode(",", $dateRange);
/** @var RawLogDao $dao */
$dao = StaticContainer::get('Piwik\DataAccess\RawLogDao');
$this->assertNotEmpty($dao->countVisitsWithDatesLimit($from, $to));
}
}
DeleteLogsDataTest::$fixture = new ManySitesImportedLogs();
|