Skip to content

Commit

Permalink
#159 Added new unit test (unfinished)
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Nov 20, 2023
1 parent c9c4028 commit c099c53
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions tests/Opus/LicenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2008-2018, OPUS 4 development team
* @copyright Copyright (c) 2008, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* @category Tests
* @package Opus
* @author Ralf Claußnitzer ([email protected])
* @author Thoralf Klein <[email protected]>
* @author Jens Schwidder <[email protected]>
*/

namespace OpusTest;

use Opus\Document;
use Opus\Common\Document;
use Opus\Licence;
use Opus\Model\DbConstrainViolationException;
use Opus\Model\Xml\Cache;
Expand Down Expand Up @@ -98,7 +92,7 @@ public function testInvalidateDocumentCache()
$lic->setNameLong('MyLongName');
$lic->setLinkLicence('http://licence.link');

$doc = new Document();
$doc = Document::new();
$doc->setType("article")
->setServerState('published')
->setLicence($lic);
Expand All @@ -124,7 +118,7 @@ public function testDocumentServerDateModifiedNotUpdatedWithConfiguredFields()
->setLinkLicence('http://test')
->store();

$doc = new Document();
$doc = Document::new();
$doc->setType("article")
->setServerState('published')
->setLicence($licence);
Expand All @@ -146,7 +140,7 @@ public function testDocumentServerDateModifiedNotUpdatedWithConfiguredFields()
}

$licence->store();
$docReloaded = new Document($docId);
$docReloaded = Document::get($docId);

$this->assertEquals(
(string) $serverDateModified,
Expand Down Expand Up @@ -350,7 +344,7 @@ public function testIsUsed()

$this->assertFalse($licence->isUsed());

$doc = new Document();
$doc = Document::new();
$doc->addLicence($licence);
$doc->store();

Expand All @@ -370,13 +364,13 @@ public function testGetDocumentCount()

$this->assertEquals(0, $licence->getDocumentCount());

$doc = new Document();
$doc = Document::new();
$doc->addLicence($licence);
$doc->store();

$this->assertEquals(1, $licence->getDocumentCount());

$doc = new Document();
$doc = Document::new();
$doc->addLicence($licence);
$doc->store();

Expand All @@ -387,4 +381,29 @@ public function testGetDocumentCount()

$this->assertEquals(1, $licence->getDocumentCount());
}

public function testAddLicence()
{
$licence = Licence::fromArray([
'NameLong' => 'Licence',
'Name' => 'CC BY',
'LinkLicence' => 'https://www.kobv.de/licence1'
]);
$licenceId = $licence->store();

$doc = Document::new();
$doc->addLicence($licence);
$doc->store();

$licences = $doc->getLicence();

$this->assertCount(1, $licences);
$this->assertEquals(1, $licence->getId());

$this->markTestIncomplete('TODO What is the purpose of this test? getId() provides unexpected result');

var_dump($licences[0]->getId());

$this->assertEquals($licenceId, $licences[0]->getId());
}
}

0 comments on commit c099c53

Please sign in to comment.