Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vote V1.12.1 - update #902

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/modules/vote/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Config extends \Ilch\Config\Install
{
public $config = [
'key' => 'vote',
'version' => '1.12.0',
'version' => '1.12.1',
'icon_small' => 'fa-solid fa-bars-progress',
'author' => 'Veldscholten, Kevin',
'link' => 'https://ilch.de',
Expand Down
4 changes: 2 additions & 2 deletions application/modules/vote/mappers/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getEntriesBy(array $where = [], array $orderBy = [], ?\Ilch\Pagi
$select->fields(['p.id', 'p.question', 'p.key', 'p.groups', 'p.status', 'p.read_access_all', 'p.multiple_reply'])
->from(['p' => $this->tablename])
->join(['ra' => $this->tablenameReadAcces], 'p.id = ra.poll_id', 'LEFT', ['read_access' => 'GROUP_CONCAT(ra.group_id)'])
->where(array_merge($where, ($read_access ? [$select->orX(['ra.read_access' => $read_access, 'p.read_access_all' => '1'])] : [])))
->where(array_merge($where, ($read_access ? [$select->orX(['ra.group_id' => $read_access, 'p.read_access_all' => '1'])] : [])))
->order($orderBy)
->group(['p.id']);

Expand Down Expand Up @@ -97,7 +97,7 @@ public function getVotes(array $where = [], $readAccess = '3'): ?array
$readAccess = explode(',', $readAccess);
}

return $this->getEntriesBy(array_merge($where, ($readAccess ? ['ra.group_id' => $readAccess] : [])), ['p.id' => 'DESC']);
return $this->getEntriesBy(array_merge($where, ($readAccess ? ['ra.read_access' => $readAccess] : [])), ['p.id' => 'DESC']);
}

/**
Expand Down
156 changes: 156 additions & 0 deletions tests/modules/vote/_files/mysql_database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
users:
-
id: 1
name: "admin"
-
id: 2
name: "User"

groups:
-
id: 1
name: "Admin"
-
id: 2
name: "User"
-
id: 3
name: "Guest"

poll:
-
id: 1
question: "Frage 1"
groups: "2"
status: 0
read_access_all: 0
multiple_reply: 0
-
id: 2
question: "Frage 2"
groups: "2"
status: 1
read_access_all: 0
multiple_reply: 0
-
id: 3
question: "Frage 3"
groups: "2"
status: 0
read_access_all: 1
multiple_reply: 0
-
id: 4
question: "Frage 4"
groups: "1"
status: 0
read_access_all: 0
multiple_reply: 0
-
id: 5
question: "Frage 5"
groups: "1"
status: 0
read_access_all: 0
multiple_reply: 1

poll_access:
-
poll_id: 1
group_id: 1
-
poll_id: 1
group_id: 2
-
poll_id: 1
group_id: 3
-
poll_id: 2
group_id: 1
-
poll_id: 2
group_id: 2
-
poll_id: 3
group_id: 1
-
poll_id: 3
group_id: 2
-
poll_id: 3
group_id: 3
-
poll_id: 4
group_id: 1
-
poll_id: 4
group_id: 2
-
poll_id: 5
group_id: 1
-
poll_id: 5
group_id: 2
-
poll_id: 5
group_id: 3

poll_res:
-
poll_id: 1
reply: "Antwort 1.1"
result: 0
-
poll_id: 1
reply: "Antwort 1.2"
result: 1
-
poll_id: 2
reply: "Antwort 2.1"
result: 1
-
poll_id: 2
reply: "Antwort 2.2"
result: 2
-
poll_id: 3
reply: "Antwort 3.1"
result: 0
-
poll_id: 3
reply: "Antwort 3.2"
result: 0
-
poll_id: 4
reply: "Antwort 4.1"
result: 0
-
poll_id: 4
reply: "Antwort 4.2"
result: 0
-
poll_id: 5
reply: "Antwort 5.1"
result: 0
-
poll_id: 5
reply: "Antwort 5.2"
result: 0

poll_ip:
-
poll_id: 1
ip: "192.168.10.100"
user_id: 0
-
poll_id: 2
ip: "192.168.10.101"
user_id: 1
-
poll_id: 2
ip: "192.168.10.102"
user_id: 0
-
poll_id: 2
ip: "192.168.10.100"
user_id: 0
116 changes: 116 additions & 0 deletions tests/modules/vote/mappers/IpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/**
* @copyright Ilch 2
* @package ilch_phpunit
*/

namespace Modules\Vote\Mappers;

use PHPUnit\Ilch\DatabaseTestCase;
use PHPUnit\Ilch\PhpunitDataset;
use Modules\Vote\Config\Config as ModuleConfig;
use Modules\User\Config\Config as UserConfig;
use Modules\Admin\Config\Config as AdminConfig;
use Modules\Vote\Mappers\Ip as IpMapper;
use Modules\Vote\Models\Ip as EntriesModel;

/**
* @package ilch_phpunit
*/
class IpTest extends DatabaseTestCase
{
protected $phpunitDataset;
/** @var IpMapper $mapper */
private $mapper;

public function setUp(): void
{
parent::setUp();
$this->phpunitDataset = new PhpunitDataset($this->db);
$this->phpunitDataset->loadFromFile(__DIR__ . '/../_files/mysql_database.yml');

$this->mapper = new IpMapper();

self::assertTrue($this->mapper->checkDB());
}

/**
* All test routines
*/
public function testVoteIpgetAllRows()
{
$entries = $this->mapper->getEntriesBy();

self::assertCount(4, $entries);
}

public function testgetVoteIp()
blackcoder87 marked this conversation as resolved.
Show resolved Hide resolved
{
$entries = $this->mapper->getEntriesBy();

self::assertCount(4, $entries);

$i = 0;
/** @var EntriesModel $entry */
$entry = $entries[$i];
self::assertEquals(1, $entry->getPollId());
self::assertEquals('192.168.10.100', $entry->getIP());
self::assertEquals(0, $entry->getUserId());

$i++;
$entry = $entries[$i];
self::assertEquals(2, $entry->getPollId());
self::assertEquals('192.168.10.101', $entry->getIP());
self::assertEquals(1, $entry->getUserId());

$i++;
$entry = $entries[$i];
self::assertEquals(2, $entry->getPollId());
self::assertEquals('192.168.10.102', $entry->getIP());
self::assertEquals(0, $entry->getUserId());

$i++;
$entry = $entries[$i];
self::assertEquals(2, $entry->getPollId());
self::assertEquals('192.168.10.100', $entry->getIP());
self::assertEquals(0, $entry->getUserId());
}

public function testsaveNewVoteIp()
{
$model = new EntriesModel();
$model->setIP('192.168.10.110');
$model->setUserId(2);
$model->setPollId(1);
$this->mapper->saveIP($model);

$entry = $this->mapper->getIP(1, '192.168.10.110');

self::assertNotNull($entry);
self::assertEquals($model->getIP(), $entry->getIP());
self::assertEquals($model->getUserId(), $entry->getUserId());
self::assertEquals($model->getPollId(), $entry->getPollId());

$entry = $this->mapper->getVotedUser(1, 2);

self::assertNotNull($entry);
self::assertEquals($model->getIP(), $entry->getIP());
self::assertEquals($model->getUserId(), $entry->getUserId());
self::assertEquals($model->getPollId(), $entry->getPollId());
}

/**
* Returns database schema sql statements to initialize database
*
* @return string
*/
protected static function getSchemaSQLQueries(): string
{
$config = new ModuleConfig();
$configUser = new UserConfig();
$configAdmin = new AdminConfig();

return $configAdmin->getInstallSql() . $configUser->getInstallSql() . $config->getInstallSql();
}
}
Loading