56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
namespace Xxx\Tests\Unit;
|
|
|
|
use Xxx\Tests\Support\FakeDb;
|
|
use Xxx\Tests\Support\SiteData;
|
|
use Xxx\Tests\Support\TestCase;
|
|
|
|
// delete_story() in publish/post.lib.php
|
|
class DeleteStoryTest extends TestCase {
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
SiteData::install(array('xxx' => array(array('id' => 1), array('id' => 2)),
|
|
'queue' => array(array('id' => 1), array('id' => 3))));
|
|
open_db('open');
|
|
}
|
|
|
|
private function ids(string $table): array {
|
|
return array_map('intval', array_column(SiteData::$tables[$table], 'id'));
|
|
}
|
|
|
|
public function testVisitorsCannotDelete(): void {
|
|
$this->assertSame('', delete_story(1));
|
|
$this->assertSame(array(), FakeDb::matching('/^DELETE/'));
|
|
}
|
|
|
|
public function testEditorsDeleteFromTheLiveTable(): void {
|
|
$this->asEditor();
|
|
$this->assertSame('Article has been deleted.', delete_story(1));
|
|
$this->assertSame(array(2), $this->ids('xxx'));
|
|
$this->assertSame(array(1, 3), $this->ids('queue'));
|
|
}
|
|
|
|
public function testEditorsDeleteFromTheQueue(): void {
|
|
$this->asEditor();
|
|
$this->request(array('queue' => '1'));
|
|
$this->assertSame('Article has been deleted.', delete_story(3));
|
|
$this->assertSame(array(1), $this->ids('queue'));
|
|
$this->assertSame(array(1, 2), $this->ids('xxx'));
|
|
}
|
|
|
|
public function testAMoveDeletesTheQueueCopyQuietly(): void {
|
|
$this->asEditor();
|
|
$this->assertSame('', delete_story(1, TRUE));
|
|
$this->assertSame(array(3), $this->ids('queue'));
|
|
$this->assertSame(array(1, 2), $this->ids('xxx'));
|
|
}
|
|
|
|
public function testTheIdIsBoundAsAnInteger(): void {
|
|
$this->asEditor();
|
|
delete_story('2 OR 1=1');
|
|
$query = FakeDb::matching('/^DELETE/')[0];
|
|
$this->assertSame('DELETE FROM xxx WHERE `id` = ? LIMIT 1', $query['sql']);
|
|
$this->assertSame(array(2), $query['params']);
|
|
}
|
|
}
|