/** * @testdox By default, only Administrators can modify data. */ public function permission() { // Set up two users, one admin and one not. The first created user is // always an admin. $admin = new \Ormic\Model\User(); $admin->username = '******'; $admin->save(); $this->assertTrue($admin->isAdmin()); $nonAdmin = new \Ormic\Model\User(); $nonAdmin->username = '******'; $nonAdmin->save(); $this->assertFalse($nonAdmin->isAdmin()); // Start a new model. $book = new Model\Book(); $book->setUser($nonAdmin); $this->assertFalse($book->canEdit()); $book->setUser($admin); $this->assertTrue($book->canEdit()); }
/** * @testdox Foreign key modifications are tracked in the datalog by their titles (rather than IDs). * This means that modifications to one record's title may result in changes appearing in the datalog of other * records. * @test */ public function foreignKeyTitles() { // Set up. $user = $this->getTestUser(); $book1 = new Model\Book(); $book1->setUser($user); $book1->title = 'Test Book with FK'; $book1->save(); $this->assertEquals(1, $book1->id); $this->assertEquals('Test Book with FK', $book1->title); $this->assertCount(2, $book1->getDatalog()); // Create an author. $author = new Model\Author(); $author->setUser($user); $author->name = 'Book Author'; $author->save(); $this->assertCount(2, $author->getDatalog()); // Create a book. $book = new Model\Book(); $book->setUser($user); $book->title = 'Test Book'; $book->author_id = $author->id; $book->save(); $this->assertCount(3, $book->getDatalog()); // Check that the recorded value for author_id was actually the title of the Author record. $datalog = $book->getDatalog(); $this->assertEquals('author_id', $datalog[1]->field); $this->assertEquals('Book Author', $datalog[1]->new_value); }