Skip to content

Commit

Permalink
Merge pull request #35 from lsst-epo/EPO-7897
Browse files Browse the repository at this point in the history
Added unit test for user creation
  • Loading branch information
ericdrosas87 authored Apr 4, 2023
2 parents 09105b3 + 5b2a105 commit cfda639
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/unit/SanityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace lsst\dam\tests;

use Craft;
use Codeception\Test\Unit;
use craft\elements\User;
//use craft\elements\Entry;
use craft\errors\ElementNotFoundException;
use yii\base\Exception;

class SanityTest extends Unit
{
/**
* @var \UnitTester
*/
protected \UnitTester $tester;

protected function _before()
{
}

protected function _after()
{
}

public function testUserCreation() {
$new_user = new User();
$new_user->username = "some_body";
$new_user->pending = true;
$new_user->firstName = "Some";
$new_user->lastName = "Body";
$new_user->email = "[email protected]";
$new_user->passwordResetRequired = false;
$new_user->validate(null, false);
try {
$success = Craft::$app->getElements()->saveElement($new_user, false);
$this->assertEquals(true, $success);
} catch (ElementNotFoundException $e) {
$this->debugSection('User not found error!', $e);
} catch (Exception $e) {
$this->debugSection('An exception occurred!', $e);
} catch (\Throwable $e) {
$this->debugSection('An throwable error occurred!', $e);
}
}

// public function testEntryCreation() {
// $callouts_section = Craft::$app->sections->getSectionByHandle('callouts');
// $entry_types = $callouts_section->getEntryTypes();
//
// $this->debugSection('Logging $entryTypes', $entry_types);
//
// $callout = $entry_types[0];
// $entry = new Entry();
// $entry->title = "Some test title";
// $entry->sectionId = $callouts_section->id;
// $entry->typeId = $callout->id;
// $entry->setFieldValue('header', "My fancy header");
// $entry->setFieldValue('text', "This and that");
// $entry->setFieldValue("backgroundColor", "base64:bmV1dHJhbDE1");
//
// try {
// $success = Craft::$app->getElements()->saveElement($entry);
// $this->assertEquals(true, $success);
// } catch (ElementNotFoundException $e) {
// $this->debugSection('User not found error!', $e);
// } catch (Exception $e) {
// $this->debugSection('An exception occurred!', $e);
// } catch (\Throwable $e) {
// $this->debugSection('An throwable error occurred!', $e);
// }
//
// }

}

0 comments on commit cfda639

Please sign in to comment.