Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fixed bug when unedited Document saved
Browse files Browse the repository at this point in the history
  • Loading branch information
githubjeka committed Jul 5, 2018
1 parent 3a6a64c commit 68c0472
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion models/DocumentFileEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function moveToNewCategory()
$fromPath = $this->fromPath;
$toPath = $this->toPath;

if ($toPath === null || $fromPath === null) {
if ($toPath === null || $fromPath === null || $toPath === $fromPath) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"workflow",
"documents"
],
"version": "0.1.4dev",
"version": "0.1.5",
"humhub": {
"minVersion": "1.2.7"
},
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/data/documents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
return [
'default' => [
'name' => 'Document for edit',
'number' => '1333-e',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit....',
'created_by' => 1,
'created_at' => time(),
'registered_at' => strtotime('2017-08-14'),
'from' => 'Store',
'to' => 'Office',
'category' => 1,
'type' => 1,
],
];
31 changes: 31 additions & 0 deletions tests/unit/DocumentFileEntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace tracker\tests\unit;

use tracker\models\Document;
use tracker\models\DocumentFileEntity;
use tracker\tests\fixtures\DocumentFixture;

/**
* @author Evgeniy Tkachenko <[email protected]>
* @property \tracker\UnitTester tester
*/
class DocumentFileEntityTest extends \Codeception\Test\Unit
{
public function testMoveToNewCategory()
{
$this->tester->haveFixtures([
'documents' => [
'class' => DocumentFixture::class,
'dataFile' => '@tracker/tests/fixtures/data/documents.php'
]
]);

/** @var Document $defaultDocument */
$defaultDocument = $this->tester->grabFixture('documents', 'default');

$file = new DocumentFileEntity($defaultDocument);

$this->assertTrue($file->moveToNewCategory());
}
}
39 changes: 16 additions & 23 deletions tests/unit/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function mkdir()
use tracker\models\Document;
use tracker\models\DocumentFileEntity;
use tracker\tests\fixtures\DocumentFileFixture;
use tracker\tests\fixtures\DocumentFixture;

/**
* @author Evgeniy Tkachenko <[email protected]>
Expand Down Expand Up @@ -145,38 +146,30 @@ public function testWorkWithCreator()

public function testWorkWithEditor()
{
$defaultAttributes = [
'name' => 'Document for edit',
'number' => '1333-e',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit....',
'created_by' => 1,
'created_at' => time(),
'registered_at' => strtotime('2017-08-14'),
'from' => 'Store',
'to' => 'Office',
'category' => 1,
'type' => 1,
];
$this->tester->haveFixtures([
'documents' => [
'class' => DocumentFixture::class,
'dataFile' => '@tracker/tests/fixtures/data/documents.php'
]
]);

$this->tester->dontSeeRecord(Document::class, ['name' => $defaultAttributes['name']]);
$this->tester->haveRecord(Document::class, $defaultAttributes);
$this->tester->seeRecord(Document::class, ['name' => $defaultAttributes['name']]);
/** @var Document $defaultDocument */
$defaultDocument = $this->tester->grabFixture('documents', 'default');

$defaultDocument = Document::find()->where(['name' => $defaultAttributes['name']])->one();
$documentEditor = new DocumentEditor($defaultDocument);

$requestModel = $documentEditor->getDocumentForm();

$this->assertEquals($defaultAttributes['name'], $requestModel->name);
$this->assertEquals($defaultAttributes['description'], $requestModel->description);
$this->assertEquals($defaultAttributes['registered_at'],
$this->assertEquals($defaultDocument['name'], $requestModel->name);
$this->assertEquals($defaultDocument['description'], $requestModel->description);
$this->assertEquals($defaultDocument['registered_at'],
date_create_from_format('Y-m-d', $requestModel->registeredAt)
->setTime(0, 0)
->format('U'));
$this->assertEquals($defaultAttributes['from'], $requestModel->from);
$this->assertEquals($defaultAttributes['to'], $requestModel->to);
$this->assertEquals($defaultAttributes['type'], $requestModel->type);
$this->assertEquals($defaultAttributes['category'], $requestModel->category);
$this->assertEquals($defaultDocument['from'], $requestModel->from);
$this->assertEquals($defaultDocument['to'], $requestModel->to);
$this->assertEquals($defaultDocument['type'], $requestModel->type);
$this->assertEquals($defaultDocument['category'], $requestModel->category);

$newAttributes = [
'name' => 'Document for edit 2',
Expand Down

0 comments on commit 68c0472

Please sign in to comment.