Skip to content

Commit

Permalink
Enable and fix PHPUnit integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Jan 17, 2023
1 parent 595c1fe commit 2daa3bb
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 135 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ jobs:
OC_PASS: test
run: |
mkdir data
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ user:add --password-from-env --display-name="Test Displayname" test
./occ user:add --password-from-env --display-name="User No. 1" user1
./occ app:enable --force ${{ env.APP_NAME }}
php -S localhost:8080 &
Expand Down Expand Up @@ -141,8 +142,9 @@ jobs:
OC_PASS: test
run: |
mkdir data
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ user:add --password-from-env --display-name="Test Displayname" test
./occ user:add --password-from-env --display-name="User No. 1" user1
./occ app:enable --force ${{ env.APP_NAME }}
php -S localhost:8080 &
Expand Down Expand Up @@ -209,8 +211,9 @@ jobs:
OC_PASS: test
run: |
mkdir data
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
./occ user:add --password-from-env --display-name="Test Displayname" test
./occ user:add --password-from-env --display-name="User No. 1" user1
./occ app:enable --force ${{ env.APP_NAME }}
php -S localhost:8080 &
Expand Down Expand Up @@ -273,9 +276,10 @@ jobs:
run: |
mkdir data
./occ maintenance:install --verbose --database=oci --database-name=XE --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=autotest --database-pass=owncloud --admin-user admin --admin-pass admin
php -f index.php
./occ user:add --password-from-env --display-name="Test Displayname" test
./occ user:add --password-from-env --display-name="User No. 1" user1
./occ app:enable --force ${{ env.APP_NAME }}
php -S localhost:8080 &
- name: PHPUnit
working-directory: apps/${{ env.APP_NAME }}
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ public function newForm(): DataResponse {
]);
$form->setSubmitMultiple(false);
$form->setShowExpiration(false);
$form->setExpires(0);
$form->setIsAnonymous(false);

$this->formMapper->insert($form);

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function read(): array {
'id' => $this->getId(),
'submissionId' => $this->getSubmissionId(),
'questionId' => $this->getQuestionId(),
'text' => htmlspecialchars_decode($this->getText()),
'text' => (string)$this->getText(),
];
}
}
12 changes: 6 additions & 6 deletions lib/Db/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public function read() {
return [
'id' => $this->getId(),
'hash' => $this->getHash(),
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'title' => (string)$this->getTitle(),
'description' => (string)$this->getDescription(),
'ownerId' => $this->getOwnerId(),
'created' => $this->getCreated(),
'access' => $this->getAccess(),
'expires' => $this->getExpires(),
'isAnonymous' => $this->getIsAnonymous(),
'submitMultiple' => $this->getSubmitMultiple(),
'showExpiration' => $this->getShowExpiration()
'expires' => (int)$this->getExpires(),
'isAnonymous' => (bool)$this->getIsAnonymous(),
'submitMultiple' => (bool)$this->getSubmitMultiple(),
'showExpiration' => (bool)$this->getShowExpiration()
];
}
}
2 changes: 1 addition & 1 deletion lib/Db/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function read(): array {
return [
'id' => $this->getId(),
'questionId' => $this->getQuestionId(),
'text' => htmlspecialchars_decode($this->getText()),
'text' => (string)$this->getText(),
];
}
}
3 changes: 2 additions & 1 deletion lib/Db/OptionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function findByQuestion(int $questionId): array {
->from($this->getTableName())
->where(
$qb->expr()->eq('question_id', $qb->createNamedParameter($questionId))
);
)
->orderBy('id');

return $this->findEntities($qb);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Db/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public function read(): array {
return [
'id' => $this->getId(),
'formId' => $this->getFormId(),
'order' => $this->getOrder(),
'type' => htmlspecialchars_decode($this->getType()),
'isRequired' => $this->getIsRequired(),
'text' => htmlspecialchars_decode($this->getText()),
'description' => htmlspecialchars_decode($this->getDescription()),
'order' => (int)$this->getOrder(),
'type' => $this->getType(),
'isRequired' => (bool)$this->getIsRequired(),
'text' => (string)$this->getText(),
'description' => (string)$this->getDescription(),
'extraSettings' => $this->getExtraSettings(),
];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function read(): array {
return [
'id' => $this->getId(),
'formId' => $this->getFormId(),
'shareType' => $this->getShareType(),
'shareType' => (int)$this->getShareType(),
'shareWith' => $this->getShareWith(),
];
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Migration/Version010200Date20200323141300.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'length' => 64,
]);
$table->addColumn('title', Types::STRING, [
'notnull' => true,
'notnull' => false,
'length' => 256,
]);
$table->addColumn('description', Types::TEXT, [
Expand Down Expand Up @@ -131,7 +131,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'notnull' => true,
]);
$table->addColumn('order', Types::INTEGER, [
'notnull' => true,
'notnull' => false,
'default' => 1,
]);
$table->addColumn('type', Types::STRING, [
Expand All @@ -143,7 +143,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'default' => 0,
]);
$table->addColumn('text', Types::STRING, [
'notnull' => true,
'notnull' => false,
'length' => 2048,
]);
$table->setPrimaryKey(['id']);
Expand All @@ -159,7 +159,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'notnull' => true,
]);
$table->addColumn('text', Types::STRING, [
'notnull' => true,
'notnull' => false,
'length' => 1024,
]);
$table->setPrimaryKey(['id']);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'notnull' => true,
]);
$table->addColumn('text', Types::TEXT, [
'notnull' => true,
'notnull' => false,
'length' => 4096,
]);
$table->setPrimaryKey(['id']);
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version030000Date20211206213004.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'notnull' => true,
]);
$table->addColumn('share_type', Types::SMALLINT, [
'notnull' => true,
'notnull' => false,
]);
$table->addColumn('share_with', Types::STRING, [
'length' => 256,
Expand Down
67 changes: 67 additions & 0 deletions lib/Migration/Version030100Date20230115214242.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Jonas Rittershofer <[email protected]>
*
* @author Joas Schilling <[email protected]>
* @author Jonas Rittershofer <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Forms\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version030100Date20230115214242 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$result = $this->ensureColumnIsNullable($schema, 'forms_v2_answers', 'text');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_forms', 'title');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_options', 'text');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_questions', 'order');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_questions', 'text');
$result |= $this->ensureColumnIsNullable($schema, 'forms_v2_shares', 'share_type');

return $result ? $schema : null;
}

protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
$table = $schema->getTable($tableName);
$column = $table->getColumn($columnName);

if ($column->getNotnull()) {
$column->setNotnull(false);
return true;
}

return false;
}
}
Loading

0 comments on commit 2daa3bb

Please sign in to comment.